예제 #1
0
def test_parses_scenarios_small_instance():
    """
    Tests if the parser correctly reads the scenarios of a small test instance.
    """
    parser = StochParser("data/test/stoch_small_scenarios_problem.sto")
    parser.parse()

    assert_equal(len(parser.scenarios), 2)

    #  SC SCEN01    ROOT      0.333333       STAGE-2
    #     RHS       C1        1              C2        5.0001
    #     X1        C1        5
    first = Scenario("SCEN01", "ROOT", "STAGE-2", 0.333333)
    first.add_modification("C1", "RHS", 1)
    first.add_modification("C2", "RHS", 5.001)
    first.add_modification("C1", "RHS", 5)

    _compare_scenarios(parser.scenarios[0], first)

    #  SC SCEN02    SCEN01    0.666667       STAGE-3
    #     RHS       C1        8
    #     X2        C2        7
    second = Scenario("SCEN02", "SCEN01", "STAGE-3", 0.666667)
    second.add_modification("C1", "RHS", 8)
    second.add_modification("C1", "X2", 7)

    _compare_scenarios(parser.scenarios[1], second)
예제 #2
0
def test_modifications(num_modifications):
    scen = Scenario("test", "", "", 0.5)

    modifications = []

    for idx in range(num_modifications):
        constr = f"Constraint {idx}"
        var = f"Variable {idx}"
        value = idx

        modifications.append((constr, var, value))
        scen.add_modification(constr, var, value)

    assert_equal(scen.modifications, modifications)
예제 #3
0
def test_modifications_from_root_no_parent():
    """
    Should return the same as the regular modifications property, as there is
    no additional parent information.
    """
    scen = Scenario("test", "root", "", 0.5)
    assert_(scen.branches_from_root())

    modifications = [("constr1", "row1", 1),
                     ("constr2", "row2", 3.5),
                     ("constr3", "row3", 10.8)]

    for constr, var, value in modifications:
        scen.add_modification(constr, var, value)

    assert_equal(scen.modifications, modifications)
    assert_equal(scen.modifications_from_root(), scen.modifications)
예제 #4
0
def test_modifications_from_root_overwrites_parent():
    """
    Tests if child modifications of the same constraint/variable pair overwrite
    parent modifications, as they should (the child is more specific).
    """
    parent = Scenario("parent", "root", "", 0.5)
    assert_(parent.branches_from_root())

    parent.add_modification("constr1", "row1", 1)
    parent.add_modification("constr2", "row2", 2.5)

    scen = Scenario("test", "parent", "", 0.5)
    scen.add_modification("constr2", "row2", 8.1)

    expected = [("constr1", "row1", 1), ("constr2", "row2", 8.1)]
    assert_equal(scen.modifications_from_root(), expected)
예제 #5
0
def test_modifications_from_root_gets_all():
    """
    Tests if modifications_from_root gets all modifications, both from the
    child scenario, and its parent.
    """
    parent = Scenario("parent", "root", "", 0.5)
    assert_(parent.branches_from_root())

    parent.add_modification("constr1", "row1", 1)
    parent.add_modification("constr2", "row2", 2.5)

    scen = Scenario("test", "parent", "", 0.5)
    scen.add_modification("constr3", "row3", 8.1)

    expected = parent.modifications + scen.modifications
    assert_equal(scen.modifications_from_root(), expected)
예제 #6
0
def test_parses_scenarios_sizes3():
    """
    Tests if the scenarios of the small sizes3.sto are parsed correctly.
    """
    parser = StochParser("data/sizes/sizes3")
    parser.parse()

    assert_equal(len(parser.scenarios), 3)

    # Full first scenario of the sizes3.sto file.
    desired = Scenario("SCEN01", "ROOT", "STAGE-2", 0.333333)
    desired.add_modification("D01JJ02", "RHS", 1.750)
    desired.add_modification("D02JJ02", "RHS", 5.250)
    desired.add_modification("D03JJ02", "RHS", 8.750)
    desired.add_modification("D04JJ02", "RHS", 7.000)
    desired.add_modification("D05JJ02", "RHS", 24.500)
    desired.add_modification("D06JJ02", "RHS", 17.500)
    desired.add_modification("D07JJ02", "RHS", 10.500)
    desired.add_modification("D08JJ02", "RHS", 8.750)
    desired.add_modification("D09JJ02", "RHS", 8.750)
    desired.add_modification("D10JJ02", "RHS", 3.500)

    _compare_scenarios(parser.scenarios[0], desired)