Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Special constraints using Java

    Posted 07/28/19 02:49 AM

    Originally posted by: A.Omidi


    Dear community team,

    I was trying to solve a MIP model that contains a chance constraint. An OPL example is:

    https://www.ibm.com/developerworks/community/forums/html/topic?id=662dda0c-f72b-44ef-9da3-9f12022ea6b0&ps=25

     

    I try to write the mentioned model (OPL) in Java and I have some issues on it.  The model is as follows:

                            // variables
                            IloNumVar x = cplex.numVar(0, Double.MAX_VALUE, "x");
                            IloNumVar y = cplex.numVar(0, Double.MAX_VALUE, "y");
    
                            // expressions
                            IloLinearNumExpr objective = cplex.linearNumExpr();
                            objective.addTerm(5, x);
                            objective.addTerm(6, y);
    
                            // define objective
                            cplex.addMinimize(objective);
    
                            // define constraints                   
                            double alfa = 0.5;      
                            double[] a1 = new double[] {1,2,3,4,5,6};
                            double[] a2 = new double[] {1,2,3,4,5,6};
                            IloLinearNumExpr logic = cplex.linearNumExpr();
                            for (int i = 0; i < a1.length; i++) {
                                    logic.addTerm(a1[i], x);
                                    logic.addTerm(a2[i], y);
                                    IloLinearNumExpr num_expr = cplex.linearNumExpr();
                                    cplex.add(cplex.ifThen(cplex.ge(logic, 3), cplex.ge(num_expr, (1-alfa)/(1/36))));
                            }
    

    When it's solved log file is:

    Found incumbent of value 0.000000 after 0.00 sec. (0.00 ticks)
    
    Root node processing (before b&c):
      Real time             =    0.00 sec. (0.00 ticks)
    Parallel b&c, 4 threads:
      Real time             =    0.00 sec. (0.00 ticks)
      Sync time (average)   =    0.00 sec.
      Wait time (average)   =    0.00 sec.
                              ------------
    Total (root+branch&cut) =    0.00 sec. (0.00 ticks)
    obj = 0.0
    x   = 0.0
    y   = 0.0
    

    I think the probabilistic model is a little bit different from the logical constraints model. In if-clause, in my model, I do not have a parameter and it is an expression. I added an IloLinearNumExpr "num_expr " to add the result to the if-clause but, it did not work.

    Would you please, say that how can I interpret such expressions using "add method"?

     

    Regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Special constraints using Java

    Posted 07/28/19 06:52 PM

    Originally posted by: EdKlotz


    Generally speaking, when you get unexpected results that you think relate to a constraint in the model, you should call the exportModel function to write our model out to an LP file.   Then look at the relevant constraint.   Now it's a bit trickier with IloIfThen, but it will can help you figure out what is happening.

    Looking at your code, I see two issues.

    • The first one is general.   You have:

                                    IloLinearNumExpr num_expr = cplex.linearNumExpr();

                                   cplex.add(cplex.ifThen(cplex.ge(logic, 3), cplex.ge(num_expr, (1-alfa)/(1/36))));

                             

                                   So num_expr is empty at this point, which means this constraint evaluates to

                                   If a1[i]x + a2[i]y >= 3 Then 0 >= b                                       where b is positive given that your alpha is  .05.

                                   Since 0 >= b can never be true, this is equivalent to a1[i]x + a2[i]y <= 3, and the solution you got of x = y = 0.0 satisfies that.for each pass in your for loop.

    • The second issue is specific to what you are actually trying to express.   The OPL statement is using logical cardinality to add up the number of times a sequence of constraints is satisfied.   The add method adds individual constraints.   So you need to build up a sum of logical conditions, then express your final constraint in terms of your logical conditions.   Have a look at the Logical Constraints for Counting and Logical Constraints as Binary Variables in the User manual.   Based on that, I think you want to create an array of binary variables to count the number of times a1[i]x + a2[i]y >= 3 in your for loop.   Associated a different binary for each (a1,a2) pair.   Then after your loop, and one more constraint that the sum of those binaries is >= 36*(1 - alpha).

    #CPLEXOptimizers
    #DecisionOptimization