Topic
11 replies Latest Post - ‏2012-05-02T13:04:59Z by Frops
Frops
Frops
6 Posts
ACCEPTED ANSWER

Pinned topic OPL to LP/MPS format identify variables

‏2012-04-18T14:20:09Z |
Dear all,

I have a model constructed with OPL language.
I have some variables indexed in a set with double indices. X_ij (where i,j \in Subset)

I have exported this model to an lp file, to work with Cplex with Matlab connector.
This lp file names the variables with one index.

I would like to use a MipStart. So I need to identify the name of the variables with my original definition.

  • Is there a way I can maintain the original names?
  • Or how can I identify the names of the variables in the lp file with my original variables?

Thanks advance,
Updated on 2012-05-02T13:04:59Z at 2012-05-02T13:04:59Z by Frops
  • AlexFleischer
    AlexFleischer
    1074 Posts
    ACCEPTED ANSWER

    Re: OPL to LP/MPS format identify variables

    ‏2012-04-19T07:28:36Z  in response to Frops
    Hi,

    the mapping is quite easy:

    
    dvar 
    
    int x[1..2][1..2];   subject to 
    { x[1][2]==3; 
    }
    


    gives

    
    Minimize obj: Subject To id23: x(1)(2)  = 3 Bounds x(1)(2) Free Generals x(1)(2) End
    


    If arrays are too big then the mapping can be less direct. To set this behaviour, you should have a look at the setting BigMapThreshold.

    Regards
    • Frops
      Frops
      6 Posts
      ACCEPTED ANSWER

      Re: OPL to LP/MPS format identify variables

      ‏2012-04-19T09:31:26Z  in response to AlexFleischer
      Thank you AlexFleischer,

      My problem had arrays too big and the mapping was not direct.

      I have changed the parameter bigMapThreshold (by default 100 to 550), and generate the new lp model.
      Now, I can identify the variables which maintain the name given in opl language.

      But the problem remains.
      I can not identify the index given to the variables, and I also need to know it to build the xml file with the solution.
      Yet the name of the variables is of the type x({1,2})#3 where 3 is the index of order given to variables, in this case the third variable.

      In the attached file, there is an example of some of the names of the variables, that I recognize through the i,j index. But I can not identify the order that it uses to fix the index.

      Thank you,
      • AlexFleischer
        AlexFleischer
        1074 Posts
        ACCEPTED ANSWER

        Re: OPL to LP/MPS format identify variables

        ‏2012-04-19T14:07:05Z  in response to Frops
        Hi,

        can you try with a much bigger bigMapThreshold ?

        Regards
      • Frops
        Frops
        6 Posts
        ACCEPTED ANSWER

        Re: OPL to LP/MPS format identify variables

        ‏2012-04-19T15:25:02Z  in response to Frops
        Dear AlexFleischer,

        I have tried with a bigger bigMapThreshold. I have noted the difference:

        * With the default value (100) my variables were like this: x#484#23 without maintaining the originals i,j subindex.
        * With value (550)* my variables are like this, x({1,2})#3 maintaining the subindex i,j, but with a unique index about the number of the variable in the whole model.
        *The names of the variables of the lp model changes when bigMapThreshold outnumbers the dimension of the array of the variable with multiple subindexs.

        The problem is that the variable is called "x({1,2})#3", so apart from knowing that the variable is the variable x({1,2}), I need to know that it has been associated with "#3" the third variable of the model. And I do not know how the assignment of the order is made.

        It may seem more or less logical, but sometimes it is not. For instance, in some cases it appears a variable (I assume dummy) called id115#22, that changes all the order from expected after #22.
        Thank you,
        • AlexFleischer
          AlexFleischer
          1074 Posts
          ACCEPTED ANSWER

          Re: OPL to LP/MPS format identify variables

          ‏2012-04-20T09:53:43Z  in response to Frops
          Hi,

          if bigMapThreshold. is big enough, you should see all your indexes.

          For example, with

          dvar int x[1..2][1..2][1..300000];
           
          subject to
          {
           x[1][2][2]==3; 
          }
          


          with bigMapThreshold 1000000 you get

          Minimize
           obj:
          Subject To
           id1200027: x#0#1#1  = 3
          Bounds
                x#0#1#1 Free
          Generals
           x#0#1#1 
          End
          


          but with bigMapThreshold 2000000

          you get

          Minimize
           obj:
          Subject To
           id1200027: x(1)(2)(2)  = 3
          Bounds
                x(1)(2)(2) Free
          Generals
           x(1)(2)(2) 
          End
          


          Regards
          Updated on 2014-03-26T05:57:03Z at 2014-03-26T05:57:03Z by AlexFleischer
          • Frops
            Frops
            6 Posts
            ACCEPTED ANSWER

            Re: OPL to LP/MPS format identify variables

            ‏2012-04-20T14:55:41Z  in response to AlexFleischer
            Thank you again,

            However, I can not manage to do what I need.

            I attach you a small example to show you the problem I have. (named small)
            • I wrote the mod and dat file.
            • From that, I generate lp and mps model files.
            • I solve this model (from both lp and mps)
            • I ask for mip starts after solving the model. (solutionsmall.mst)

            The final problem is that in a real case, I want to introduce an external solution through mst files (that represent mipstart solutions).
            I would like to use solutions or partial solutions that I obtain from other procedures, to help CPLEX solve the problem.
            I want to write a MST file with that solution, and intoduce it previously to solve execution.

            MST files have the following format to give names to variables.

            <variable name="x({1,2})" index="0" value="3"/>
            <variable name="x({1,8})" index="1" value="3"/>
            <variable name="x({5,2})" index="2" value="3"/>
            <variable name="x({3,2})" index="3" value="3"/>

            So, to give values to my variables in mst files, I need to identify the index="0" with variable "x({1,2})".
            Although in that small case, the lp model builded from mod and dat file uses variables as expected. x({1,2})
            In my real big case, I have tried to fix bigMapThreshold up to 20000000000; (that returns me a problem of Error de tiempo de ejecución de guión: cannot convert to an integer, "20000000000". Error in execution time)
            For smaller values, in lp format, I get variables with this format. x({1,23})#23.
            Which I understand that identify with <variable name="x({1,23})" index="23" value="0"/>
            That is why I wanted to know how cplex gave the index # to the variables.
            I thought I could identify the variable names in the mst file.

            I am very grateful for your invaluable help,

            Frops
          • AlexFleischer
            AlexFleischer
            1074 Posts
            ACCEPTED ANSWER

            Re: OPL to LP/MPS format identify variables

            ‏2012-04-20T15:40:43Z  in response to AlexFleischer
            Hi,

            after the # you have the rank.
            For example:

            dvar int x[1..2][10..300000];
             
            subject to
            {
             x[2][2000]==3; 
            }
            


            gives

            Minimize
             obj:
            Subject To
             id600001: x#1#1990  = 3
            Bounds
                  x#1#1990 Free
            Generals
             x#1#1990 
            End
            


            1 because 2-1=1
            1990 because 2000-10=1990

            so what is after the # gives you the rank

            Regards
            Updated on 2014-03-26T05:56:58Z at 2014-03-26T05:56:58Z by AlexFleischer
            • Frops
              Frops
              6 Posts
              ACCEPTED ANSWER

              Re: OPL to LP/MPS format identify variables

              ‏2012-04-23T13:32:25Z  in response to AlexFleischer
              Hi,

              Thank you for clarifying that after # we found the rank.

              In any case, in my model I find indexes I am not able to indentify uniquely.
              I need to identify them, to generate from external procedures, a solution.
              I attach two lp models as an example. Models have no fisical sense, just examples of what happens.
              Note that:
              -variable x, indexed in the previously build subset RR=http://1..10xhttp://1..10. 100 variables.
              -variable e, indexed in http://1..10
              -variable tt, indexed in http://1..10

              Both lp files are generated from the same mod/dat file (also attached), with different values of bigMapThreshold.

              In one case, I obtain these variables:

              bigMapThreshold=100(default) ;
              • x#0#0,x#1#1,x#2#2,...x#99#99 (up to 99 variables in total)
              • tt(1)#100,tt(2)#102,tt(3)#104, tt(4)#106, tt(5)#108, tt(6)#110, tt(7)#112, tt(8)#114, tt(9)#116, tt(10)#118
              _e(1)#101,_e(2)#103,_e(3)#105,_e(4)#107, _e(5)#109, _e(6)#111, _e(7)#113, _e(8)#115, _e(9)#117, _e(10)#119,

              bigMapThreshold=1000000000; (bigger values return error)
              • x({1,1})#0 , x({1,2})#1, x({1,3})#2,...,x({1,10})#9, x({2,1})#10,...,x({10,9})#98,x({10,10})#99 (up to 99 variables in total)
              • tt(1)#100 and idem
              • e(1)#101 and idem
              I understand that after # we find an index numbering all the variables. In our case, up to 120 variables (from 0-199)
              With number #0 to the first, until the last.
              However, I am not able to identify the order that the export function gives to number the variable.
              Thank you again,

              Attachments

              • Frops
                Frops
                6 Posts
                ACCEPTED ANSWER

                Re: OPL to LP/MPS format identify variables

                ‏2012-05-02T13:04:59Z  in response to Frops
                Hi,

                If it is not the way I try to do it, it does not matter. Another way that works is ok for me.

                I would like to use externally generated solutions to help CPLEX solve the model.
                I work with Cplex + Matlab, and from a model generated with OPL language and exported to MPS format.

                Thank you in advance,

                Frops
  • SystemAdmin
    SystemAdmin
    1883 Posts
    ACCEPTED ANSWER

    Re: OPL to LP/MPS format identify variables

    ‏2012-04-19T14:36:12Z  in response to Frops
    Hi All,

    Does anyone know how to convert the other way (i.e.,) from LP/MPS format to OPL format???
    Thanks a lot

    let me know if anyone knows.

    Regards,
    Dinesh
    • AlexFleischer
      AlexFleischer
      1074 Posts
      ACCEPTED ANSWER

      Re: OPL to LP/MPS format identify variables

      ‏2012-04-19T14:51:25Z  in response to SystemAdmin
      Hi

      main
      {
       cplex.importModel("hello.lp");
       cplex.solve(); 
      }
      


      Regards
      Updated on 2014-03-26T05:57:10Z at 2014-03-26T05:57:10Z by AlexFleischer