Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Summation in post processing execute Block

    Posted 10/11/19 08:56 AM

    Originally posted by: Nomykan


    Hi,

    i have a small question regarding the postprocessing execute block. i have a MIP problem and everything works good. there is no problem in the model. now i need to use the decision variable and calculate an expression in post processing using the execute block like x=sum(i in time, s in scenario) prob[s]*y[i,s] where x is to be determined and y is the decision variable. the main idea is to first solve the problem and then using the decision variable to evaluate another expression in the postprocessing. this expression dont need any constaints just calculating the value of x by summing all the values in the expression.   i have tried the for loop with summation but it does not work. any idea how to use the sum expression to evaluate the entire expresssion. Thanks

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Summation in post processing execute Block

    Posted 10/11/19 09:59 AM

    Hi,

    you should use OPL for that computation and not scripting.

    See for example

    dvar int x[1..10];

    subject to
    {
    forall(i in 1..10) x[i]==i;
    }

    int y=sum(i in 1..10) x[i];

    execute
    {
    writeln("y=",y);
    }

    which gives

    y=55

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Summation in post processing execute Block

    Posted 10/11/19 11:07 AM

    Originally posted by: Nomykan


    Hi Alex, 

    Thanks for your quick response. it had solved my confusion and it is working now. now the problem is i have an indicator function in the expression which is to be evaluated and require the use of if-else. i have attached an instance of the indicator function here with the message. the main idea is to sum up those values in which the indicator function gives value 1. in this case for if-else we need to use execute block or how we can do that in the OPL or if there is sepecifc function in OPL for that to evaluate the indicator function ?

    Thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Summation in post processing execute Block

    Posted 10/11/19 11:12 AM

    Hi,

    you can use logical expressions in OPL:

    dvar int x[1..10];

    subject to
    {
    forall(i in 1..10) x[i]==i mod 3;
    }

    int y=sum(i in 1..10) (x[i]==2);

    execute
    {
    writeln("y=",y);
    }

    gives

    y=3

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Summation in post processing execute Block

    Posted 10/11/19 11:32 PM

    Originally posted by: Nomykan


    Hi Alex,

    Thanks for your rightly guided information... now everything is Ok 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  RE: Re: Summation in post processing execute Block

    Posted 06/22/21 09:37 AM
    Dear @ALEX FLEISCHER
    in your solution , why did you use only the index (i) and where is it the second one (j) !! at the photo of the author it exist two summation ,can you explain more Dear Mr.



    Regards.

    ------------------------------
    Siwar
    ------------------------------



  • 7.  RE: Re: Summation in post processing execute Block

    Posted 06/22/21 09:48 AM
    Hi,

    my goal was to help.

    The equation in the image can be written as

    range I=1..3;
    range J=1..4;
    
    int B=10;
    
    dvar int Y[I][J];
    dvar int X;
    
    subject to
    {
      X==sum(i in I,j in J) (Y[i][j]==B);
      X==3;
    }​


    which gives

    X = 3;
    Y = [[10 10 10 0]
                 [0 0 0 0]
                 [0 0 0 0]];


    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------