def test_testproblem_init(problems_list):
    p1 = CVXProblem(**problems_list[0])
    assert p1.metadata["cone_types"] == set([s.LP])
    p2 = CVXProblem(**problems_list[1])
    assert p2.metadata["cone_types"] == set([s.LP, s.SOCP])
    p3 = CVXProblem(**problems_list[2])
    assert p3.metadata["cone_types"] == set([s.LP, s.SOCP, s.SDP])
    p4 = CVXProblem(**problems_list[3])
    assert p4.metadata["cone_types"] == set([s.LP, s.EXP])
    p5 = CVXProblem(**problems_list[4])
    assert p5.metadata["cone_types"] == set([s.LP, s.MIP])
def test_read(problems_list):
    mock_import = MagicMock()
    mock_import.return_value = MagicMock(problems=problems_list)
    if sys.version_info[0] < 3:  # Python 2.x
        with patch("__builtin__.__import__", mock_import):
            problems = CVXProblem.read("fileID", "problemDir")
            assert [problem.problemID for problem in problems] == [
                "lp_prob", "socp_prob", "sdp_prob", "exp_prob", "mip_prob"
            ]
    else:  # Python 3.x
        with patch("builtins.__import__", mock_import):
            problems = CVXProblem.read("fileID", "problemDir")
            assert [problem.problemID for problem in problems] == [
                "lp_prob", "socp_prob", "sdp_prob", "exp_prob", "mip_prob"
            ]
def mip_prob():
    # {LP, MIP}
    x = cp.Int(1)
    prob = cp.Problem(cp.Minimize(x),[x >= 0])
    return CVXProblem(problemID="mip_prob",
                      problem=prob,
                      opt_val=0.0)
def lp_prob():
    # {LP}
    x = cp.Variable()
    prob = cp.Problem(cp.Minimize(x), [x >= 2])
    return CVXProblem(problemID="lp_prob",
                      problem=prob,
                      opt_val=2.0)
Exemple #5
0
def exp_prob():
    # {LP, EXP}
    x = cp.Variable(2)
    A = np.eye(2)
    prob = cp.Problem(cp.Minimize(cp.log_sum_exp(x)), [A * x >= 0])
    return CVXProblem(problemID="exp_prob",
                      problem=prob,
                      opt_val=float('-inf'))
Exemple #6
0
def empty_prob():
    x = cp.Variable()
    prob = cp.Problem(cp.Minimize(x))
    return CVXProblem(problemID="empty_prob",
                      problem=prob,
                      opt_val=float('-inf'))