Decision Optimization

Decision Optimization

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

 View Only
  • 1.  How to model the constraints with piecewise function in cplex using c++

    Posted Tue November 22, 2011 11:15 PM

    Originally posted by: RainLee


    Hi,
    the constraints is as follows:
    p>=pmin
    where,p is a decision varible, pmin is a function of (x,y),
    and if x+y<2,pmin=x+2*y ; if x+y>=2 ,pmin=2*x+3*y
    how to model this constraints.your answer will be appreciate
    thanks in advance!
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 04:37 AM

    Originally posted by: SystemAdmin


    Please refer to the documentation of the IloPiecewiseLinear construct, see http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r3/index.jsp at "CPLEX > CPLEX C++ Reference Manual > Concepts > Piecewise Linearity in CPLEX" and at "CPLEX > User's Manual for CPLEX > Discrete optimization > Using piecewise linear functions in optimization: a transport example".

    Tobias
    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 05:16 AM

    Originally posted by: RainLee


    thanks for your answer, maybe I didn't express my real question correctly at first, i just want to know can cplex deal with the piecewise quadratic functions, however, by which the feasible region determined is convex. my real question are described in the third floor.
    wishes for your beneficial references!
    thank you very much
    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 05:56 AM

    Originally posted by: SystemAdmin


    Unfortunately, this is not so easy. Namely, the region has to be convex in the full variable space, including the auxiliary variables used to model the piece-wise construct. And since the id58 and id71 variables are linked to quadratic terms by means of equations, this is not the case.

    Unfortunately, it is not possible to use quadratic terms in an indicator constraint, so removing the auxiliary variables and equations by substituting the auxiliary variables for their quadratic terms is not an option.

    But I think in the special case of your "model.lp" there is a solution. Namely, one can observe the following:

    1. id54 = 0 and id67 = 0 dominate id54 = 1 and id67 = 1 in terms of the objective function and the regular constraints (i.e., if you have a feasible solution with id54 = 1 or id67 = 1, then you can just set id54 = id67 = 0 to get an equivalent feasible solution). The only constraints that could force the two variables to 1 are the indicators i1 and i3. Consequently, the indicator direction that forces them to 0 is redundant and you can remove the "->" direction of the indicator constraints.

    2. Similary, the "<-" direction of the indicator constraints i2 and i4 can be removed.

    3. Now, id58 and id71 are only required to be large enough by the indicator constraints, and only the quadratic constraints id64 and id81 bound the variables from above. Consequently, the ">=" direction of the quadratic equations is not needed in the model and you can relax the equation to "<=" inequalities. Namely, if for example id58 is smaller than its corresponding quadratic expression, you could always (in a postprocessing step) increase it to be equal to the quadratic expression without violating any constraints and without changing the objective value. Thus, the relaxation to "<=" is valid.

    The resulting model is this:

    
    Minimize obj: 17.6200008392334 id1 + id53 + 0 id58 + 0 id71 + [ 0.000620000006165355 id1 ^2 ] / 2 Subject To id15: id2 >= 150 id17: id2 <= 455 id19: id3 >= 150 id21: id3 <= 455 id23: id2  = 300 id26: - id2 + id3 <= 200 id28: - id2 + id3 >= -200 id30: id1  = 300 id66: id54 - id56 <= 0 id83: id67 - id69 <= 0 id64: id58 + [ 0.0025 id2 ^2 + 0.0025 id3 ^2 ]  <= 0 id81: id71 + [ 0.00125 id2 ^2 - 0.0025 id2 * id3 + 0.00125 id3 ^2 ]  <= 0 i1: id54 = 0 -> id3 + id2 >= 500.000001 i2: id56 = 1 -> 0.75 id2 + 0.75 id3 + id1 + id58 >= 262.5 i3: id67 = 0 -> id3 + id2 <= 499.999999 i4: id69 = 1 -> id1 + id71 >= -50 Bounds id53 = 970 0 <= id54 <= 1 0 <= id56 <= 1 id58 Free 0 <= id67 <= 1 0 <= id69 <= 1 id71 Free Binaries id54  id56  id67  id69 End
    


    And this solves easily, with the solution

    
    MIP - Integer optimal solution:  Objective =  6.2839002520e+03 Solution time =    0.03 sec.  Iterations = 7  Nodes = 0   CPLEX> disp sol var - Incumbent solution Variable Name           Solution Value id1                         300.000000 id53                        970.000000 id58                       -394.218931 id71                        -68.295780 id2                         300.000000 id3                         214.700604 id54                          1.000000 id56                          1.000000 id67                          1.000000 id69                          1.000000
    

    Tobias
    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 09:52 AM

    Originally posted by: RainLee


    thanks for your excellent explaination. maybe if the number of constraints ranging from line id64: to i4 is small , i can modify it manually,and then solve it in interactive optimizer,however, in practice, the number of constrains like id64 to i4 is large, is there any method to express it in c++.
    my previous process is as follows:
    for(int i=0;i<10;i++)
    {
    model.add(IloIfThen(env,x[i]+y[i]<=500,0.75*x[i] +0.75*y[i]+z[i]-0.0025* x[i]*x[i] + 0.0025*y[i]*y[i] >=262.5 ));
    model.add(IloIfThen(env,x[i]+y[i] >= 500, zi]-0.00125 * x[i]*x[i]-0.0025 * x[i] * y[i] + 0.00125 * y[i]*y[i]>=-50));

    }
    then export model into a LP file
    finally modify the constraints manually in LP file and solve it in interactive optimizer

    maybe it looks stupid, but i didn't find any good code method in C++ to model it, would you please give me some advice ? I will be appreciated.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 04:54 AM

    Originally posted by: RainLee


    the question I really want to ask is how to model the the piecewise quatratic constraints (described by the lines from id64: to i4: as follows) by which the feasible region determined is covex.
    my code is like this (it can be obtained from attch files)
    \Problem name: IloCplex

    Minimize
    obj: 17.6200008392334 id1 + id53 + 0 id58 + 0 id71
    + http:// 0.000620000006165355 id1 ^2 / 2
    Subject To
    id15: id2 >= 150
    id17: id2 <= 455
    id19: id3 >= 150
    id21: id3 <= 455
    id23: id2 = 300
    id26: - id2 + id3 <= 200
    id28: - id2 + id3 >= -200
    id30: id1 = 300
    id66: id54 - id56 <= 0
    id83: id67 - id69 <= 0
    id64: id58 + http:// 0.0025 id2 ^2 + 0.0025 id3 ^2 = 0
    id81: id71 + http:// 0.00125 id2 ^2 - 0.0025 id2 * id3 + 0.00125 id3 ^2 = 0
    i1: id54 = 1 <-> id3 + id2 <= 500
    i2: id56 = 1 <-> 0.75 id2 + 0.75 id3 + id1 + id58 >= 262.5
    i3: id67 = 1 <-> id3 + id2 >= 500
    i4: id69 = 1 <-> id1 + id71 >= -50 0 <= id54 <= 1
    0 <= id56 <= 1
    id58 Free
    0 <= id67 <= 1
    0 <= id69 <= 1
    id71 Free
    Binaries
    id54 id56 id67 id69
    End

    the Cplex cannot deal with the line from id64: to i4:,i.e, the Q in quatratic funtions are not postive semi-definite, however, the feasible region determined by which is convex.
    Anyone who knows how to deal with it? Is there any modelling method? thanks in advance.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Wed November 23, 2011 07:20 PM

    Originally posted by: RainLee


    I have got through it by rplaceing the quadratic equtions by a varible and adding it as a inequality constraints. thanks for your patient answer. and the last question is how to get the sigle indicator direction "->",if I use IloIfThen() function, i always get "<->". thanks again.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 8.  Re: How to model the constraints with piecewise function in cplex using c++

    Posted Thu November 24, 2011 05:34 AM

    Originally posted by: SystemAdmin


    Yes, this is exactly the suggestion that Roland and I also came up with in our internal discussion of your problem.

    Regarding the indicators, there is (currently) no way in Concert to get one-way indicators instead of the two-way indicators. But presolve should be able to figure it out that one direction is not needed. Indeed, in your small example, just relaxing the quadratic equations to inequalities gives exactly the same solution as with my modified model that include the indicator modifications. And if you look at the presolved model after just relaxing the quadratic equations, the indicators have indeed been converted into one-way indicators.
    Tobias
    #DecisionOptimization
    #MathematicalProgramming-General