Ejemplo n.º 1
0
def test_remove_related_2nd_vehicle_different_terminal(
        solution_for_related_removal_different_terminals_2ndvehicle,
        monkeypatch):
    def mock_randint(start, end):
        return 2

    def mock_random_number():
        return 0.8

    monkeypatch.setattr("random.randint", mock_randint)
    monkeypatch.setattr("random.random", mock_random_number)

    solution = solution_for_related_removal_different_terminals_2ndvehicle
    solution._assign_request(1, 0, 2)
    solution._assign_request(2, 0, 4)
    solution._assign_request(0, 0, 6)
    assert destroy_factory.calculate_relatedness(solution, 0, 1, [0, 1, 2],
                                                 [3]) is None
    assert destroy_factory.calculate_relatedness(solution, 2, 0, [0, 1, 2],
                                                 [3]) is None
    assert round(
        destroy_factory.calculate_relatedness(solution, 2, 1, [0, 1, 2], [3]),
        4) == 34.4093
    #route 0: [6, 0, 2, 1, 4, 5, 3, 8], route 1: [7, 9]
    #Choose the most/more related request to remove (p >>>1)
    destroy_related = destroy_factory.produce_remove_related(2, 10)
    destroy_related(solution)
    route = solution.routes[0].route
    assert 2 not in route
    assert 5 not in route
    assert 1 not in route
    assert 4 not in route
    assert len(solution.request_bank) == 2
Ejemplo n.º 2
0
def test_remove_related_all_pickups_not_on_depot(solution_for_related_removal3,
                                                 monkeypatch):
    def mock_randint(start, end):
        return 2

    def mock_random_number():
        return 0.8

    monkeypatch.setattr("random.randint", mock_randint)
    monkeypatch.setattr("random.random", mock_random_number)

    solution = solution_for_related_removal3
    solution._assign_request(1, 0, 2)
    solution._assign_request(2, 0, 4)
    solution._assign_request(0, 0, 6)
    assert round(destroy_factory.calculate_relatedness(solution, 1, 0, [], []),
                 4) == 21.2986
    assert round(destroy_factory.calculate_relatedness(solution, 2, 0, [], []),
                 4) == 34.0237
    assert round(destroy_factory.calculate_relatedness(solution, 2, 1, [], []),
                 4) == 32.0611
    #route 0: [6, 0, 2, 1, 4, 5, 3, 8], route 1: [7, 9]
    #Choose the most/more related request to remove (p >>>1)
    destroy_related = destroy_factory.produce_remove_related(2, 10)
    destroy_related(solution)
    route = solution.routes[0].route
    assert 2 not in route
    assert 5 not in route
    assert 1 not in route
    assert 4 not in route
    assert len(solution.request_bank) == 2
Ejemplo n.º 3
0
def test_remove_related_pickup0_and_1_on_depot_all_deliveries_on_depot(
        solution_for_related_removal_all_deliveries_on_depot2, monkeypatch):
    def mock_randint(start, end):
        return 2

    def mock_random_number():
        return 0.8

    monkeypatch.setattr("random.randint", mock_randint)
    monkeypatch.setattr("random.random", mock_random_number)

    solution = solution_for_related_removal_all_deliveries_on_depot2
    solution._assign_request(1, 0, 2)
    solution._assign_request(2, 0, 4)
    solution._assign_request(0, 0, 6)
    assert destroy_factory.calculate_relatedness(solution, 0, 1, [0, 1],
                                                 [3, 4, 5]) is None
    assert destroy_factory.calculate_relatedness(solution, 2, 0, [0, 1],
                                                 [3, 4, 5]) is None
    assert destroy_factory.calculate_relatedness(solution, 2, 1, [0, 1],
                                                 [3, 4, 5]) is None
    #route 0: [6, 0, 2, 1, 4, 5, 3, 8], route 1: [7, 9]
    #Choose the most/more related request to remove (p >>>1)
    destroy_related = destroy_factory.produce_remove_related(2, 10)
    destroy_related(solution)
    route = solution.routes[0].route
    assert 2 not in route
    assert 5 not in route
    assert len(solution.request_bank) == 1
Ejemplo n.º 4
0
def test_remove_related_pickups_1_request_not_on_depot(
        solution_for_related_removal1, monkeypatch):
    def mock_randint(start, end):
        return 2

    def mock_random_number():
        return 0.8

    monkeypatch.setattr("random.randint", mock_randint)
    monkeypatch.setattr("random.random", mock_random_number)

    solution = solution_for_related_removal1
    #solution.problem.P[1].x_coord = 40
    #solution.problem.P[1].y_coord = 40
    solution._assign_request(1, 0, 2)
    solution._assign_request(2, 0, 4)
    solution._assign_request(0, 0, 6)
    assert round(
        destroy_factory.calculate_relatedness(solution, 1, 0, [0, 2], []),
        4) == 20.8065
    assert round(
        destroy_factory.calculate_relatedness(solution, 2, 0, [0, 2], []),
        4) == 14.5602
    assert round(
        destroy_factory.calculate_relatedness(solution, 2, 1, [0, 2], []),
        4) == 25.1103
    #route 0: [6, 0, 2, 1, 4, 5, 3, 8], route 1: [7, 9]
    #Choose the most/more related request to remove (p >>>1)
    destroy_related = destroy_factory.produce_remove_related(2, 10)
    destroy_related(solution)
    route = solution.routes[0].route
    assert 2 not in route
    assert 5 not in route
    assert 0 not in route
    assert 3 not in route
    assert len(solution.request_bank) == 2
Ejemplo n.º 5
0
def test_remove_related_2nd_vehicle_different_terminal_customers4(
        solution_for_related_removal_different_terminals_2ndvehicle2,
        monkeypatch):
    #Test with 4 customers, customer 3 located at terminal vehicle 2
    def mock_randint(start, end):
        return 3

    def mock_random_number():
        return 0.8

    monkeypatch.setattr("random.randint", mock_randint)
    monkeypatch.setattr("random.random", mock_random_number)

    solution = solution_for_related_removal_different_terminals_2ndvehicle2
    solution._assign_request(1, 0, 2)
    solution._assign_request(2, 0, 4)
    solution._assign_request(0, 0, 6)
    solution._assign_request(3, 1, 2)
    assert round(
        destroy_factory.calculate_relatedness(solution, 1, 0, [0, 1, 2, 3],
                                              [7]), 4) == 32.5576
    assert round(
        destroy_factory.calculate_relatedness(solution, 2, 0, [0, 1, 2, 3],
                                              [7]), 4) == 14.5602
    assert round(
        destroy_factory.calculate_relatedness(solution, 2, 1, [0, 1, 2, 3],
                                              [7]), 4) == 34.4093
    assert destroy_factory.calculate_relatedness(solution, 3, 0, [0, 1, 2, 3],
                                                 [7]) is None
    assert destroy_factory.calculate_relatedness(solution, 3, 1, [0, 1, 2, 3],
                                                 [7]) is None
    assert destroy_factory.calculate_relatedness(solution, 3, 2, [0, 1, 2, 3],
                                                 [7]) is None
    #route 0: [8, 0, 2, 1, 5, 6, 4, 10], route 1: [9, 3, 7, 11]
    #Choose the most/more related request to remove (p >>>1)
    destroy_related = destroy_factory.produce_remove_related(2, 10)
    destroy_related(solution)
    route = solution.routes[1].route
    assert 3 not in route
    assert 7 not in route
    assert len(solution.request_bank) == 1