Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Absolute value in constraint : |x1-x2|-x3<=0

    Posted Fri June 09, 2017 09:34 AM

    Originally posted by: devos1


    Dears, 

    I am wondering how can I write this constraint using cplex in my ILP:  |x1-x2|-x3<=0

    In fact, all variables are binaries and I want that x3 is set to 0 when x1 and x2 are equal to 1.

     

    thanks in advance.

    Best regards.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Fri June 09, 2017 10:24 AM

    Hi,

    in OPL CPLEX you could write


    dvar boolean x1;
    dvar boolean x2;
    dvar boolean x3;

    subject to
    {
    abs(x1-x2)-x3<=0;
    ((x1==1) && (x2==1)) => (x3==0);
    }

    which gives

    x1 = 0;
    x2 = 0;
    x3 = 1;

    regards


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Fri June 09, 2017 10:31 AM

    Originally posted by: devos1


    Sorry, I forget to precise that I am coding in java.

    I think that ((x1==1) && (x2==1)) => (x3==0) is not equivalent to |x1-x2|-x3<=0.

    I miss express my need.

    Tell me please,  how can I exress/write my constraint ((x1==1) && (x2==1)) => (x3==0) using cplex in a java based-code ?

    Your help is very appreciated.

    kind regards.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Fri June 09, 2017 12:43 PM

    Hi,

    have you tried to use

    public final IloConstraint ifThen(IloConstraint con1, IloConstraint con2) throws IloException

    ?

    regards

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Sat June 10, 2017 04:36 PM

    You can just add the constraint x1 + x2 + x3 <= 2. If x1 and x2 are both 1, this forces x3 to be 0. For any other combination of values of x1 and x2, x3 can be either 0 or 1.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Sun June 11, 2017 08:46 AM

    Originally posted by: devos1


    Thanks for your great help.

     

    I will try this tomorrow because the source code and build environment is in my professional machine.

     

    Best regards.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: Absolute value in constraint : |x1-x2|-x3<=0

    Posted Tue June 13, 2017 04:53 AM

    Originally posted by: devos1


    Thank you for your help and support.

    The solution is to add the constraint suggested by PaulRobin: x1 + x2 + x3 <= 2

    It works fine.

    Best regards.


    #DecisionOptimization
    #MathematicalProgramming-General