Decision Optimization

Decision Optimization

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

 View Only
  • 1.  OR logical constraint in Java and CPLEX Concert technology

    Posted Thu June 24, 2021 08:59 AM
    Hi All,

    I used CPLEX OPL and OR logical constraint can be easily described as below.

    x1 + x2 >=2 || x1 + x2==0;

    I would like to know how to express OR logical constraint in Java and CPLEX Concert Technology library.

    I have called cplex object as below. 

    IloCplex cplex = new IloCplex();

    There is an OR function under cplex object. I guess this function allows user to express OR logical constraint, but don't know how to use it.

    Would anyone please let me know how to express OR logical constraint in Java and CPLEX Concert Technology?

    Thank you for your help in advance!


    ------------------------------
    Sung Hwang
    ------------------------------

    #DecisionOptimization


  • 2.  RE: OR logical constraint in Java and CPLEX Concert technology

    Posted Thu June 24, 2021 11:38 AM
    The IloCplex.or() function returns a goal. Using goals is rather complicated, and involves creating a custom class that extends the abstract class IloCplex.Goal. If your variables have known upper bounds, it would be easier to express the disjunction by adding a new binary variable (call it z) and two new constraints: x1 + x2 >= 2*z and x1 + x2 <= M*z, where M is an upper bound for the sum of x1 and x2.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: OR logical constraint in Java and CPLEX Concert technology

    Posted Thu June 24, 2021 02:19 PM
    Hi,

    could "or" help ?

    Let me change the zoo example to show this

    IloCplex cplexBus = new IloCplex();
    
         // decision variables
         IloNumVar nbbus40 = cplexBus.numVar(0, 10000,IloNumVarType.Int); 
         IloNumVar nbbus30 = cplexBus.numVar(0, 10000,IloNumVarType.Int); 
    
         // move at least 300 kids to the zoo
         cplexBus.addGe(cplexBus.sum(cplexBus.prod(40,nbbus40), cplexBus.prod(30,nbbus30)),300);
         
         cplexBus.add(cplexBus.or(cplexBus.ge(nbbus40,8),cplexBus.ge(nbbus30,8)));
    
           
    
         // objective : minimize cost = 500*nbbus40+400*nbBus30
         cplexBus.addMinimize(cplexBus.sum(cplexBus.prod(500,nbbus40), cplexBus.prod(400,nbbus30)));
         
         
        
         cplexBus.solve();
    
          System.out.println("nbbus40 : "  +cplexBus.getValue(nbbus40) );
          System.out.println("nbbus30 : "  +cplexBus.getValue(nbbus30) );​

    works fine

    regards



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



  • 4.  RE: OR logical constraint in Java and CPLEX Concert technology

    Posted Thu June 24, 2021 03:12 PM
    I guess it's not as complicated as I thought -- IloCplex.or() takes care of extending the Goal class for you.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 5.  RE: OR logical constraint in Java and CPLEX Concert technology

    Posted Thu June 24, 2021 03:17 PM
    Thank you Alex and Paul for your comments!


    ------------------------------
    Sung Hwang
    ------------------------------