Example #1
0
def test_insert_regret_k4_basic(solution3):
    noise = False
    solution3._delta_f = numpy.array([[15, 9, 12], [8, 6, 4], [3, 2, 1]],
                                     dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(4, single_run=True)
    with pytest.raises(IndexError):
        heuristic(solution3, noise)
Example #2
0
def test_insert_regret_k3_with_nan(solution3):
    noise = False
    #pytest.set_trace()
    solution3._delta_f = numpy.array(
        [[15, 9, 12], [None, None, None], [3, 2, 1]], dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(3, single_run=True)
    outcome = heuristic(solution3, noise)
    #expected = numpy.array([9, None, 3], dtype = float)
    #expected = numpy.array([0])
    #expected = 1
    expected = [7, 0, 3, 10]
    outcome = solution3.routes[1].route
    assert (expected == outcome)
Example #3
0
def test_insert_regret_k3_basic_with_ties(solution3):
    noise = False
    #    pytest.set_trace()
    solution3._delta_f = numpy.array([[22, 9, 12], [18, 6, 4], [3, 2, 1]],
                                     dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(3, single_run=True)
    heuristic(solution3, noise)
    #expected = numpy.array([16, 16, 3], dtype = float)
    #expected = numpy.array([0, 1])
    #expected = 2
    expected = [8, 1, 4, 11]
    outcome = solution3.routes[2].route
    assert (expected == outcome)
Example #4
0
def test_insert_regret_k_with_inf(solution3):
    noise = False
    #pytest.set_trace()
    solution3._delta_f = numpy.array(
        [[15, 9, numpy.Inf], [numpy.inf, numpy.inf, numpy.inf], [1, 2, 3]],
        dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(single_run=True)
    outcome = heuristic(solution3, noise)
    #expected = numpy.array([6, 0, 1], dtype=float)
    #expected = numpy.array([0])
    #expected = 1
    expected = [7, 0, 3, 10]
    outcome = solution3.routes[1].route
    assert (expected == outcome)
Example #5
0
def test_insert_regret_k3_with_inf_nan_ties(solution4):
    noise = False
    #pytest.set_trace()
    solution4._delta_f = numpy.array(
        [[15, 9, numpy.Inf], [numpy.Inf, numpy.Inf, numpy.Inf],
         [None, None, None], [1, 2, 6]],
        dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(3, single_run=True)
    outcome = heuristic(solution4, noise)
    #expected = numpy.array([6, 0, None, 6], dtype=float)
    #expected = numpy.array([3])
    #expected = 0
    expected = [8, 3, 7, 11]
    outcome = solution4.routes[0].route
    assert (expected == outcome)
Example #6
0
def test_insert_regret_k_basic_noise(solution3):
    noise = True

    def temp(x, y):
        return 0.8

    random.uniform = temp
    #pytest.set_trace()
    solution3._delta_f = numpy.array([[15, 9, 12], [8, 6, 4], [3, 2, 1]],
                                     dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(single_run=True)
    heuristic(solution3, noise)
    #expected = numpy.array([3, 2, 1], dtype = float)
    #expected = numpy.array([0])
    #expected = 1
    expected = [7, 0, 3, 10]
    outcome = solution3.routes[1].route
    assert (expected == outcome)
Example #7
0
def test_insert_regret_k_single_route(solution3):
    noise = False
    solution3._delta_f = numpy.array([[7], [8], [9]], dtype=float)
    heuristic = repair_factory.produce_insert_regret_k(single_run=True)
    with pytest.raises(IndexError):
        heuristic(solution3, noise)