Example #1
0
def test_reads_iain():
    """Test reading of SMTI-GRP instances."""
    instance = read_hrtc("tests/testfiles/hrtc-iain-small.instance")
    eq_(instance.number_of_single_agents_left(), 6)
    eq_(instance.number_of_couples_left(), 2)
    eq_(instance.number_of_single_agents_right(), 5)
    instance = read_hrtc("tests/testfiles/hrtc-iain.instance")
    eq_(instance.number_of_single_agents_left(), 88)
    eq_(instance.number_of_couples_left(), 11)
    eq_(instance.number_of_single_agents_right(), 11)
Example #2
0
def test_solve():
    """Solve simple instance
    """
    instance = read_hrtc("tests/testfiles/smti-simple.instance")
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 3)
    instance = read_hrtc("tests/testfiles/smti-nocomplete.instance")
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 2)
Example #3
0
def test_grp_solve():
    """Solve GRP instances
    """
    instance = read_hrtc("tests/testfiles/smti-grp-simple.instance")
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 3)
    instance = read_hrtc("tests/testfiles/smti-grp-simple.instance")
    model = MAX_SMTI_IP(instance)
    model.dummy_variables = True
    matching = model.solve()
    eq_(len(matching), 3)
Example #4
0
def test_reads():
    """Read in test1.instance and test2.instance and check some parameters.
    """
    instance = read_hrtc("tests/testfiles/test1.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.number_of_couples_left(), 0)
    eq_(instance.number_of_single_agents_right(), 2)

    instance = read_hrtc("tests/testfiles/test2.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.number_of_couples_left(), 2)
    eq_(instance.number_of_single_agents_right(), 2)
Example #5
0
def test_grp_solve_weighted():
    """Solve GRP instances
    """
    instance = read_hrtc("tests/testfiles/smti-grp-diff-maxweight.instance")
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 4)
    instance = read_hrtc("tests/testfiles/smti-grp-diff-maxweight.instance")
    instance.threshold(5)
    model = MAX_SMTI_IP(instance)
    model.weighted = True
    matching = model.solve()
    eq_(len(matching), 3)
Example #6
0
def test_dummy_variables_simple():
    """Solve simple instance using dummy variables
    """
    instance = read_hrtc("tests/testfiles/smti-simple.instance")
    model = MAX_SMTI_IP(instance)
    model.dummy_variables = True
    matching = model.solve()
    eq_(len(matching), 3)
Example #7
0
def test_grp_thresholds():
    """Solve GRP instances with thresholding
    """
    instance = read_hrtc("tests/testfiles/smti-grp-thresholds.instance")
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 3)
    instance = read_hrtc("tests/testfiles/smti-grp-thresholds.instance")
    instance.threshold(80)
    model = MAX_SMTI_IP(instance)
    matching = model.solve()
    eq_(len(matching), 2)
    instance = read_hrtc("tests/testfiles/smti-grp-thresholds.instance")
    instance.threshold(80)
    model = MAX_SMTI_IP(instance)
    model.weighted = True
    matching = model.solve()
    eq_(len(matching), 2)
Example #8
0
def test_max_weight_matching():
    """A simple SMTI-GRP instance.
    """
    instance = read_hrtc("tests/testfiles/smti-grp-simple.instance")
    eq_(max_weight_matching(instance), 200)
    instance.threshold(30)
    eq_(max_weight_matching(instance), 197)
    instance.threshold(50)
    eq_(max_weight_matching(instance), 177)
Example #9
0
def test_trims():
    """Test the trimming of preference lists
    """
    instance = read_hrtc("tests/testfiles/test1.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.number_of_couples_left(), 0)
    eq_(instance.number_of_single_agents_right(), 2)
    one = instance.single_agent_left("1")
    eq_(len(list(one.acceptable_agents())), 2)
    one.trim_after_worst(["1"])
    eq_(len(list(one.acceptable_agents())), 1)
Example #10
0
def test_make_couple():
    """Create a couple in an instance, ensure numbers change.
    """
    instance = read_hrtc("tests/testfiles/test1.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.number_of_couples_left(), 0)
    eq_(instance.number_of_single_agents_right(), 2)
    instance.make_couple_from_agent_pair_on_left()
    eq_(instance.number_of_single_agents_left(), 0)
    eq_(instance.number_of_couples_left(), 1)
    eq_(instance.number_of_single_agents_right(), 2)
Example #11
0
def test_reads_smti_grp():
    """Test reading of SMTI-GRP instances."""
    # With column/row headers
    instance = read_hrtc("tests/testfiles/smti-grp-simple.instance")
    eq_(instance.number_of_single_agents_left(), 3)
    eq_(instance.single_agent_left("1").weight_of("1"), 48)
    eq_(instance.single_agent_right("2").weight_of("3"), 55)
    eq_(instance.number_of_single_agents_right(), 3)
    # Without the header row/column, but a header showing number of rows and
    # columns instead
    instance = read_hrtc("tests/testfiles/smti-grp-noheader.instance")
    eq_(instance.number_of_single_agents_left(), 3)
    eq_(instance.single_agent_left("1").weight_of("1"), 48)
    eq_(instance.single_agent_right("2").weight_of("3"), 55)
    eq_(instance.number_of_single_agents_right(), 3)
    # An unbalanced instance.
    instance = read_hrtc("tests/testfiles/smti-grp-noheader-unbal.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.single_agent_left("1").weight_of("1"), 48)
    eq_(instance.single_agent_right("3").weight_of("2"), 94)
    eq_(instance.number_of_single_agents_right(), 3)
Example #12
0
def test_preprocess():
    """Test that preprocessing works as expected.
    """
    instance = read_hrtc("tests/testfiles/test1.instance")
    eq_(instance.number_of_single_agents_left(), 2)
    eq_(instance.number_of_couples_left(), 0)
    eq_(instance.number_of_single_agents_right(), 2)
    one = instance.single_agent_left("1")
    eq_(len(list(one.acceptable_agents())), 2)
    count = instance.preprocess()
    eq_(len(list(one.acceptable_agents())), 1)
    eq_(count, 2)
    eq_(len(list(instance.single_agent_left("2").acceptable_agents())), 1)
    eq_(len(list(instance.single_agent_right("1").acceptable_agents())), 2)
    eq_(len(list(instance.single_agent_right("2").acceptable_agents())), 0)
Example #13
0
def test_max_card_matching_hrct():
    """An instance with couples. Note that this isn't implemented.
    """
    instance = read_hrtc("tests/testfiles/test2.instance")
    eq_(max_card_matching(instance), -1)
Example #14
0
def test_max_card_matching_simple():
    """test1 is a simple instance of SMTI.
    """
    instance = read_hrtc("tests/testfiles/test1.instance")
    eq_(max_card_matching(instance), 2)
Example #15
0
def test_max_card_matching_smti_grp():
    """This is a simple instance of SMTI-GRP.
    """
    instance = read_hrtc("tests/testfiles/smti-grp-simple.instance")
    eq_(max_card_matching(instance), 3)
Example #16
0
def test_max_card_matching_hrt():
    """An instance with capacities.
    """
    instance = read_hrtc("tests/testfiles/hrt.instance")
    eq_(max_card_matching(instance), 759)
Example #17
0
def test_max_card_matching_smti():
    """This is a much larger SMTI instance.
    """
    instance = read_hrtc("tests/testfiles/smti.instance")
    eq_(max_card_matching(instance), 9941)