2
$\begingroup$

I am trying to solve a mixed integer quadratic programming (MIQP) problem.

The objective function contains the product of two continuous decision variables, some of constraints are non-linear too. I would like to know that can docplex module in python solve this kind of the problem?

$\endgroup$
4
  • 3
    $\begingroup$ In what ways are the constraints nonlinear? $\endgroup$
    – prubin
    Feb 27, 2022 at 16:14
  • 2
    $\begingroup$ Following up on @prubin 's comment, CPLEX can handle (attempt to solve) quadratic (bilinear) objective function, but the only nonlinear constraints it allows are convex quadratic (which must be inequalities) and Second Order Cone constraints. $\endgroup$ Feb 27, 2022 at 17:04
  • 1
    $\begingroup$ @GizemTekindur many of the methods that are used for modeling MIP, have a quadratic version (with "quad" or "quadratic" in their names). For example, for adding quadratic constraints, you can use add_quadratic_constraints method. You can chceck them all in docplex documentation $\endgroup$
    – EhsanK
    Feb 27, 2022 at 18:47
  • $\begingroup$ However, quadratic constraints method wasn't called (they are just written with add_constraints method) the model has a solution. Do you think it is possible since the constraints are second order cone ones? Moreover, although the objective is nonlinear, it is easily solved which confuses me too. $\endgroup$
    – GTek
    Mar 1, 2022 at 21:27

1 Answer 1

3
$\begingroup$

In OPL You can write

range R = 0..2;
dvar int x[R] in 0..40;


maximize
  x[0] + 2 * x[1] + 10 * x[2]
  - 0.5 * ( 33 * x[0]^2 + 22 * x[1]^2 + 11 * x[2]^2 
          - 12 * x[0] * x[1] - 23 *x [1] * x[2] );

subject to {
  ct1:  - x[0] +     x[1] + x[2] <= 20;
  ct2:    x[0] - 3 * x[1] + x[2] <= 30;
  ct3:    x[0]^2 + x[1]^2 + x[2]^2 <= 10.0;
}

tuple xSolutionT{ 
    int R; 
    float value; 
};
{xSolutionT} xSolution = {<i0,x[i0]> | i0 in R};
execute{ 
    writeln(xSolution);
}   

which you can rewrite with docplex into

from docplex.mp.model import Model

mdl = Model(name='miqcp')

x=[mdl.integer_var(0,40,name="x"+str(i)) for i in range(0,3)] 

mdl.add(- x[0] +     x[1] + x[2] <= 20)
mdl.add(x[0] - 3 * x[1] + x[2] <= 30)
mdl.add(x[0]**2 + x[1]**2 + x[2]**2 <= 10.0)

mdl.maximize(x[0] + 2 * x[1] + 10 * x[2] - 0.5 * ( 33 * x[0]**2 \
+ 22 * x[1]**2 + 11 * x[2]**2 - 12 * x[0] * x[1] - 23 *x [1] * x[2] ))

mdl.solve()

for i in range(0,3):
    print(x[i].name," = ",x[i].solution_value)
$\endgroup$
1
  • $\begingroup$ Would you please, write the generic form of the above problem by using the add_constraint method? $\endgroup$
    – A.Omidi
    May 11, 2022 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.