Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

CPLEX Mathematical Model

  • 1.  CPLEX Mathematical Model

    Posted Wed August 03, 2016 01:21 PM

    Originally posted by: kashifjadoon


    Can anybody help me with the following problem:

    I have a matrix X that contains 24 rows and 5 columns. The first column contains time with the respective rows in the format 1:00 till 24:00. For each time there are four values associated with that particular hour. The last column contains 0:

    Time          column 1         column  2       column 3     column 4

    01:00           1000                 1500                800                0

    02:00             300                   100                 200                0

    03:00             600                   500               1500               0

        .                    .                          .                   .                       0

       .                     .                          .                   .                      0

       .                     .                          .                   .                      0

    24:00            700                  1000               600                0

    From columns 2,3,4 and 5 Six consecutive values  can be selected, example from time 01:00 to 06:00 say column 2 then time 07:00 to 12:00 say column 1, then time 13:00 to 18:00 say column 1 and from 19:00 to 24:00 say column 1.

    I want to find the overall minimum values for 24 hours with the constraint that six consecutive values from each four columns and no column is selected twice or thrice..

    Can somebody help me in this regard.

    I will be very thankful if someone can provide me the mathematical equation.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: CPLEX Mathematical Model

    Posted Tue August 23, 2016 07:52 PM

    Hi,

    you could try something like the following in OPL:

    .mod

    tuple t
     {
     key int h;
     int column1;
     int column2;
     int column3;
     int column4;
     }
     
     range horizon=1..24;
     range possibleStart=1..19;
     
     {t} s=...;
     
     int colValue[h in horizon][c in 1..4];
     
     execute
     {
     for(var i in s)
     {
        colValue[i.h][1]=i.column1;
        colValue[i.h][2]=i.column2;
        colValue[i.h][3]=i.column3;
        colValue[i.h][4]=i.column4;
     }
     }
     
     dvar boolean x[horizon][1..4];
     dvar boolean start[horizon][1..4];
     dvar int obj;
     
     minimize obj;
     subject to
     {
     
     forall(h in 20..24,c in 1..4) start[h][c]==0;
     forall(h in horizon) start[h][4]==0;
     
     
      // Objective
      obj==sum(h in horizon,c in 1..4) x[h][c]*colValue[h][c];
     
      // 4 starts
      sum(c in 1..3) sum(h in possibleStart) start[h][c]==4;
     
      // we cannot have a start for 5 periods after a start
      forall(h in possibleStart,c in 1..4) forall(offset in 1..5)
          start[h+offset][c]<=1-start[h][c];
     
      // One value max per given hour
      forall(h in horizon) sum(c in 1..4) x[h][c]<=1;
     
      // after a start we take 6 values
      forall(h in possibleStart,c in 1..4,offset in 0..5) x[h+offset][c]>=start[h][c];
     }
     
    tuple startResult
    {
    int startHour;
    int column;
    }

    {startResult} result={<h,c> | h in horizon, c in 1..4 : start[h][c]==1};

    execute
    {
    writeln(result);
    }
     

    .dat

    s=
     {
     <1, 1000          ,       1500        ,        800     ,           0>,
     <2, 3000          ,       100        ,        200     ,           0>,
     <3, 600          ,       500        ,        1500     ,           0>,
     <4, 1000          ,       1500        ,        800     ,           0>,
     <5, 1000          ,       1500        ,        800     ,           0>,
     <6, 3000          ,       100        ,        200     ,           0>,
     <7, 600          ,       500        ,        1500     ,           0>,
     <8, 1000          ,       1500        ,        800     ,           0>,
     <9, 1000          ,       1500        ,        800     ,           0>,
     <10, 3000          ,       100        ,        200     ,           0>,
     <11, 600          ,       500        ,        1500     ,           0>,
     <12, 1000          ,       1500        ,        800     ,           0>,
     <13, 1000          ,       1500        ,        800     ,           0>,
     <14, 3000          ,       100        ,        200     ,           0>,
     <15, 600          ,       500        ,        1500     ,           0>,
     <16, 1000          ,       1500        ,        800     ,           0>,
     <17, 1000          ,       1500        ,        800     ,           0>,
     <18, 1000          ,       1500        ,        800     ,           0>,
     <19, 1000          ,       1500        ,        800     ,           0>,
     <20, 1000          ,       1500        ,        800     ,           0>,
     <21, 1000          ,       1500        ,        800     ,           0>,
     <22, 1000          ,       1500        ,        800     ,           0>,
     <23, 1000          ,       1500        ,        800     ,           0>,
     <24, 700          ,       1000        ,        600     ,           0>
     };

    which gives

     {<1 3> <7 2> <13 3> <19 3>}

    regards

     


    #DecisionOptimization
    #MathematicalProgramming-General