Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Display Optimal Decision Variables Values in cplex studio

    Posted 06/12/17 01:35 PM

    Originally posted by: Bahman


    Hi there,

    In one of the models I am working on, I have defined a binary decision variable: dvar boolean X[<i,j> in Arcs][k in K][t in T].

    What I want to do is that for each k in K such that X[a in Arcs][k][t in T] == 1, all of the arcs, a, to be displayed. so I have used an execute block as postprocessing as follows:

    execute PathPerOD {
        for(var k in K) {
            for(var a in Arcs) {
                for(var t in T) {
                    if(X[a][k][t]==1) {
                        write(a," ");                
                    }            
                }        
            }    
        }
        writeln();
    }

     

    but, it does not show anything!

     

    Does anyone have any idea what the problem could be!

     

    Regards,
    Bahman 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Display Optimal Decision Variables Values in cplex studio

    Posted 06/12/17 07:17 PM

    Does it work if you change

    if (X[a][k][t] == 1)
    

    to

    if (X[a][k][t] >= 0.5)
    

    ? CPLEX returns a double-precision value for X and I suspect OPL does not round that value automatically. If I'm right, you're doing an equality comparison on floating point numbers, which seldom ends well.

     

    Paul

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Display Optimal Decision Variables Values in cplex studio

    Posted 06/13/17 10:26 AM

    Originally posted by: Bahman


    Dear Paul,

     

    I appreciate your reply! I simply modified the condition as follows:

    execute {
        for(var k in K) {
            for(var a in Arcs) {
                for(var t in T) {
                    if(X[a][k][t]!=0) {
                        writeln("Path for k = ",k,": ",a);                
                    }            
                }        
            }    
        }
        writeln();
    }

     

    and I got:

    Path for k = 1:  <1 4 450>
    Path for k = 1:  <4 9 400>
    Path for k = 2:  <1 4 450>
    Path for k = 2:  <4 11 500>
    Path for k = 2:  <11 12 450>
    Path for k = 2:  <12 13 650>
    Path for k = 2:  <13 14 500>
    Path for k = 3:  <1 3 600>
    Path for k = 3:  <3 6 650>
    Path for k = 3:  <6 7 500>
    Path for k = 4:  <2 1 700>
    Path for k = 4:  <1 4 450>
    Path for k = 4:  <4 9 400>
    Path for k = 4:  <9 10 450>

    ...

    However, I would like it to be like:

    Path for k = 1: <1 4 450> ,  <4 9 400>

    ...

    Regards,
    Bahman

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Display Optimal Decision Variables Values in cplex studio

    Posted 06/13/17 10:32 AM

    I can't help with the output formatting. You might want to ask in the OPL forum, since it's a scripting question.

    I can point out that the change you made is still wrong. If the optimal value of X[a][k][t] should be zero (don't select the arc), CPLEX is liable to return something like 0.000001 for its value. Since that is not equal to zero, your code will treat it as if it were one. Please see my previous response for a safe way to handle to the comparison.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Display Optimal Decision Variables Values in cplex studio

    Posted 06/13/17 10:53 AM

    Originally posted by: Bahman


    Dear Paul,

     

    Although the printed results are the same for both   X[a][k][t] != 0  and  X[a][k][t] > = 0.5 , in this experiment, but referring to your previous post, your justification completely makes sense to me and I will be using the latter condition. 

     

    I appreciate your reply!

     

    Regards,
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization