import utils.codegen_utils as cu P = sparse.triu([[4., 1.], [1., 2.]], format='csc') q = np.ones(2) A = sparse.csc_matrix(np.array([[1., 1.], [1., 0.], [0., 1.], [0., 1.]])) l = np.array([1., 0., 0., -np.inf]) u = np.array([1., 0.7, 0.7, np.inf]) n = P.shape[0] m = A.shape[0] # New data q_new = np.array([2.5, 3.2]) l_new = np.array([0.8, -3.4, -np.inf, 0.5]) u_new = np.array([1.6, 1.0, np.inf, 0.5]) # Generate problem solutions sols_data = { 'x_test': np.array([0.3, 0.7]), 'y_test': np.array([-2.9, 0.0, 0.2, 0.0]), 'obj_value_test': 1.88, 'status_test': 'optimal', 'q_new': q_new, 'l_new': l_new, 'u_new': u_new } # Generate problem data cu.generate_problem_data(P, q, A, l, u, 'basic_qp', sols_data)
# Set random seed for reproducibility rg = Generator(PCG64(2)) n = 50 m = 150 # Generate random Matrices Pt = sparse.random(n, n, random_state=rg) P = Pt.T.dot(Pt) + sparse.eye(n) P = sparse.triu(P, format='csc') q = sp.randn(n) A = sparse.random(m, n, random_state=rg).tolil() # Lil for efficiency u = 3 + sp.randn(m) l = -3 + sp.randn(m) # Make random problem primal infeasible A[int(n/2), :] = A[int(n/2)+1, :] l[int(n/2)] = u[int(n/2)+1] + 10 * rg.random() u[int(n/2)] = l[int(n/2)] + 0.5 # Convert A to csc A = A.tocsc() # Generate problem solutions sols_data = {'status_test': 'primal_infeasible'} # Generate problem data cu.generate_problem_data(P, q, A, l, u, 'primal_infeasibility', sols_data)
import numpy as np from scipy import sparse import utils.codegen_utils as cu P = sparse.diags([0.617022, 0.92032449, 0.20011437, 0.50233257, 0.34675589], format='csc') q = np.array([-1.10593508, -1.65451545, -2.3634686, 1.13534535, -1.01701414]) A = sparse.csc_matrix((0, 5)) l = np.array([]) u = np.array([]) # Generate problem solutions sols_data = { 'x_test': np.array([1.79237542, 1.79775228, 11.81058885, -2.26014678, 2.93293975]), 'obj_value_test': -19.209752026813277, 'status_test': 'optimal' } # Generate problem data cu.generate_problem_data(P, q, A, l, u, 'unconstrained', sols_data)
n = 50 m = 100 N = int(m / 2) gamma = 1.0 b = np.hstack([np.ones(N), -np.ones(N)]) A_upp = sparse.random(N, n, density=0.5) A_low = sparse.random(N, n, density=0.5) Ad = sparse.vstack( [ A_upp / np.sqrt(n) + (A_upp != 0.0).astype(float) / n, A_low / np.sqrt(n) - (A_low != 0.0).astype(float) / n, ], format="csc", ) # osqp data Im = sparse.eye(m) P = sparse.block_diag([sparse.eye(n), sparse.csc_matrix((m, m))], format="csc") q = np.hstack([np.zeros(n), gamma * np.ones(m)]) A = sparse.vstack( [ sparse.hstack([sparse.diags(b).dot(Ad), -Im]), sparse.hstack([sparse.csc_matrix((m, n)), Im]), ], format="csc", ) l = np.hstack([-np.inf * np.ones(m), np.zeros(m)]) u = np.hstack([-np.ones(m), np.inf * np.ones(m)]) cu.generate_problem_data(P, q, A, l, u, "svm")
import numpy as np import scipy.sparse as spa import utils.codegen_utils as cu P = spa.csc_matrix(np.array([[2., 5.], [5., 1.]])) q = np.array([3., 4.]) A = spa.csc_matrix( np.array([[-1.0, 0.], [0., -1.], [-1., 3.], [2., 5.], [3., 4]])) l = -np.inf * np.ones(A.shape[0]) u = np.array([0., 0., -15., 100., 80.]) sols_data = {'sigma_new': 5} # Generate problem data cu.generate_problem_data(P, q, A, l, u, 'non_cvx', sols_data)
import numpy as np import scipy.sparse as spa import utils.codegen_utils as cu P = spa.csc_matrix(np.array([[2., 5.], [5., 1.]])) q = np.array([3., 4.]) A = spa.csc_matrix( np.array([[-1.0, 0.], [0., -1.], [-1., 3.], [2., 5.], [3., 4]])) l = -np.inf * np.ones(A.shape[0]) u = np.array([0., 0., -15., 100., 80.]) # Generate problem data cu.generate_problem_data(P, q, A, l, u, 'non_cvx')