Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Dynamically add constraints

    Posted 11/03/11 10:25 AM

    Originally posted by: taito


    Hello. I am Japanese, so I am sorry not to write statement by English well.
    And, I am beginner.

    I want to add some constraints during optimization of a MIP dynamically.
    The one of the constraints I want to add is as follows.

    IloNum M = 1000.0;
    IloNum N = 2.0;

    IloNumVar p( env, 0, +IloInfinity, ILOFLOAT );
    IloNumVar q( env, 0, +IloInfinity, ILOFLOAT );

    IloNumVar a( env, 0, 1, ILOINT );

    IloConstraint c( env, -M <= q - p <= M * ( 1 - a ) ) - N; // <--- this

    I am implementing my application using C++.

    Because these constraints are unlikely violated, I tried to use lazy constraint.
    But, program throws exception at cplex.addLazyConstraint function.
    This exception is "InvalidCutException: invalid cut".

    Why?
    Is the constraint not a linear?
    Is using addLazyConstraint not correct?
    How to implement adding constraint during optimization of a MIP?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Dynamically add constraints

    Posted 11/03/11 11:12 AM

    Originally posted by: SystemAdmin


    Hm, your code does not compile for me (CPLEX 12.2 or 12.3). I assume you meant something like this:
    IloConstraint c(-M <= q - p <=  M * ( 1 - a ) - N );
    

    And this is indeed a problem since you are adding a range constraint where the upper bound of the range involves variable as well. Things like that are not supported for cuts. You can split up your single constraint into two equivalent constraints that are supported as cuts like this:
    IloRange r1(env, -M, q - p);
    IloRange r2(env, -IloInfinity, q - p - M * ( 1 - a ), - N);
     
    cplex.addLazyConstraint(r1);
    cplex.addLazyConstraint(r2);
    

    Note that the variables a, q and p must already exist in the model, otherwise you will again get an InvalidCutException. If the variables do not appear in any constraint or in the objective function then explicitly add them:
    model.add(a);
    model.add(q);
    model.add(p);
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Dynamically add constraints

    Posted 11/07/11 12:21 PM

    Originally posted by: taito


    Thank you. My can optimize MIP using Lazy constraint.
    IloConstraint replaced IloRange.

    I am sorry for the late reply...
    #CPLEXOptimizers
    #DecisionOptimization