Skip to content

Commit

Permalink
fix PyVRP version conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
heatingma committed May 7, 2024
1 parent 185a770 commit 161be43
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ml4co_kit/solver/cvrp/pyvrp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import time
import numpy as np
from tqdm import tqdm
Expand All @@ -8,6 +9,12 @@
from .base import CVRPSolver


if sys.version_info.major == 3 and sys.version_info.minor == 8:
CP38 = True
else:
CP38 = False


class CVRPPyVRPSolver(CVRPSolver):
def __init__(
self,
Expand Down Expand Up @@ -46,9 +53,9 @@ def _solve(
cvrp_model.add_vehicle_type(capacity=capacity, num_available=max_num_available)
clients = [
cvrp_model.add_client(
x=self.round_func(nodes_coord[idx][0]),
y=self.round_func(nodes_coord[idx][1]),
demand=self.round_func(demands[idx])
self.round_func(nodes_coord[idx][0]),
self.round_func(nodes_coord[idx][1]),
self.round_func(demands[idx])
) for idx in range(0, len(nodes_coord))
]
locations = [depot] + clients
Expand All @@ -57,7 +64,8 @@ def _solve(
distance = self.get_distance(x1=(frm.x, frm.y), x2=(to.x, to.y))
cvrp_model.add_edge(frm, to, distance=self.round_func(distance))
res = cvrp_model.solve(stop=MaxRuntime(self.time_limit))
routes = res.best.get_routes()

routes = res.best.get_routes() if CP38 else res.best.routes()
tours = [0]
for route in routes:
tours += route.visits()
Expand Down

0 comments on commit 161be43

Please sign in to comment.