Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Modeling the chance constraints

    Posted 07/17/19 02:54 AM

    Originally posted by: A.Omidi


    Hello support team,

    I was trying to write a chance constraint using Java in CPLEX but, I have some issues on it. I don't have any experience to deal with this form of constraints.

    The constraint is as follows:

    prob[sum(j, a(j)*x(j)) <= b] >= beta;
    

     

    I was wondering if, is there any efficient way to write this using CPLEX in the Java?

    Regards   


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Modeling the chance constraints



  • 3.  Re: Modeling the chance constraints

    Posted 07/21/19 07:17 AM

    Originally posted by: A.Omidi


    Dear Alex,

    Thanks for your replay. It is so useful. 

    I try to write you mentioned model 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
                            List<IloRange> constraints = new ArrayList<IloRange>();
                            IloLinearNumExpr num_expr = cplex.linearNumExpr();
                            for (int a1 = 0; a1 < 6; a1++) {
                                    for (int a2 = 0; a2 < 6; a2++) {
                                            num_expr.addTerm(a1, x);
                                            num_expr.addTerm(a2, y);
                                    }
                            }
    
                            cplex.addGe(num_expr, 3);
                            constraints.add(cplex.addGe(num_expr, (0.5/(1/36))));
    

    When I run the model it has some errors.

    Would you please, say that how can I write such probability constraint using Java?

    Regards

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Modeling the chance constraints

    Posted 07/22/19 01:24 AM

    Hi,

    you issue seems to be to translate

    1/36*sum(a1,a2 in 1..6) (a1*x + a2*y >= 3)>=1-alpha;

    from OPL to java concert.

    For indicator constraints you could have a look at https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/discr_optim/indicator_constr/02_indicators_defn.html

    and see the example Fixnet.java where you will see

    // Add logical constraints that require x[i]==0 if f[i] is 0.
             for (int i = 0; i < orig.length; ++i)
                cplex.add(cplex.ifThen(cplex.eq(f[i], 0.0), cplex.eq(x[i], 0.0)));

     

    In your case instead of cplex.ifThen you could use  IloCplexModeler.eq

     

    regards

     

    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Modeling the chance constraints

    Posted 07/23/19 04:35 AM

    Originally posted by: A.Omidi


    Dear Alex,

    Thanks for your comment. I correct my code using you mentioned and run it. The code 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 (I was wondering, you advise me if I'm wrong about that).

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

     

    Regards

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization