wish: let doRoute return distance or cost of solution
esidebo opened this issue · 2 comments
I'd like to know if I can somehow extract the cost of the solution found by doRoute. The reason is that I'm trying to solve the Travelling-Salesman-Problem (TSP) with many destinations. For this I need the "distance" (=cost) between each destination in the problem, which I can let doRoute compute. But doRoute only returns the nodes. Is there a way to extract that?
Let me ask while posting: do I understand correct that pyroutelib finds the best route with the A* algorithm, where edges are weighted by weights as given at
Line 60 in cb2f8ae
I'd like to know if I can somehow extract the cost of the solution found by doRoute.
router.routing contains costs between nodes.
You would get the total cost of a route like that, assuming router
is the pyroutelib3.Router instance and route
is the returned list of nodes:
total_cost = 0.0
for idx in range(len(route) - 1):
total_cost += router.routing[route[idx]][route[idx+1]
I didn't find any documentation on how the optimization is actually done.
Closing, explained in the comment above.