Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Logical constraints as binary variables in Java

    Posted Mon February 07, 2011 05:15 AM

    Originally posted by: Baldsmooth


    Hi there,

    In Java, how would I do the following:

    IloIntVar b(env, 0, 1);
    model.add(b == (x >= y));

    For b == (x >= y), would I have to use 2 IfThen constraints?

    Thanks,

    Richard
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Logical constraints as binary variables in Java

    Posted Mon February 07, 2011 11:29 AM

    Originally posted by: SystemAdmin


    > Baldsmooth wrote:
    > Hi there,
    >
    > In Java, how would I do the following:
    >
    > IloIntVar b(env, 0, 1);
    > model.add(b == (x >= y));
    >
    > For b == (x >= y), would I have to use 2 IfThen constraints?
    >

    I think so. I would go with:

    IloCplex cplex = new IloCplex();
    IloNumVar b = cplex.boolVar();
    cplex.add(cplex.ifThen(cplex.eq(b, 1), cplex.ge(x, y)));
    cplex.add(cplex.ifThen(cplex.ge(x, y), cplex.eq(b, 1)));
    


    Personally, though, I don't use ifThen constraints; I make up my own "big M" constraints. CPLEX turns ifThens into "big M" type constraints internally, and I usually trust my ability to find a tight model-specific value of M more than I trust CPLEX's internal heuristics for selecting M. (No disrespect to CPLEX here: Ed Klotz, in a presentation at INFORMS, pretty much advised the audience to do this when we have any sort of intuition about the size of M.)

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Logical constraints as binary variables in Java

    Posted Mon February 07, 2011 02:36 PM

    Originally posted by: Baldsmooth


    Thanks. Too bad we cannot pass in a value for M as an argument to the ifThen.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Logical constraints as binary variables in Java

    Posted Mon February 07, 2011 06:41 PM

    Originally posted by: SystemAdmin


    In response to Paul's comments, I believe Ed is away from the office this week and he may not have a chance to respond, but I would like to clarify that actually CPLEX does not simply convert logical constraints to "big-M", but rather maintains the constraints through an internal structure called Indicator Constraints, which are branched upon directly. (Indicators can be used in the Callable Library for the same purpose as logical constraints are in Concert and OPL.) Ed's advice was that the additional presence of well-thought-out bounds such as in a good big-M formulation can be an additional aid in getting faster solution times on difficult models, while retaining Indicators' superior numerical behavior. He also notes that if these bounds happen to be rather modest (say somewhere like 1 to 1000) then the risk of numerical misbehavior in big-M formulation is not high anyway. CPLEX will try to infer such bounds on its own, but sometimes can not. But if no bounds are provided and none can be inferred, logical constraints (and/or indicator constraints) can operate correctly anyway, while this would not be the case for a big-M formulation nor could CPLEX convert to big-M internally.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Logical constraints as binary variables in Java

    Posted Tue February 08, 2011 06:28 PM

    Originally posted by: SystemAdmin


    John,

    Thanks for the clarification.

    Paul
    #CPLEXOptimizers
    #DecisionOptimization