Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  3D decision variable execute function

    Posted 02/03/14 06:30 AM

    Originally posted by: khadeejah


    how to write a command that displays output of two 3D decision variable array; X[I][j][k] and Y[I][j][k] in OPL cplex 12.5.1????


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: 3D decision variable execute function

    Posted 02/03/14 10:23 AM

    Originally posted by: fbahr


    execute DISPLAY {
       writeln("X = ", X);
       ...
    }
    

    or

    execute DISPLAY {
      for(var i in I)
        for(var j in J)
          for(var k in K)
             writeln("X[",i,"][",j,"][",k,"] = ", X[i][j][k]);
      ...
    }
    

    --fbahr

    P.S.: [Future] questions related to OPL should go here:
    https://www.ibm.com/developerworks/community/forums/html/forum?id=...000000002053


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: 3D decision variable execute function

    Posted 02/04/14 06:36 PM

    Originally posted by: khadeejah


    i 'd two errors : processing failed and unexpected end of file in scripting!!

    execute DISPLAY{

    for var (s in stages)

    for var (j in products)

    for var (t in periods)

    writeln ("X[",s,"][",j,"][",t,"]=",X[s][j][t])

    writeln ("I[",s,"][",j,"][",t,"]=",I[s][j][t])}

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: 3D decision variable execute function

    Posted 02/05/14 06:21 AM

    Originally posted by: fbahr


    
    execute DISPLAY {
      for (var s in stages)         //< [1]
        for (var j in products)
          for (var t in periods) {  //< [2]
            writeln("X[",s,"][",j,"][",t,"]=",X[s][j][t]);
            writeln("I[",s,"][",j,"][",t,"]=",I[s][j][t]);
        }
    }
    

    [1]: The 'var' keyword has to go with the local variable identifiers s, j, t (i. e., _in_ the parentheses).

    [2]: To loop over more than one command, the body of a loop has to be properly bounded (using curly brackets).

    --fbahr


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: 3D decision variable execute function

    Posted 02/05/14 07:56 AM

    Originally posted by: khadeejah


    3 errors: processing failed, 

    syntax error, unexpected execute,

    unexpected end of file in scripting

    below is my .mod file :

    {int} products = ...;

     {int} stages = ...;

     {int} parts = ...;

     int Nbperiods= ...;

    range periods = 1..Nbperiods;

     float dsj [stages][products]= ...;

    float units [periods][products]= ...;

    float msj [stages][products]= ...;

    float Ms [stages]= ...;

    float Qs [stages]= ...;

    float alpha [stages][products]= ...;

    float Ss [stages]= ...;

    float as [stages]= ...;

    float delta [products][parts]= ...;

    int Beta= ...;

    float vj [products]= ...;

    int Wst= ...;

     dvar int+ X [stages][products][periods];

    dvar int+ I [stages][products][periods]; // Q: periods should be written as [ 0..Nbperiods]

     minimize

    sum (j in products, s in stages, t in periods)(msj [s][j]* X [s][j][t]+

    Ss[s]*X[s][j][t]*(dsj[s][j]/Beta)+

    (Ms[s]*X[s][j][t]*dsj[s][j]/Qs[s])+

    alpha[s][j]*I[s][j][t]);

    subject to {

     ctInventory:

     forall( s in stages, j in products, t in periods,p in parts)

    {

    if(s==1)

    {

    sum (p in parts)

    I[s][j][t] == I[s][j][t-1] + X[s][j][t] -( delta[j][p] *( X[s+1][j][t]));

    }

    else if ((s+1)==6){

     

    I[s][j][t] == I[s][j][t-1]+X[s][j][t]- units [j][t];

    } else{

    I[s][j][t] == I[s][j][t-1] + X[s][j][t] - X[s+1][j][t];}

    }

    ctCapacity:

    forall (s in stages , t in periods)

     

    sum( j in products )

    dsj[s][j] * X[s][j][t] <= as[s];

     ctWarehouse:

    forall( s in stages, t in periods )

    {sum( j in products)

    vj[j]*I[s][j][t] <= Wst;

     

    execute DISPLAY{

    for var (s in stages)

    for var (j in products)

    for var (t in periods){

    writeln ("X[",s,"][",j,"][",t,"]=",X[s][j][t]);

    writeln ("I[",s,"][",j,"][",t,"]=",I[s][j][t]);

    }}

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: 3D decision variable execute function

    Posted 02/05/14 08:34 AM

    Originally posted by: fbahr


    Before the 'execute DISPLAY{' line, there are two curly brackets missing (closing  '... subject to { ...  forall( s in stages, t in periods ){ sum( j in products)vj[j]*I[s][j][t] <= Wst;').

    And the 'var's in  'for var (s in stages)' etc. are still placed incorrectly; has to be: 'for (var s in stages)'.

    --fbahr


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: 3D decision variable execute function

    Posted 02/10/14 04:48 AM

    Originally posted by: khadeejah


    Thanks a lot fbahr it worked. but I got other errors:

    • CPLEX(default) cannot extract expression: ctInventory: forall(s in stages, j in products, t in 1..52, p in parts) if ( s == 1 ) sum(p in parts) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+(delta[j][p]*X[(s+1)][j][t])*(-1); else if ( s == 5 ) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+units[j][t]*(-1); else I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+X[(s+1)][j][t]*(-1). 

     

    • CPLEX(default) cannot extract expression: ctInventory: forall(s in stages, j in products, t in 1..52, p in parts) if ( s == 1 ) sum(p in parts) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+(delta[j][p]*X[(s+1)][j][t])*(-1); else if ( s == 5 ) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+units[j][t]*(-1); else I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+X[(s+1)][j][t]*(-1). 

     

    • CPLEX(default) cannot extract model: IloAlgorithm cannot extract extractable. 

     

    • Index out of bound for array "I#0#0":

     

    • OPL cannot extract expression: ctInventory: forall(s in stages, j in products, t in 1..52, p in parts) if ( s == 1 ) sum(p in parts) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+(delta[j][p]*X[(s+1)][j][t])*(-1); else if ( s == 5 ) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+units[j][t]*(-1); else I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+X[(s+1)][j][t]*(-1). 
       
    • OPL cannot extract expression: if ( s == 1 ) sum(p in parts) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+(delta[j][p]*X[(s+1)][j][t])*(-1); else if ( s == 5 ) I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+units[j][t]*(-1); else I[s][j][t] == I[s][j][(t+(-1))]+X[s][j][t]+X[(s+1)][j][t]*(-1). 


       

    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: 3D decision variable execute function

    Posted 02/10/14 08:02 AM

    Originally posted by: fbahr


    Let's just take a look at the first constraint, case s == 1:

    ctInventory:
    forall(s in stages, j in products, t in 1..52, p in parts)
      sum(p in parts) I[s][j][t]
      == I[s][j][(t+(-1))]+X[s][j][t]+(delta[j][p]*X[(s+1)][j][t])*(-1);
    

    For t = 1, I[s][j][0] is not defined; likewise for s = card(stages): X[card(stages)+1][j][t] (assuming that your variable definitions haven't changed).

    And, actually, these errors are reported by Optimization Studio [for starters, ignore those "cannot extract" error messages -- and focus on the "Index out of bound for array ..." reports].

    --fbahr

    P.S.: Is  `sum(p in parts) I[s][j][t]` [which is equivalent to `card(parts) * I[s][j][t]`] really something you want to have in this constraint?


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: 3D decision variable execute function

    Posted 02/10/14 10:56 AM

    Originally posted by: khadeejah


    what do you mean by card??

    yes, parts is something I need to have. I only need it in the first stage and not afterwards .

    and how can I define the initial inventory which is at t=0?; I[s][j][0]; or can I start with t=2 so that t initial would be from t=1??

    one more thing is that " Index out of bound for array "I#0#0""error, would disappear if I defined I at t=0 ? because I is one of my decision variables.

    sorry for my stupid questions.

    and thanks for your prompt replies, you help me a lot, many many thanks fbahr.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: 3D decision variable execute function

    Posted 02/10/14 11:52 AM

    Originally posted by: fbahr


    > what do you mean by card??

    'card' returns the number of items in a set.

    My point was: `sum(p in parts) I[s][j][t]` expands to `I[s][j][t] + I[s][j][t] + ... + I[s][j][t]` -- and I'm not really sure if that's want you meant to say.

    > how can I define the initial inventory which is at t=0?; I[s][j][0]; or can I start with t=2 so that t initial would be from t=1?

    Both is viable; it basically depends on what I[s][j][*] is supposed to mean - inventory at the beginning of a period, or at its end.

    > one more thing is that " Index out of bound for array "I#0#0""error, would disappear if I defined I at t=0?

    Yes.

    > sorry for my stupid questions.

    No worries, no one is born a master.

    --fbahr


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: 3D decision variable execute function

    Posted 02/10/14 03:10 PM

    Originally posted by: khadeejah


    Hi fbahr,

                  I made some modifications, and the parts part no more exists in the model. i'm calculating inventory at the end of the period, 

    i still have "Index out of bound for array "I(1)(1)": 0. ", what i understand that i need to write in the data file values for 3D I[s][j][t], is that right?

    another thing why it always asking at t=0, however i defined t values started from 1?, or cplex is reading value t=1 as number 0 in the order of reading??

     

    #CPLEXOptimizers
    #DecisionOptimization