0

When I run this using cvxpy (cost is my objective function):

x = cp.Variable((4,4), integer=False)

for i in range(0,4):
    for j in range(0,3):
        cost += (x[i][j] / x[i][j+1] + 5)**2

It gets error:

cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically:
The objective is not DCP. Its following subexpressions are not:
var3[0, 0:2][0] / var3[0, 0:2][1]
var3[1, 0:2][0] / var3[1, 0:2][1]

Why does this appear? I have checked the DCP ruleset as it said: http://cvxr.com/cvx/doc/dcp.html#quadforms . But i'm also not sure.

BTW, if i turn the division to log, like cost += (log(x[i][j]) - log(x[i][j+1]) + 5)**2, it will also give a error:NameError: name 'log' is not defined var1, seems the content in log can't be a variable.

So is there a solution to address this? Or how can i transform my objective function in cvxpy to do this?

happy
  • 67
  • 7
  • 1
    CVXPY is for convex problems only. The first sentence at https://www.cvxpy.org/: "*CVXPY is an open source Python-embedded modeling language for convex optimization problems.*" – Erwin Kalvelagen Nov 27 '22 at 22:11
  • 1
    ``x/y`` is not a convex function of two variables ``x,y``. Neither is ``(x/y+5)^2``. To apply ``log`` to a cvxpy variable you would have to use ``cp.log(...)``, since Python's ``log`` obviously doesn't know howto deal with cvxpy objects. But similar nonconvexity issue will occur. – Michal Adamaszek Nov 27 '22 at 22:49
  • So this is what kind of function? I saw cvxpy has Disciplined quasiconvex programming (DQCP)[https://www.cvxpy.org/tutorial/dqcp/index.html#dqcp-problems] and Disciplined Geometric Programming(DGP)[https://www.cvxpy.org/tutorial/dgp/index.html]. It seems in these two, I can realise the multiple or division of two variables. – happy Nov 28 '22 at 02:04
  • Also, can cvxpy only solve convex optimization problems? In its document seems concave problems is also suitable. – happy Nov 28 '22 at 03:36
  • 1
    You might fit DGP but that of course depends on the rest of your problem, which you never showed. Why not write on https://or.stackexchange.com/ with your FULL problem and ask for advice for a suitable problem type/solver. Asking these partial questions will keep you in the blind. Maximizing(concave) and Minimizing(convex) is the same. – Michal Adamaszek Nov 28 '22 at 07:25
  • I have posted my whole question in [https://or.stackexchange.com/questions/9413/how-to-solve-this-mixed-integer-quadratic-program-using-cvxpy-or-other-method]. I wish you can have a look on it. I'm very grateful for that! – happy Nov 28 '22 at 16:16

0 Answers0