Topic
5 replies Latest Post - ‏2014-05-19T08:31:52Z by AlexFleischer
RobertH79
RobertH79
4 Posts
ACCEPTED ANSWER

Pinned topic how to define data sets in Ilog like GLPK

‏2014-05-07T18:12:12Z |

Hi There!

I'm new to Ilog Cplex.

I have to translate/convert a model that was written in GLPK to ILOG OPL.

I'm at the beginning of it but unfortunatelly I'm get stuck. It's about defining the data sets and work with these in the model file .

 

In GLPK it looks like this:

Data file:

param number_one := 1;

param number_two := 2;

set E[1] := E1 E2;

set E[2] := E3 E4;

set E[3] := E5 E6;

----

Model File:

param number_one;

param number_two;

param numberof_set := number_one + number_two;

set E{i in 1..numberof_set};

set EX := setof{i in 1.. numberof_set, j in E[i]} j;

 

So there should be as many sets in the data file as the sum of the two numbers. In this case its three.

I would like to get the above sets in the same way in Ilog. I think I can bear with the remain parts of the model.

A would greatly appreciate your help!

Thanks a lot!

 

Robert

  • AlexFleischer
    AlexFleischer
    1081 Posts
    ACCEPTED ANSWER

    Re: how to define data sets in Ilog like GLPK

    ‏2014-05-09T07:12:43Z  in response to RobertH79

    Hi,

    could the following help ?

    .mod

    int nb=1+2;
     
     {int} s[1..nb]=...;
     
     execute
     {
     writeln(s);
     }

    .dat

    s=[ {1,2} {3} {4} ];

     

    regards

     

    Alex Fleischer

     

    • RobertH79
      RobertH79
      4 Posts
      ACCEPTED ANSWER

      Re: how to define data sets in Ilog like GLPK

      ‏2014-05-10T11:25:48Z  in response to AlexFleischer

      Dear Alex!

      I wish to thank for your help and the example code. I guess it's going to be okay for my question that I asked.

      I have implemented this in the following way:

      .mod

      int nb = 1+2;

      {string} E[i in 1..nb]=...;

      {string} EX = union( i in 1..3) E[i];

      .dat

      E = [ {E1, E2} {E3, E4} {E5, E6} ];

      So the datasets are the follows according to the given declaration above

      E[{"E1" "E2"}{"E3" "E4"}{"E5" "E6"}]

      EX{"E1" "E2" "E3" "E4" "E5" "E6"}

      I tried to build the rest of the model file, but i had some error messages.

      Error message:

      Cannot use the type {string}[range] with "in".

      This error does occur in the cases when (i in E) is in the declaration.

      For example:

      sum (i in E) p[i] * y[i];

      forall (i in EX) sum (i in E) y [i] <= n;

      forall (i in E) tr_serv*y[i] <= ts[i];   

      Thanks in advance.

      Have a nice day.

      Robert

       
      • AlexFleischer
        AlexFleischer
        1081 Posts
        ACCEPTED ANSWER

        Re: how to define data sets in Ilog like GLPK

        ‏2014-05-13T16:08:08Z  in response to RobertH79

        Hi

        forall (i in E) is not correct since E is not a {string} but an array of {string}

        forall (i in E[1]) will work better

        regards

         

        • RobertH79
          RobertH79
          4 Posts
          ACCEPTED ANSWER

          Re: how to define data sets in Ilog like GLPK

          ‏2014-05-13T20:13:57Z  in response to AlexFleischer
          Dear Alex!
           
          Thank you very much for all your invaluable help and support. The red error messages have gone and the model has run! But in this way I can just work with certain set that is named in the brackets. In your example it was the first E[1]. The model run without warning but it had elements from the first array eg: E1, E2. 
           
          So how can I define in the the way:
          forall (i in E[n])  or sum (i in E[n])
          to work all the sets that is created in the .dat file and present in the {string} array:
          E [{"E1" "E2"}{"E3" "E4"}{"E5" "E6"}]
           
          Thank you for your help.
           
          Regards 
          Robert
          Updated on 2014-05-13T20:22:24Z at 2014-05-13T20:22:24Z by RobertH79
          • AlexFleischer
            AlexFleischer
            1081 Posts
            ACCEPTED ANSWER

            Re: how to define data sets in Ilog like GLPK

            ‏2014-05-19T08:31:52Z  in response to RobertH79

            Hi

            could

            forall( j in 1..nb) forall (i in E[j])

            help ?

            Regards