from cvxpy import * # Create two scalar optimization variables. x = Variable() y = Variable() # Create two constraints. constraints = [x + y == 1, x - y >= 1] # Form objective. obj = Minimize(square(x - y)) # Form and solve problem. prob = Problem(obj, constraints) prob.solve() # The optimal dual variable (Lagrange multiplier) for # a constraint is stored in constraint.dual_value. print "optimal (x + y == 1) dual variable", constraints[0].dual_value print "optimal (x - y >= 1) dual variable", constraints[1].dual_value print "x - y value:", (x - y).value # Solving a problem with different solvers. x = Variable(2) obj = Minimize(norm(x, 2) + norm(x, 1)) constraints = [x >= 2] prob = Problem(obj, constraints) # Solve with ECOS. prob.solve(solver=ECOS) print "optimal value with ECOS:", prob.value # Solve with CVXOPT. prob.solve(solver=CVXOPT) print "optimal value with CVXOPT:", prob.value # Solve with SCS. prob.solve(solver=SCS) print "optimal value with SCS:", prob.value # Solve with ECOS. prob.solve(solver=ECOS, verbose=True) print "optimal value with ECOS:", prob.value # Solve with SCS and display output. opts = {"USE_INDIRECT": False} prob.solve(solver=SCS, verbose=True, solver_specific_opts=opts) print "optimal value with SCS:", prob.value # Get ECOS arguments. c, G, h, dims, A, b = prob.get_problem_data(ECOS) # Get CVXOPT arguments. c, G, h, dims, A, b = prob.get_problem_data(CVXOPT) # Get CVXOPT arguments. data, dims = prob.get_problem_data(SCS)