def test_subproblem(self, n):
     data = SolomonDataSet(
         path="benchmarks/data/cvrptw/", instance_name="C101.txt", n_vertices=n
     )
     self.G = data.G
     best_values_lp = None
     lp_iter = []
     times_lp = []
     for r in range(REPS_LP):
         prob = VehicleRoutingProblem(
             self.G, load_capacity=data.max_load, time_windows=True
         )
         start = time()
         prob.solve(cspy=False)
         best_value_lp = prob.best_value
         times_lp.append(time() - start)
         lp_iter.append(prob._iteration)
         del prob
     best_values_cspy = []
     times_cspy = []
     iter_cspy = []
     for r in range(REPS_CSPY):
         prob = VehicleRoutingProblem(
             self.G, load_capacity=data.max_load, time_windows=True
         )
         start = time()
         prob.solve(cspy=True, pricing_strategy="Exact")
         times_cspy.append(time() - start)
         best_values_cspy.append(prob.best_value)
         iter_cspy.append(prob._iteration)
         prob.check_arrival_time()
         prob.check_departure_time()
         del prob
     assert all(best_value_lp == val_cspy for val_cspy in best_values_cspy)
     write_avg(n, times_cspy, iter_cspy, times_lp, lp_iter)
示例#2
0
class TestIssue101_small:
    def setup(self):
        self.G = DiGraph()
        self.G.add_edge("Source", 1, cost=5)
        self.G.add_edge("Source", 2, cost=5)
        self.G.add_edge(1, "Sink", cost=5)
        self.G.add_edge(2, "Sink", cost=5)
        self.G.add_edge(1, 2, cost=1)
        self.G.nodes[1]["lower"] = 0
        self.G.nodes[1]["upper"] = 20
        self.G.nodes[2]["lower"] = 0
        self.G.nodes[2]["upper"] = 20
        self.G.nodes[1]["service_time"] = 5
        self.G.nodes[2]["service_time"] = 5
        self.G.nodes[1]["demand"] = 8
        self.G.nodes[2]["demand"] = 8
        self.prob = VehicleRoutingProblem(self.G,
                                          load_capacity=10,
                                          time_windows=True)

    def test_cspy(self):
        self.prob.solve()
        self.prob.check_arrival_time()
        self.prob.check_departure_time()

    def test_lp(self):
        self.prob.solve(cspy=False)
        self.prob.check_arrival_time()
        self.prob.check_departure_time()
示例#3
0
文件: test_toy.py 项目: Kuifje02/vrpy
 def test_LP_schedule(self):
     """Tests column generation procedure on toy graph"""
     prob = VehicleRoutingProblem(
         self.G,
         num_stops=3,
         time_windows=True,
     )
     prob.solve(cspy=False)
     prob.check_arrival_time()
     prob.check_departure_time()
示例#4
0
文件: test_toy.py 项目: Kuifje02/vrpy
 def test_cspy_schedule(self):
     """Tests if final schedule is time-window feasible"""
     prob = VehicleRoutingProblem(
         self.G,
         num_stops=3,
         time_windows=True,
     )
     prob.solve()
     assert prob.departure_time[1]["Source"] == 0
     assert prob.arrival_time[1]["Sink"] in [41, 62]
     prob.check_arrival_time()
     prob.check_departure_time()
示例#5
0
class TestsSolomon:
    def setup(self):
        """
        Solomon instance c101, 25 first nodes only including depot
        """
        data = SolomonDataSet(path="benchmarks/data/cvrptw/",
                              instance_name="C101.txt",
                              n_vertices=25)
        self.G = data.G
        self.n_vertices = 25
        self.prob = VehicleRoutingProblem(self.G,
                                          load_capacity=data.max_load,
                                          time_windows=True)
        initial_routes = [
            ["Source", 13, 17, 18, 19, 15, 16, 14, 12, 1, "Sink"],
            ["Source", 20, 24, 23, 22, 21, "Sink"],
            ["Source", 5, 3, 7, 8, 10, 11, 6, 4, 2, "Sink"],
            ["Source", 9, "Sink"],
        ]
        # Set repeating solver arguments
        self.solver_args = {
            "pricing_strategy": "BestPaths",
            "initial_routes": initial_routes,
        }

    def test_setup_instance_name(self):
        assert self.G.graph["name"] == "C101." + str(self.n_vertices)

    def test_setup_vehicle_capacity(self):
        assert self.G.graph["vehicle_capacity"] == 200

    def test_setup_nodes(self):
        # extra node for the Sink
        assert len(self.G.nodes()) == self.n_vertices + 1

    def test_setup_edges(self):
        assert len(
            self.G.edges()) == self.n_vertices * (self.n_vertices - 1) + 1

    def test_subproblem_lp(self):
        # benchmark result
        # e.g., in Feillet et al. (2004)
        self.prob.solve(**self.solver_args, cspy=False)
        assert round(self.prob.best_value, -1) in [190, 200]
        self.prob.check_arrival_time()
        self.prob.check_departure_time()

    def test_subproblem_cspy(self):
        self.prob.solve(**self.solver_args, cspy=True)
        assert round(self.prob.best_value, -1) in [190, 200]
        self.prob.check_arrival_time()
        self.prob.check_departure_time()
示例#6
0
class TestIssue101_large:
    def setup(self):
        G = read_gpickle("benchmarks/tests/graph_issue101")
        self.prob = VehicleRoutingProblem(G, load_capacity=80)
        self.prob.time_windows = True

    # def test_lp(self):
    #     self.prob.solve(cspy=False, solver="gurobi")
    #     self.prob.check_arrival_time()
    #     self.prob.check_departure_time()

    def test_cspy(self):
        self.prob.solve(pricing_strategy="Exact")
        self.prob.check_arrival_time()
        self.prob.check_departure_time()