Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Range limit

    Posted Wed December 04, 2013 02:28 PM

    Originally posted by: MarcosQ


    Hi everybody,

                              I just started using ILOG CPLEX and already have many questions about it. For starters, there is any way to create a range where the upper limited is another range? For example, I'm trying something like that:

    range a = 1..value;

    range b= 1..a;

                 Looks like I can't do that. Is there any way to do something similar?

     

    Thanks,

    Marcos


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Range limit

    Posted Wed December 04, 2013 04:33 PM

    This looks like an OPL question, in which case you would be better off asking on the OPL forum.

    I'm pretty sure you cannot do what you stated, but you can define b the same as a (range b = 1..value;) and then, in expressions where you are iterating over both a and b, add the logical restriction that b <= a. I'm not sure of the precise syntax, but someone on the OPL forum can hopefully help (or you can look through the OPL examples provided with CPLEX Studio until you find one that does this).

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Range limit

    Posted Wed December 11, 2013 03:53 PM

    Originally posted by: MarcosQ


    Hi Paul,

                  sorry about that, I'll post my next questions on the OPL forum. Thanks for the heads up!


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Range limit

    Posted Thu December 05, 2013 01:34 AM

    What exactly is

      range b = 1..a;

    supposed to mean? A range is a set of subsequent integers from its lower bound to its upper bound. But what should b look like if its upper bound is a range? Could you give us an example of what a looks like and what you want b to be in that case?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Range limit

    Posted Wed December 11, 2013 03:58 PM

    Originally posted by: MarcosQ


    Hi Daniel,

                      I'm trying to implement this function:

     

             so, the max value of u in the second sum is determined for the current value of the first sum.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Range limit

    Posted Fri December 13, 2013 09:51 AM

    OK, the first two summations can be done with the same range, the last sum has unrelated indeces and thus needs an extra range:

    int p = ...;
    int v = ...;
    range P = 1 .. p;
    range V = 1 .. v;
    dexpr float F = sum(u in R) sum(d in R : d <= u) sum(i in V) x[i][u*d]*o[i][u-d];

    I did not double check that my syntax is correct but you should get the idea. The point is to use 'd <= u' in the second summation.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Range limit

    Posted Tue December 24, 2013 12:12 PM

    Originally posted by: MarcosQ


    Hi, I just made a few adaptations and now the expression looks like: 

            maximize

                  sum (u in P) sum(d in P:d<=u) sum(i in V) x[i][u][d] * o[i][u-d];

     

             but I got an error message saying tthat OLP could'n extract the expression: x[i][u][d] * o[i][(u+d*(-1))]

     

    Best regards to all!


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Range limit

    Posted Mon January 06, 2014 05:52 AM

    You need to provide more details. Are x and o decision variables or data? Does the range P start at 0 or 1? For u=d you will access o[i][0] which may not exist if range P starts at 1.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Range limit

    Posted Mon January 06, 2014 02:54 PM

    Originally posted by: MarcosQ


    Hi Daniel,

                       I made several changes since my last post, and this problem was solved, however, I still can't get the answer, looks like there are an unfeasible problem. Look below for the current OPL code and a .dat file

     

    int umps = ...;

    int wells = ...;
    int horiz = ...;
    int turn = ...;
    int total = wells+1;
     
     range P = 1..horiz;
     range V = 1..wells;
     
     range days = 1..horiz;
     range lines = 1..wells;
     range columns = 1..horiz;
     range dimension = 1..total;
      
     range v = 0..wells;
     
     
     int distance[dimension][dimension]=...;
     int optime[lines][columns]=...;
     float vol[lines][columns]=...;
     
     dvar boolean x[days][days][v];
     dvar boolean y[days][v][v];
     dvar boolean z[days][dimension][dimension];
     
     
     maximize
    sum (z in P) sum(a in P:a<z) sum(b in V) x[z][a][b] * vol[b][z-a];
     
    subject to {
      
      forall (a in days, b in v)
        ct1:sum (c in v) y[a][b][c] <= 1;
      
      forall (a in days, b in v)
        ct2:sum (c in v) y[a][c][b] <= 1;
        
      forall (a in days)
        ct3:sum (b in v:b!=0) y[a][0][b] == 1; 
     
      forall (a in days)
        ct4:sum (b in v:b!=0) y[a][b][0] == 1;
        
      forall (a in days, b in v)
        ct5:sum (c in v) y[a][b][c] - sum (c in v) y[a][c][b] == 0;
        
      forall (a in days, m in V)
        ct6:sum (b in v, c in v) y[a][b][c] <= m - 1;
        
      forall (a in days)
        ct7:sum (b in dimension, c in dimension) (distance[b][c]*z[a][b][c]) + 
        sum (d in v:d!=0, e in days:(a-e) in columns) (optime[d][a-e]*x[a][e][d]) <= turn;
        
      forall (a in days, b in v)
        ct8:sum (c in v) x[a][a][c] - sum (c in v)y[a][b][c] == 0;
    }

     

     

    And a .dat file:

     

    umps=1;
    wells=16;
    horiz=30;
    turn=960;
     
    vol=[[9.65, 2.70, 4.65, 6.05, 7.06, 7.79, 8.31, 8.68, 8.96, 9.15, 9.29, 9.39, 9.47, 9.52, 9.55, 9.58, 9.60, 9.61, 9.62, 9.64, 9.64, 9.64, 9.65, 9.65, 9.65, 9.65, 9.65, 9.65, 9.65, 9.65],
    [6.68, 3.12, 4.78, 5.67, 6.14, 6.39, 6.53, 6.60, 6.64, 6.66, 6.67, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68, 6.68],
    [7.87, 2.51, 4.22, 5.37, 6.17, 6.71, 7.08, 7.34, 7.50, 7.62, 7.70, 7.75, 7.79, 7.81, 7.83, 7.84, 7.85, 7.85, 7.85, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87, 7.87],
    [4.40, 1.62, 2.65, 3.30, 3.70, 3.96, 4.12, 4.23, 4.29, 4.34, 4.36, 4.38, 4.39, 4.39, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40, 4.40],
    [10.26, 3.78, 6.17, 7.68, 8.63, 9.23, 9.61, 9.85, 10.00, 10.09, 10.15, 10.19, 10.22, 10.23, 10.24, 10.25, 10.25, 10.25, 10.25, 10.25, 10.25, 10.26, 10.26, 10.26, 10.26, 10.26, 10.26, 10.26, 10.26, 10.26],
    [9.91, 2.78, 4.78, 6.21, 7.25, 7.99, 8.53, 8.91, 9.20, 9.39, 9.54, 9.65, 9.72, 9.77, 9.82, 9.84, 9.86, 9.87, 9.88, 9.89, 9.90, 9.90, 9.90, 9.90, 9.91, 9.91, 9.91, 9.91, 9.91, 9.91],
    [5.10, 1.27, 2.24, 2.95, 3.49, 3.89, 4.20, 4.42, 4.59, 4.72, 4.81, 4.89, 4.94, 4.98, 5.01, 5.03, 5.05, 5.07, 5.08, 5.08, 5.09, 5.09, 5.09, 5.10, 5.10, 5.10, 5.10, 5.10, 5.10, 5.10],
    [9.48, 4.14, 6.49, 7.79, 8.53, 8.95, 9.18, 9.32, 9.38, 9.42, 9.46, 9.47, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48, 9.48],
    [9.71, 2.19, 3.89, 5.20, 6.22, 7.01, 7.62, 8.09, 8.46, 8.74, 8.96, 9.13, 9.26, 9.36, 9.44, 9.50, 9.55, 9.58, 9.61, 9.64, 9.66, 9.67, 9.68, 9.69, 9.69, 9.70, 9.70, 9.70, 9.70, 9.71],
    [4.55, 1.03, 1.82, 2.44, 2.91, 3.29, 3.57, 3.79, 3.96, 4.09, 4.20, 4.27, 4.34, 4.39, 4.42, 4.45, 4.47, 4.49, 4.50, 4.52, 4.53, 4.53, 4.54, 4.54, 4.54, 4.54, 4.55, 4.55, 4.55, 4.55],
    [10.65, 2.66, 4.66, 6.16, 7.28, 8.13, 8.77, 9.23, 9.59, 9.86, 10.06, 10.21, 10.31, 10.40, 10.46, 10.52, 10.55, 10.58, 10.60, 10.61, 10.62, 10.63, 10.63, 10.64, 10.64, 10.65, 10.65, 10.65, 10.65, 10.65],
    [4.73, 1.51, 2.53, 3.23, 3.71, 4.04, 4.26, 4.41, 4.50, 4.58, 4.63, 4.66, 4.69, 4.70, 4.71, 4.72, 4.72, 4.72, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73, 4.73],
    [5.28, 1.69, 2.83, 3.60, 4.14, 4.50, 4.75, 4.92, 5.03, 5.11, 5.16, 5.19, 5.23, 5.24, 5.25, 5.26, 5.27, 5.27, 5.27, 5.27, 5.28, 5.28, 5.28, 5.28, 5.28, 5.28, 5.28, 5.28, 5.28, 5.28],
    [9.52, 3.71, 5.97, 7.36, 8.19, 8.71, 9.03, 9.22, 9.34, 9.40, 9.46, 9.48, 9.50, 9.51, 9.51, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52, 9.52],
    [4.60, 1.04, 1.84, 2.46, 2.95, 3.32, 3.60, 3.83, 4.01, 4.13, 4.24, 4.32, 4.39, 4.43, 4.47, 4.49, 4.52, 4.54, 4.55, 4.56, 4.57, 4.58, 4.58, 4.59, 4.59, 4.59, 4.59, 4.59, 4.59, 4.59],
    [4.82, 1.36, 2.32, 3.02, 3.53, 3.89, 4.16, 4.35, 4.47, 4.57, 4.64, 4.70, 4.73, 4.76, 4.78, 4.79, 4.80, 4.80, 4.81, 4.81, 4.81, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82]];
     
    optime=[[211, 63, 105, 134, 156, 171, 182, 190, 196, 200, 203, 205, 207, 208, 209, 209, 210, 210, 210, 210, 211, 211, 211, 211, 211, 211, 211, 211, 211, 211],
    [148, 72, 107, 126, 136, 142, 145, 146, 147, 147, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148],
    [173, 59, 95, 120, 137, 148, 156, 162, 165, 168, 169, 171, 171, 172, 172, 172, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173],
    [99, 40, 62, 76, 85, 90, 94, 96, 97, 98, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99],
    [224, 86, 137, 169, 189, 202, 210, 215, 218, 220, 222, 222, 223, 223, 223, 223, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224],
    [216, 65, 107, 138, 160, 176, 187, 195, 201, 205, 209, 211, 212, 213, 214, 215, 215, 216, 216, 216, 216, 216, 216, 216, 216, 216, 216, 216, 216, 216],
    [114, 33, 53, 69, 80, 89, 95, 100, 103, 106, 108, 110, 111, 112, 112, 113, 113, 113, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114],
    [207, 94, 144, 171, 187, 196, 201, 204, 205, 206, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207],
    [212, 53, 89, 116, 138, 155, 168, 178, 186, 192, 196, 200, 203, 205, 206, 208, 209, 209, 210, 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212],
    [103, 28, 45, 58, 68, 76, 82, 86, 90, 93, 95, 97, 98, 99, 100, 100, 101, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102],
    [232, 63, 105, 137, 161, 179, 192, 202, 210, 215, 219, 223, 225, 227, 228, 229, 230, 230, 231, 231, 231, 232, 232, 232, 232, 232, 232, 232, 232, 232],
    [106, 38, 60, 75, 85, 92, 96, 100, 102, 103, 104, 105, 105, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106],
    [118, 42, 66, 83, 94, 102, 107, 110, 113, 114, 116, 116, 117, 117, 117, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118],
    [208, 85, 133, 162, 180, 191, 198, 202, 204, 206, 207, 207, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, 208],
    [104, 28, 45, 58, 69, 76, 83, 87, 91, 94, 96, 98, 99, 100, 101, 101, 102, 102, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 104, 104],
    [108, 35, 55, 70, 81, 89, 94, 98, 101, 103, 105, 106, 106, 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108]];
     
    distance=[[0, 11, 19, 54, 54, 31, 31, 19, 19, 11, 11, 1, 11, 19, 31, 31, 19],
    [11, 0, 11, 54, 54, 31, 31, 19, 19, 1, 1, 11, 1, 11, 31, 31, 19],
    [19, 11, 0, 66, 66, 42, 42, 31, 31, 11, 11, 19, 11, 1, 42, 42, 31],
    [54, 54, 66, 0, 1, 23, 23, 46, 46, 54, 54, 54, 54, 66, 23, 23, 46],
    [54, 54, 66, 1, 0, 23, 23, 46, 46, 54, 54, 54, 54, 66, 23, 23, 46],
    [31, 31, 42, 23, 23, 0, 1, 31, 31, 31, 31, 31, 31, 42, 1, 1, 31],
    [31, 31, 42, 23, 23, 1, 0, 31, 31, 31, 31, 31, 31, 42, 1, 1, 31],
    [19, 19, 31, 46, 46, 31, 31, 0, 1, 19, 19, 19, 19, 31, 31, 31, 1],
    [19, 19, 31, 46, 46, 31, 31, 1, 0, 19, 19, 19, 19, 31, 31, 31, 1],
    [11, 1, 11, 54, 54, 31, 31, 19, 19, 0, 1, 11, 1, 11, 31, 31, 19],
    [11, 1, 11, 54, 54, 31, 31, 19, 19, 1, 0, 11, 1, 11, 31, 31, 19],
    [1, 11, 19, 54, 54, 31, 31, 19, 19, 11, 11, 0, 11, 19, 31, 31, 19],
    [11, 1, 11, 54, 54, 31, 31, 19, 19, 1, 1, 11, 0, 11, 31, 31, 19],
    [19, 11, 1, 66, 66, 42, 42, 31, 31, 11, 11, 19, 11, 0, 42, 42, 31],
    [31, 31, 42, 23, 23, 1, 1, 31, 31, 31, 31, 31, 31, 42, 0, 1, 31],
    [31, 31, 42, 23, 23, 1, 1, 31, 31, 31, 31, 31, 31, 42, 1, 0, 31],
    [19, 19, 31, 46, 46, 31, 31, 1, 1, 19, 19, 19, 19, 31, 31, 31, 0]];

    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Range limit

    Posted Fri January 17, 2014 02:07 PM

    If your problem is infeasible then there are several tools to analyze infeasiblity and figure out what is wrong. See this chapter in the user manual to learn more details.


    #CPLEXOptimizers
    #DecisionOptimization