Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
P = spspa.block_diag((2*D, 2*spspa.eye(k)), format='csc')
q = np.append(-mu / gamma, np.zeros(k))
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)
uA = np.array([np.inf, np.inf])
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'random':
# Random Example
n = 30
m = 50
# Generate random Matrices
Pt = sp.randn(n, n)
P = spspa.csc_matrix(np.dot(Pt.T, Pt))
q = sp.randn(n)
A = spspa.csc_matrix(sp.randn(m, n))
uA = 3 + sp.randn(m)
# lA = uA
lA = -3 + sp.randn(m)
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'lp':
# Random Example
n = 100
m = 50
# Generate random Matrices
P = spspa.csc_matrix(np.zeros((n, n)))
q = sp.randn(n)
A = spspa.vstack([spspa.csc_matrix(sp.randn(m, n)), spspa.eye(n)])
lA = np.append(- 3 + sp.randn(m), - 3 + sp.randn(n))
uA = np.append(3 + sp.randn(m), 3 + sp.randn(n))
p = qp.quadprogProblem(P, q, A, lA, uA)
else:
assert False, "Unknown example"
# Solve with CPLEX
resultsCPLEX = p.solve(solver=CPLEX, verbose=1)
# v >= 0
Im = spspa.eye(m)
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)
# Infeasible example
# P = spspa.eye(2)
P = spspa.csc_matrix((2, 2))
q = np.ones(2)
A = spspa.csc_matrix(np.array([[1, 0], [0, 1], [1, 1]]))
lA = np.array([0., 0., -1.])
uA = np.array([np.inf, np.inf, -1.])
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'unbounded':
# Unbounded example
P = spspa.csc_matrix((2, 2))
q = np.array([2, -1])
A = spspa.eye(2)
lA = np.array([0., 0.])
uA = np.array([np.inf, np.inf])
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'random':
# Random Example
n = 30
m = 50
# Generate random Matrices
Pt = sp.randn(n, n)
P = spspa.csc_matrix(np.dot(Pt.T, Pt))
q = sp.randn(n)
A = spspa.csc_matrix(sp.randn(m, n))
uA = 3 + sp.randn(m)
# lA = uA
lA = -3 + sp.randn(m)
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'lp':
# Random Example
uA = 3 + sp.randn(m)
# lA = uA
lA = -3 + sp.randn(m)
p = qp.quadprogProblem(P, q, A, lA, uA)
elif example == 'lp':
# Random Example
n = 100
m = 50
# Generate random Matrices
P = spspa.csc_matrix(np.zeros((n, n)))
q = sp.randn(n)
A = spspa.vstack([spspa.csc_matrix(sp.randn(m, n)), spspa.eye(n)])
lA = np.append(- 3 + sp.randn(m), - 3 + sp.randn(n))
uA = np.append(3 + sp.randn(m), 3 + sp.randn(n))
p = qp.quadprogProblem(P, q, A, lA, uA)
else:
assert False, "Unknown example"
# Solve with CPLEX
resultsCPLEX = p.solve(solver=CPLEX, verbose=1)
# Solve with GUROBI
resultsGUROBI = p.solve(solver=GUROBI, OutputFlag=1)
# Solve with OSQP. You can pass options to OSQP solver
resultsOSQP = p.solve(solver=OSQP, max_iter=5000,
eps_rel=1e-5,
eps_abs=1e-5,
alpha=1.6,
rho=0.1,
scale_steps=3,