Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
A = spspa.vstack([
spspa.hstack([spspa.csc_matrix(np.ones((1, n))),
spspa.csc_matrix((1, k))]),
spspa.hstack([F.T, -spspa.eye(k)]),
spspa.hstack([spspa.eye(n), spspa.csc_matrix((n, k))])
]).tocsc()
lA = np.hstack([1., np.zeros(k), np.zeros(n)])
uA = np.hstack([1., np.zeros(k), np.ones(n)])
else:
assert False, "Unhandled version"
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
p = qp.quadprogProblem(Q, c, Aeq, beq, Aineq, bineq, lb, ub)
# Solve with GUROBI
resultsGUROBI = p.solve(solver=GUROBI, OutputFlag=0)
# Solve with OSQP
if i == 0:
options = {'eps_abs': 0.,
'eps_rel': 0.,
'splitting': 2,
# 'kkt_method': 'indirect',
# 'kkt_ind_alg': 'gmres',
# 'kkt_ind_tol': 1e-5,
# 'kkt_ind_maxiter': 10
}
probOSQP = osqp.OSQP(**options)
probOSQP.problem(Q, c, Aeq, beq, Aineq, bineq, lb, ub)
else:
probOSQP.set_problem_data(c=c, beq=beq, bineq=bineq)
resultsOSQP = probOSQP.solve()
print "\n"
print("Comparison OSQP - GUROBI")
print("-------------------------")
print "Difference in objective value %.8f" % \
np.linalg.norm(resultsOSQP.objval - resultsGUROBI.objval)
print "Norm of solution difference %.8f" % \
np.linalg.norm(resultsOSQP.x - resultsGUROBI.x)
print "Norm of dual eq difference %.8f" % \
np.linalg.norm(resultsOSQP.sol_dual_eq - resultsGUROBI.sol_dual_eq)
print "Norm of dual ineq difference %.8f" % \
np.linalg.norm(resultsOSQP.sol_dual_ineq -
def __init__(self, m, n, dens_lvl=1.0, osqp_opts={}):
# Generate data
x_true = np.random.randn(n) / np.sqrt(n)
A = spspa.random(m, n, density=dens_lvl, format='csc')
uA = A.dot(x_true) + 0.1*np.random.rand(m)
lA = -np.inf * np.ones(m)
q = -A.T.dot(np.random.rand(m))
P = spspa.csc_matrix((n, n))
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
Im = spspa.eye(m)
P = spspa.block_diag((spspa.csc_matrix((n, n)), Im), format='csc')
q = np.zeros(n + m)
A = spspa.vstack([
spspa.hstack([Ad, -Im]),
spspa.hstack([spspa.eye(n), spspa.csc_matrix((n, m))]),
]).tocsc()
lA = np.append(bd, np.zeros(n))
uA = np.append(bd, np.inf * np.ones(n))
else:
assert False, "Unhandled version"
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
q = np.append(np.zeros(m + n), self._gammas[0]*np.ones(n))
In = spspa.eye(n)
Onm = spspa.csc_matrix((n, m))
A = spspa.vstack([spspa.hstack([Ad, -spspa.eye(m),
spspa.csc_matrix((m, n))]),
spspa.hstack([In, Onm, -In]),
spspa.hstack([In, Onm, In])]).tocsc()
lA = np.hstack([bd, -np.inf * np.ones(n), np.zeros(n)])
uA = np.hstack([bd, np.zeros(n), np.inf * np.ones(n)])
else:
assert False, "Unhandled version"
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
# minimize np.ones(n).T * t
# subject to Ax = b
# -t <= x <= t
In = spspa.eye(n)
P = spspa.csc_matrix((2*n, 2*n))
q = np.append(np.zeros(n), np.ones(n))
A = spspa.vstack([spspa.hstack([Ad, spspa.csc_matrix((m, n))]),
spspa.hstack([In, -In]),
spspa.hstack([In, In])])
lA = np.hstack([bd, -np.inf * np.ones(n), np.zeros(n)])
uA = np.hstack([bd, np.zeros(n), np.inf * np.ones(n)])
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
P = spspa.block_diag((spspa.csc_matrix((n, n)), Im,
spspa.csc_matrix((m, m))), format='csc')
q = np.append(np.zeros(m + n), np.ones(m))
A = spspa.vstack([
spspa.hstack([A, Im, Im]),
spspa.hstack([A, -Im, -Im]),
spspa.hstack([spspa.csc_matrix((m, n)), Im,
spspa.csc_matrix((m, m))]),
spspa.hstack([spspa.csc_matrix((m, n + m)), Im])]).tocsc()
lA = np.hstack([b, -np.inf*np.ones(m), np.zeros(2*m)])
uA = np.hstack([np.inf*np.ones(m), b, np.ones(m), np.inf*np.ones(m)])
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)
# t >= 0
P = spspa.block_diag((2*spspa.eye(n), spspa.csc_matrix((m, m))),
format='csc')
q = np.append(np.zeros(n), gamma*np.ones(m))
A = spspa.vstack([
spspa.hstack([spspa.diags(b).dot(A), -spspa.eye(m)]),
spspa.hstack([spspa.csc_matrix((m, n)), spspa.eye(m)]),
]).tocsc()
lA = np.append(-np.inf * np.ones(m), np.zeros(m))
uA = np.append(-np.ones(m), np.inf * np.ones(m))
# Create a quadprogProblem and store it in a private variable
self._prob = qp.quadprogProblem(P, q, A, lA, uA)
# Create an OSQP object and store it in a private variable
self._osqp = osqp.OSQP(**osqp_opts)
self._osqp.problem(P, q, A, lA, uA)