Exemple #1
0
def test_feasible(use_indirect):
    for i in range(num_feas):
        data, p_star = tools.gen_feasible(K, n=m // 3, density=0.1)
        solver = scs.SCS(data, K, use_indirect=use_indirect, **opts)
        sol = solver.solve()
        assert_almost_equal(np.dot(data["c"], sol["x"]), p_star, decimal=2)
        assert_almost_equal(np.dot(-data["b"], sol["y"]), p_star, decimal=2)
Exemple #2
0
def test_solve_infeasible(use_indirect, gpu):
    data = tools.gen_infeasible(K, n=m // 2)
    solver = scs.SCS(data, K, use_indirect=use_indirect, gpu=gpu, **params)
    sol = solver.solve()
    y = sol["y"]
    np.testing.assert_array_less(np.linalg.norm(data["A"].T @ y), 1e-3)
    np.testing.assert_array_less(data["b"].T @ y, -0.1)
    np.testing.assert_almost_equal(y, tools.proj_dual_cone(y, K), decimal=4)
Exemple #3
0
def test_solve_unbounded(use_indirect, gpu):
    data = tools.gen_unbounded(K, n=m // 2)
    solver = scs.SCS(data, K, use_indirect=use_indirect, gpu=gpu, **params)
    sol = solver.solve()
    x = sol["x"]
    s = sol["s"]
    np.testing.assert_array_less(np.linalg.norm(data["A"] @ x + s), 1e-3)
    np.testing.assert_array_less(data["c"].T @ x, -0.1)
    np.testing.assert_almost_equal(s, tools.proj_cone(s, K), decimal=4)
Exemple #4
0
def test_solve_feasible(use_indirect, gpu):
    data, p_star = tools.gen_feasible(K, n=m // 3, density=0.1)
    solver = scs.SCS(data, K, use_indirect=use_indirect, gpu=gpu, **params)
    sol = solver.solve()
    x = sol["x"]
    y = sol["y"]
    s = sol["s"]
    np.testing.assert_almost_equal(np.dot(data["c"], x), p_star, decimal=3)
    np.testing.assert_almost_equal(np.dot(data["c"], x), p_star, decimal=3)
    np.testing.assert_array_less(np.linalg.norm(data["A"] @ x - data["b"] + s),
                                 1e-3)
    np.testing.assert_array_less(np.linalg.norm(data["A"].T @ y + data["c"]),
                                 1e-3)
    np.testing.assert_almost_equal(s.T @ y, 0.0)
    np.testing.assert_almost_equal(s, tools.proj_cone(s, K), decimal=4)
    np.testing.assert_almost_equal(y, tools.proj_dual_cone(y, K), decimal=4)
Exemple #5
0
def test_warm_start(use_indirect):
    # max x
    # s.t 0 <= x <= 1
    solver = scs.SCS(data, cone, use_indirect=use_indirect, verbose=False)
    sol = solver.solve()
    assert_almost_equal(sol["x"][0], 1.0, decimal=2)

    sol = solver.solve()
    assert_almost_equal(sol["x"][0], 1.0, decimal=2)
    assert_array_less(sol["info"]["iter"], 10)

    sol = solver.solve(x=None)
    sol = solver.solve(x=np.array([7.0]), y=None, s=None)
    sol = solver.solve(
        x=np.array([7.0]), y=np.array([1.0, 2.0]), s=np.array([3.0, 4.0])
    )

    with pytest.raises(ValueError):
        sol = solver.solve(x=np.array([1.0, 2.0]))
Exemple #6
0
def test_update(use_indirect):
    # max x
    # s.t 0 <= x <= 1
    solver = scs.SCS(data, cone, use_indirect=use_indirect, verbose=False)
    sol = solver.solve()
    assert_almost_equal(sol["x"][0], 1.0, decimal=2)

    # min x
    # s.t 0 <= x <= 1
    c_new = np.array([1.0])
    solver.update(c=c_new)
    sol = solver.solve()
    assert_almost_equal(sol["x"][0], 0.0, decimal=2)

    # max x
    # s.t -1 <= x <= 1
    b_new = np.array([1.0, 1.0])
    solver.update(b=b_new)
    sol = solver.solve()
    assert_almost_equal(sol["x"][0], -1.0, decimal=2)
Exemple #7
0
def test_unbounded(use_indirect):
    for i in range(num_unb):
        data = tools.gen_unbounded(K, n=m // 2)
        solver = scs.SCS(data, K, use_indirect=use_indirect, **opts)
        sol = solver.solve()
        check_unbounded(sol)
Exemple #8
0
def test_infeasible(use_indirect):
    for i in range(num_infeas):
        data = tools.gen_infeasible(K, n=m // 2)
        solver = scs.SCS(data, K, use_indirect=use_indirect, **opts)
        sol = solver.solve()
        check_infeasible(sol)
Exemple #9
0
def test_problems(cone, use_indirect, expected):
    solver = scs.SCS(data, cone=cone, use_indirect=use_indirect, verbose=False)
    sol = solver.solve()
    assert_almost_equal(sol["x"][0], expected, decimal=2)