
import osqp
import scipy.sparse as sparse
import numpy as np
# Define problem data
P = sparse.csc_matrix([[4., 1.], [1., 2.]])
q = np.array([1., 1.])
A = sparse.csc_matrix([[1., 0.], [0., 1.], [1., 0.], [0., 1.]])
l = np.array([0., 0., 0.2, 1.1])
u = np.array([1., 1., 0.2, 1.1])
# Create an OSQP object
prob = osqp.OSQP()
# Setup workspace and change alpha parameter
prob.setup(P, q, A, l, u, alpha=1.0)
# Solve problem
res = prob.solve()
print res.ximport cvxpyimport scipy.sparse as sparseimport numpy as np
# Define problem dataP = sparse.csc_matrix([[4., 1.], [1., 2.]])q = np.array([1., 1.])A = sparse.csc_matrix([[1., 0.], [0., 1.], [1., 0.], [0., 1.]])l = np.array([0., 0., 0.2, 1.1])u = np.array([1., 1., 0.2, 1.1])mu = 1 # Penalty parameter
# Define CVXPY problemx = cvxpy.Variable(2)# Standard objectiveobjective = .5 * cvxpy.quad_form(x, P) + q * x # Penalty part of the objectiveobjective += mu * (cvxpy.norm1(A * x - u) + cvxpy.norm1(-A * x + l))problem = cvxpy.Problem(cvxpy.Minimize(objective), [])results = problem.solve(solver=cvxpy.OSQP, verbose=True)P = sparse.csc_matrix([[2., -4., 0.],
[0., 4., -4.],
[0., 0., 2.]])
import cvxpy
import scipy.sparse as sparse
import numpy as np
import osqp
# Define problem data
P = sparse.csc_matrix([[2., -4., 0.],
[0., 4., -4.],
[0., 0., 2.]])
q = np.array([1., 1., 0.])
A = sparse.csc_matrix([[-1., 1., 0.],
[0., -1., 1.],
[1., 0., 0.],
[0., 0., 1.],
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
l = np.array([-0.3, -0.3, 0.2, 0.7, -0.3, -0.3, -0.3])
u = np.array([0.3, 0.3, 0.2, 0.7, 1.1, 1.1, 1.1])
mu = 1 # Penalty parameter
mu = 15 # Penalty parameter
P_csc = .5 * (P + P.transpose())
m = osqp.OSQP()
m.setup(P=P_csc, q=q, A=A, l=l, u=u, max_iter = 1000, verbose=True)
# m.warm_start(x=initialX)
results = m.solve() # this works
print results.x
# Define CVXPY problem
x = cvxpy.Variable(P.shape[1])
# Standard objective
objective = cvxpy.quad_form(x, P) + q * x
# Penalty part of the objective
objective += mu * (cvxpy.norm1(A * x - u) + cvxpy.norm1(-A * x + l))
problem = cvxpy.Problem(cvxpy.Minimize(objective), [])
results = problem.solve(solver=cvxpy.OSQP, verbose=False)
print results
print x.value
P_csc = .5 * (P + P.transpose())
import cvxpyimport osqpimport scipy.sparse as sparseimport numpy as np
# Define problem dataP = sparse.csc_matrix([[2., -4., 0.], [0., 4., -4.], [0., 0., 2.]])# Make symmetric and not indefiniteP = .5 * (P + P.T) + 1e-08 * sparse.eye(3)
q = np.array([1., 1., 0.])A = sparse.csc_matrix([[-1., 1., 0.], [0., -1., 1.], [1., 0., 0.], [0., 0., 1.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])l = np.array([-0.3, -0.3, 0.2, 0.7, -0.3, -0.3, -0.3])u = np.array([0.3, 0.3, 0.2, 0.7, 1.1, 1.1, 1.1])
mu = 15 # Penalty parameter
m = osqp.OSQP()m.setup(P=P, q=q, A=A, l=l, u=u, verbose=True)results_osqp = m.solve() # this works
# Define CVXPY problemx = cvxpy.Variable(P.shape[1])
# Standard objectiveobjective = cvxpy.quad_form(x, P) + q * x
# Penalty part of the objectiveobjective += mu * (cvxpy.norm1(A * x - u) + cvxpy.norm1(-A * x + l))
problem = cvxpy.Problem(cvxpy.Minimize(objective))objective_osqp_cvxpy = problem.solve(solver=cvxpy.OSQP, verbose=True)
print "Result OSQP Python x =", np.round(results_osqp.x, 3)print "Results OSQP CVXPY x =", np.round(x.value, 3)To view this discussion on the web visit https://groups.google.com/d/msgid/osqp/26ad2b60-08ac-495d-8c4b-7be765513c65%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "OSQP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+unsubscribe@googlegroups.com.
To post to this group, send email to os...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to osqp+uns...@googlegroups.com.