0

How do I add a quadratic constraint using the scip python interface? In one of the examples, I see something like model.addCons(x*x+y*y<=6) However, since I have a lot of variables(x1..xn and my constraint is of the form x'Qx<=0.2, where x is n*1 and Q is n*n), this method is rather impossible. How can I put the quadratic constraint in a python dictionary of coeffs as I do the linear constraints? (coeffs={x**2:3.0,y**2:1.0,z**2:5.0} for example if I want 3x^2+y^2+5z^2<=10)

cprakashagr
  • 751
  • 11
  • 28
snyder
  • 1

1 Answers1

0

This is currently not supported. You need to loop through your quadratic constraints and add them one after the other using the expression method.

mattmilten
  • 6,242
  • 3
  • 35
  • 65
  • Thank you for your answer. But since I have a large number of quadratic terms in my constraint (x'Qx, where Q is of the scale 5000*5000). Can I efficiently loop through this large number of terms? – snyder Mar 15 '16 at 10:25
  • I don't see why you couldn't. This largely depends on how your coefficients are stored. When creating the quadratic constraint, though, I highly recommend using the quicksum() method instead of explicitly stating the linear or quadratic expression. – mattmilten Mar 15 '16 at 10:38
  • How can I use the quicksum() method, is there any document about it,thanks – snyder Mar 15 '16 at 15:25
  • It's similar to Gurobi's implementation: https://www.gurobi.com/documentation/6.5/refman/py_quicksum.html – mattmilten Mar 15 '16 at 17:11
  • Example: ```model.addCons(quicksum(c[i,j]*x[i,j] for i in I for j in J) <= 10)``` – mattmilten Mar 15 '16 at 17:12
  • ...and you need to import it: ```from pyscipopt import quicksum``` – mattmilten Mar 15 '16 at 17:14