NetworkX KeyError on some datasets while calling prob.solve()
Closed this issue · 2 comments
The library is great and very easy to use ! While implementing on my own data, I am facing the following error :
Context : This error only occurs when certain delivery locations are added to my input data. What is the root cause of such errors and how can I clean/mitigate the same ? It seems to be a NetworkX specific issue.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-13-d9e2204baef3> in <module>
1 from vrpy import VehicleRoutingProblem
2 prob = VehicleRoutingProblem(G, load_capacity=4)
----> 3 prob.solve()
~\anaconda3\lib\site-packages\vrpy\main.py in solve(self, initial_routes, preassignments, pricing_strategy, cspy, exact, time_limit, solver, dive, greedy)
176
177 # Initialization
--> 178 self._initialize()
179
180 # Column generation
~\anaconda3\lib\site-packages\vrpy\main.py in _initialize(self)
263 else:
264 # Initial solution is computed with Clarke & Wright (or round trips)
--> 265 self._get_initial_solution()
266 # Initial routes are converted to digraphs
267 self._convert_initial_routes_to_digraphs()
~\anaconda3\lib\site-packages\vrpy\main.py in _get_initial_solution(self)
469 self.G, self.load_capacity, self.duration, self.num_stops
470 )
--> 471 alg.run()
472 logger.info("Initial solution found with value %s" % alg.best_value)
473 self._initial_routes = alg.best_routes
~\anaconda3\lib\site-packages\vrpy\clarke_wright.py in run(self)
31 def run(self):
32 """Runs Clark & Wrights savings algorithm."""
---> 33 self._initialize_routes()
34 self._get_savings()
35 for (i, j) in self._ordered_edges:
~\anaconda3\lib\site-packages\vrpy\clarke_wright.py in _initialize_routes(self)
43 # Create round trip
44 round_trip_cost = (
---> 45 self.G.edges["Source", v]["cost"] + self.G.edges[v, "Sink"]["cost"]
46 )
47 route = DiGraph(cost=round_trip_cost)
~\anaconda3\lib\site-packages\networkx\classes\reportviews.py in __getitem__(self, e)
928 def __getitem__(self, e):
929 u, v = e
--> 930 return self._adjdict[u][v]
931
932 # EdgeDataView methods
KeyError: 29
Any help would be much appreciated !!
An error is raised because there seems to be missing edges: at least one node is not connected to the Source and/or Sink. To start with, can you verify this ?
I checked and it seemed to be an issue specific to the data I am using. All nodes are connected but there is some corrupted data in the data file I am using and removing that row stops the error from happening.
I will get back once I do a more thorough deep-dive on my own raw data. You can mark the issue as closed until then.