1

I am testing CVXOpt with the following model

>>> from cvxopt.modeling import op
>>> x = variable()
>>> y = variable()  
>>> c1 = ( 2*x+y >> c2 = ( x+2*y >> c3 = ( x >= 0 )
>>> c4 = (y >= 0 )
>>> lp1 = op(-4*x-5*y, [c1,c2,c3,c4])

However, I get two problems:

  1. Invalid argument for constraints for the last line of code. I've checked the CVXOpt documentation and the way is coded seems to be the right way to do it.
  2. Less important but still it will be nice if someone could tell me why i get a syntax error when writing all constraints (c1, c2,..) in the same line as shown here. Instead i've had to use different lines for each.
inestr
  • 11
  • 3

1 Answers1

3

There seem to be some problems with the syntax you're using. Also please always make sure your code snipped allows to run the code. The correct way to write your optimization problem is:

>>> from cvxopt.modeling import op
>>> from cvxopt.modeling import variable
>>> x = variable()
>>> y = variable()
>>> c1 = ( 2*x+y <= 7)      # You forgot to add the (in-) equality here and below
>>> c2 = ( x+2*y >= 2)
>>> c3 = ( x >= 0 )
>>> c4 = (y >= 0 )
>>> lp1 = op(-4*x-5*y, [c1,c2,c3,c4])
>>> lp1.solve()
     pcost       dcost       gap    pres   dres   k/t
 0: -1.0900e+01 -2.3900e+01  1e+01  0e+00  8e-01  1e+00
 1: -1.3034e+01 -2.0322e+01  9e+00  1e-16  5e-01  9e-01
 2: -2.4963e+01 -3.5363e+01  3e+01  3e-16  8e-01  3e+00
 3: -3.3705e+01 -3.3938e+01  2e+00  3e-16  4e-02  4e-01
 4: -3.4987e+01 -3.4989e+01  2e-02  5e-16  4e-04  5e-03
 5: -3.5000e+01 -3.5000e+01  2e-04  3e-16  4e-06  5e-05
 6: -3.5000e+01 -3.5000e+01  2e-06  4e-16  4e-08  5e-07
Optimal solution found.

In the fifth and sixth line, you forgot to add the (in-) equality. You have to state explicitly what you are comparing to, i.e. the inequality sign and the value you want to compare to.

You can write all (in-) equalities on one line if you use a semicolon to separate them. Again, be careful with your syntax, you forgot to close some brackets in your example code.

>>> c1 = ( 2*x+y <= 7); c2 = ( x+2*y >= 2); c3 = ( x >= 0 ); c4 = (y >= 0 )
Angela
  • 53
  • 4
  • Oh, thank you very much Angela for taking the time to resolve my doubt. I think it should work. Otherwise, I will let you know!. – inestr Jul 30 '14 at 01:35