CVXOPT SDP Backend

AUTHORS:

  • Ingolfur Edvardsson (2014-05) : initial implementation

  • Dima Pasechnik (2015-12) : minor fixes

class sage.numerical.backends.cvxopt_sdp_backend.CVXOPTSDPBackend

Bases: sage.numerical.backends.matrix_sdp_backend.MatrixSDPBackend

Cython constructor

EXAMPLES:

sage: from sage.numerical.backends.generic_sdp_backend import get_solver
sage: p = get_solver(solver = "CVXOPT")                 # optional - cvxopt
dual_variable(i, sparse=False)

The \(i\)-th dual variable

Available after self.solve() is called, otherwise the result is undefined

  • index (integer) – the constraint’s id.

OUTPUT:

The matrix of the \(i\)-th dual variable

EXAMPLES:

sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt')       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1])                                         # optional - cvxopt
sage: a1 = matrix([[1, 2.], [2., 3.]])
sage: a2 = matrix([[3, 4.], [4., 5.]])
sage: a3 = matrix([[5, 6.], [6., 7.]])
sage: b1 = matrix([[1, 1.], [1., 1.]])
sage: b2 = matrix([[2, 2.], [2., 2.]])
sage: b3 = matrix([[3, 3.], [3., 3.]])
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3)                            # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3)                            # optional - cvxopt
sage: p.solve()                                     # tol 1e-08            # optional - cvxopt
-3.0
sage: B=p.get_backend()                                                    # optional - cvxopt
sage: x=p.get_values(x).values()                                           # optional - cvxopt
sage: -(a3*B.dual_variable(0)).trace()-(b3*B.dual_variable(1)).trace()       # tol 1e-07   # optional - cvxopt
-3.0
sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g  # tol 1.5e-08 # optional - cvxopt
0.0
get_objective_value()

Return the value of the objective function.

Note

Behaviour is undefined unless solve has been called before.

EXAMPLES:

sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False)       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1] + x[2])                                  # optional - cvxopt
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
sage: a2 = matrix([[7., -18.], [-18., 8.]])
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
sage: a4 = matrix([[33., -9.], [-9., 26.]])
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0.,   8., 5.]])
sage: b2 = matrix([[0.,  10.,  16.], [10., -10., -10.], [16., -10., 3.]])
sage: b3 = matrix([[-5.,   2., -17.], [2.,  -6.,   8.], [-17.,  8., 6.]])
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)                  # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)                  # optional - cvxopt
sage: N(p.solve(), digits=4)                                               # optional - cvxopt
-3.154
sage: N(p.get_backend().get_objective_value(), digits=4)                   # optional - cvxopt
-3.154
get_variable_value(variable)

Return the value of a variable given by the solver.

Note

Behaviour is undefined unless solve has been called before.

EXAMPLES:

sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False)       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1] + x[2])                                  # optional - cvxopt
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
sage: a2 = matrix([[7., -18.], [-18., 8.]])
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
sage: a4 = matrix([[33., -9.], [-9., 26.]])
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0.,   8., 5.]])
sage: b2 = matrix([[0.,  10.,  16.], [10., -10., -10.], [16., -10., 3.]])
sage: b3 = matrix([[-5.,   2., -17.], [2.,  -6.,   8.], [-17.,  8., 6.]])
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)                  # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)                  # optional - cvxopt
sage: N(p.solve(), digits=4)                                               # optional - cvxopt
-3.154
sage: N(p.get_backend().get_variable_value(0), digits=3)                   # optional - cvxopt
-0.368
sage: N(p.get_backend().get_variable_value(1), digits=4)                   # optional - cvxopt
1.898
sage: N(p.get_backend().get_variable_value(2), digits=3)                   # optional - cvxopt
-0.888
slack(i, sparse=False)

Slack of the \(i\)-th constraint

Available after self.solve() is called, otherwise the result is undefined

  • index (integer) – the constraint’s id.

OUTPUT:

The matrix of the slack of the \(i\)-th constraint

EXAMPLES:

sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt')       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1])                                         # optional - cvxopt
sage: a1 = matrix([[1, 2.], [2., 3.]])
sage: a2 = matrix([[3, 4.], [4., 5.]])
sage: a3 = matrix([[5, 6.], [6., 7.]])
sage: b1 = matrix([[1, 1.], [1., 1.]])
sage: b2 = matrix([[2, 2.], [2., 2.]])
sage: b3 = matrix([[3, 3.], [3., 3.]])
sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3)                            # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3)                            # optional - cvxopt
sage: p.solve()                         # tol 1e-08                        # optional - cvxopt
-3.0
sage: B = p.get_backend()                                                  # optional - cvxopt
sage: B1 = B.slack(1); B1               # tol 1e-08                        # optional - cvxopt
[0.0 0.0]
[0.0 0.0]
sage: B1.is_positive_definite()                                            # optional - cvxopt
True
sage: x = sorted(p.get_values(x).values())                                 # optional - cvxopt
sage: x[0]*b1 + x[1]*b2 - b3 + B1       # tol 1e-09                        # optional - cvxopt
[0.0 0.0]
[0.0 0.0]
solve()

Solve the problem.

Note

This method raises SDPSolverException exceptions when the solution cannot be computed for any reason (none exists, or the LP solver was not able to find it, etc…)

EXAMPLES:

sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False)       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1] + x[2])                                  # optional - cvxopt
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
sage: a2 = matrix([[7., -18.], [-18., 8.]])
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
sage: a4 = matrix([[33., -9.], [-9., 26.]])
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0.,   8., 5.]])
sage: b2 = matrix([[0.,  10.,  16.], [10., -10., -10.], [16., -10., 3.]])
sage: b3 = matrix([[-5.,   2., -17.], [2.,  -6.,   8.], [-17.,  8., 6.]])
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
sage: p.add_constraint(a1*x[0] + a3*x[2] <= a4)                            # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)                  # optional - cvxopt
sage: N(p.solve(), digits=4)                                               # optional - cvxopt
-3.225
sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False)       # optional - cvxopt
sage: x = p.new_variable()                                                 # optional - cvxopt
sage: p.set_objective(x[0] - x[1] + x[2])                                  # optional - cvxopt
sage: a1 = matrix([[-7., -11.], [-11., 3.]])
sage: a2 = matrix([[7., -18.], [-18., 8.]])
sage: a3 = matrix([[-2., -8.], [-8., 1.]])
sage: a4 = matrix([[33., -9.], [-9., 26.]])
sage: b1 = matrix([[-21., -11., 0.], [-11., 10., 8.], [0.,   8., 5.]])
sage: b2 = matrix([[0.,  10.,  16.], [10., -10., -10.], [16., -10., 3.]])
sage: b3 = matrix([[-5.,   2., -17.], [2.,  -6.,   8.], [-17.,  8., 6.]])
sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]])
sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4)                  # optional - cvxopt
sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4)                  # optional - cvxopt
sage: N(p.solve(), digits=4)                                               # optional - cvxopt
-3.154
solver_parameter(name, value=None)

Return or define a solver parameter

INPUT:

  • name (string) – the parameter

  • value – the parameter’s value if it is to be defined, or None (default) to obtain its current value.

Note

The list of available parameters is available at solver_parameter().

EXAMPLES:

sage: from sage.numerical.backends.generic_sdp_backend import get_solver
sage: p = get_solver(solver = "CVXOPT")                                    # optional - cvxopt
sage: p.solver_parameter("show_progress")                                  # optional - cvxopt
False
sage: p.solver_parameter("show_progress", True)                            # optional - cvxopt
sage: p.solver_parameter("show_progress")                                  # optional - cvxopt
True