0

I have problem by writing quadratic constraints by docplex in python This is my constraint: A[i,j,k]=Z[i,j,k] *h[i,j,k]+Q[i,j,k]*d[i,j,k] ∀i,j,k
I wrote the constraint as below: mdl.add_quadratic_constraints(z_qsd[i,j,k]*h_qsd[i,j,k]+Q_qsd[i,j,k]*d_qsd[i,j,k]==A_qsd[i,j,k] for i in q_ualification for j in s_hift for k in d_ay) when I solve the model, I get this message: Model is non-convex

  • Hi. You don't seem to have actually asked a question, nor given us a minimal code example so others can reproduce the issue easily. Do that? :) – WurmD Jan 22 '21 at 09:58

2 Answers2

0

The multiplication operator '*' has been overloaded in DOcplex to write quadratic expression. In other terms, you can multiply two variables. Forgetting about indices, and assuming you have only four variables A,z,h,Q the constraint can be written as:

mdl.add(A == Z *h + Q *d)

Now, for three-dimensional variables, you should use a variation of Model.continuous_var_cube (change the type), for example:

 As = mdl.continous_var_cube(3,5,7, "A")

which builds a Python dictionary of variables, indexed by tuples of indices in the cartesian product of the three ranges (1..3)x(1..5)x(1..7), that is 3x5x7 = 85 variables. Each variable can be accessed by a collection of indices, as in

a123 = As[1,2,3]
Philippe Couronne
  • 826
  • 1
  • 5
  • 6
0

Here is a small quadratic-objective problem example, inspired by the famous "zoo" examples from Alex Fleischer (see https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/ for more)

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
# X**2 is the square of variable X
mdl.minimize(500 * nbbus40**2 + 400 * nbbus30**2)
mdl.solve()
for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value)
Philippe Couronne
  • 826
  • 1
  • 5
  • 6