3import scipy.sparse
as sp
5data = qp.QPALMData(3, 4)
7row = np.array([0, 0, 1, 1])
8col = np.array([0, 1, 0, 1])
9values = np.array([1, -1, -1, 2])
10data.Q = sp.csc_matrix((values, (row, col)), shape=(3, 3))
12data.q = np.array([-2, -6, 1])
13data.bmin = np.array([0.5, -10, -10, -10])
14data.bmax = np.array([0.5, 10, 10, 10])
16row = np.array([0, 1, 0, 2, 0, 3])
17col = np.array([0, 0, 1, 1, 2, 2])
18values = np.array([1, 1, 1, 1, 1, 1])
19data.A = sp.csc_matrix((values, (row, col)), shape=(4, 3))
21settings = qp.QPALMSettings()
22solver = qp.QPALMSolver(data, settings)
24sol_x = solver.solution.x
26assert abs(sol_x[0] - 5.5) < tol
27assert abs(sol_x[1] - 5.0) < tol
28assert abs(sol_x[2] - (-10)) < tol
31solver.warm_start(solver.solution.x, solver.solution.y)
33assert solver.info.iter == 0
37settings.eps_abs = 1e-10
40solver.update_settings(settings)
42sol_x = solver.solution.x
44assert abs(sol_x[0] - 5.5) < strict_tol
45assert abs(sol_x[1] - 5.0) < strict_tol
46assert abs(sol_x[2] - (-10)) < strict_tol
48settings.eps_abs = 1e-4
49settings.eps_rel = 1e-4
50solver.update_settings(settings)
53solver.update_bounds(bmin=data.bmin)
55sol_x = solver.solution.x
56assert abs(sol_x[0] - 8.5) < tol
57assert abs(sol_x[1] - 7) < tol
58assert abs(sol_x[2] - (-15)) < tol
67solver.update_q(data.q)
69sol_x = solver.solution.x
70assert abs(sol_x[0] - 0) < tol
71assert abs(sol_x[1] - 0) < tol
72assert abs(sol_x[2] - 0.5) < tol