Skip to content

Commit

Permalink
handle missing distance value from the dictionnary of distance
Browse files Browse the repository at this point in the history
- gpdp ortools solver works with complete graph, therefore returns path not necessarly fulfilling the original routing problem. However due to recent callback implementation in ortools solver, we need to tackle the missing distance case to avoid exceptions. Therefore we put high cost to missing transition value
  • Loading branch information
g-poveda committed Mar 4, 2024
1 parent 768add0 commit a08524a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion discrete_optimization/pickup_vrp/gpdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def change_problem(self, new_problem: Problem) -> None:


class GPDP(Problem):
MAX_VALUE = 10e9

def __init__(
self,
number_vehicle: int,
Expand Down Expand Up @@ -302,7 +304,7 @@ def evaluate(self, variable: GPDPSolution) -> Dict[str, float]: # type: ignore
def compute_distance(self, path: List[Node]) -> float:
distance = 0.0
for i in range(len(path) - 1):
distance += self.distance_delta[path[i]][path[i + 1]]
distance += self.distance_delta[path[i]].get(path[i + 1], GPDP.MAX_VALUE)
return distance

def evaluate_function_node(self, node_1: Node, node_2: Node) -> float:
Expand Down

0 comments on commit a08524a

Please sign in to comment.