-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suboptimal routes when using multiple depot #717
Comments
Start and End nodes are duplicated for each routes. Be sure to manipulate the index and not the node, using nodeToIndex, in order to manipulate the correct object index. or-tools/ortools/constraint_solver/routing.h Line 951 in 9487eb8
|
Also be sure to manipulate start and end node using related to #708 issue |
@braktar Start nodes are the buses start locations at my case, End nodes are same for all buses, which is the school location actually. Here is how I fill the locations list: self._start_locations = []
self._end_locations = []
for x in buses_locations:
# I add the school index each time for end_locations
self._end_locations.append(0)
# as the bus location is appended to locations, I add its index:
start_index= len(self._locations)
self._start_locations.append(start_index)
# the bus location ( start location is added to locations )
self._locations.append(x) @Mizux I do manipulate start and end node as: def solution_output(self):
routes = []
for vehicle_nbr in range(num_routes):
index = routing.Start(vehicle_nbr)
route = [index] # should be the bus start location
while not routing.IsEnd(index):
index = assignment.Value(routing.NextVar(index))
node_index = routing.IndexToNode(index)
route.append(node_index)
routing.End(vehicle_nbr)
routes.append(route)
return routes Out of range seems to be solved, but the results are strange, I have developed a front end tool to experiment with the OR Tools library, by which I can determine the strategy on the fly, here is what I got: yellow markers are the buses, notice the following:
Any advice? |
You should take a look at https://github.com/google/or-tools/blob/master/examples/python/cvrp.py As statute before index must be converted to a "node index" ie a location index so change your output routine to: def solution_output(self):
routes = []
for vehicle_nbr in range(num_routes):
index = routing.Start(vehicle_nbr)
route = [routing.routing.IndexToNode(index)] # should be the bus start location
while not routing.IsEnd(index):
index = assignment.Value(routing.NextVar(index))
node_index = routing.IndexToNode(index)
route.append(node_index)
route.append(routing.IndexToNode(routing.End(vehicle_nbr))) # to add the bus end location end aka start location
routes.append(route)
return routes |
well, without knowing which constraints you use it's difficult to say if result is reasonable or not. Also OR-Tools use a two steps algo:
search_parameters.log_search = True note: if your model is strongly constrained your first solution will be near to optimal and local search (step 2) won't increase so much the solution (i.e. could be disable), on the other hand if your constraints are loose solver can find a first "dirty" solution very fast but not "so reasonable". Also your image seems like route loop from yellow point as start and end node i.e. the red point in the center is not part of the other routes (only the orange one) (yellow -> {1, 2, 3} -> yellow) -> Did you use a vector of depots, ends nodes ? |
Did you use the cf: https://github.com/google/or-tools/blob/master/examples/python/cvrp.py#L258 |
yes, I use it, as here:
yes, I am using a vector of depots (start points), ends nodes (the same end point), as here: self._start_locations = []
self._end_locations = []
for x in buses_locations:
# I add the school index each time for end_locations
self._end_locations.append(0)
# as the bus location is appended to locations, I add its index:
start_index= len(self._locations)
self._start_locations.append(start_index)
# the bus location ( start location is added to locations )
self._locations.append(x) as here it seems that I am not doing local search? |
EDIT: Local search is enable by default (only the guided search is not) search_parameters.log_search = True Concerning first solution strategy doc here: https://developers.google.com/optimization/routing/routing_options#first-solution-strategy-options In result 3/4 point 1 is the cheapest arc to insert (compare to the farther checkpoint 3) so I would say even during the first strategy pass solver should choose it as good candidate. |
Thanks for the links, I have added local search, but I could not see any effect. # used_strategy is dynamic to make testing easy
search_parameters.first_solution_strategy = (
getattr(routing_enums_pb2.FirstSolutionStrategy, used_strategy)
)
# used_local_search_strategy is dynamic to make testing easy
search_parameters.local_search_metaheuristic = (
getattr(routing_enums_pb2.LocalSearchMetaheuristic, used_local_search_strategy)
) I have recorded this video so that you can have a look here: https://youtu.be/0HvW0Epubic In the video you will see two tabs for the same settings, the locations order is the only difference, I used all the possibilities, but I had the expected solution only when the locations were already sorted (from start to end ) |
Thanks for the video, I'll try to do some tests also... |
@Mizux Hi! did you try some tests on cases with multiple starting locations? |
Hi, in a related issue #727 (comment) and on my branch mizux/java. I figure out that few examples (and me too) sometime missmatch "node index" and "index". Are you sure to use the correct index when reading the solution etc ? |
if we consider reading the solution as phase 2 at which we use I tried for vehicle_nbr in range(num_routes):
index = routing.Start(vehicle_nbr)
route = [routing.IndexToNode(index)]
while not routing.IsEnd(index):
index = assignment.Value(routing.NextVar(index))
node_index = routing.NodeToIndex(index)
route.append(node_index)
route.append(
routing.IndexToNode(routing.End(vehicle_nbr)))
routes.append(route)
return routes but I got strange results for routes solution: <class 'list'>: [7, 1, 0, -1, 7, 0]
<class 'list'>: [8, 4, 3, 2, 0, 0] where can I find documentation about |
I agree with your phase 1 and phase 2 usage. I thing you have a miss take in your code. in the while loop second line index = assignment.Value(routing.NextVar(index))
node_index = routing.NodeToIndex(index) should be index = assignment.Value(routing.NextVar(index))
node_index = routing.IndexToNode(index) also your loop seems to have an error I mean you verify routes = []
for vehicle_nbr in range(num_routes):
index = routing.Start(vehicle_nbr)
route = []
while not routing.IsEnd(index):
node_index= routing.IndexToNode(index)
route.append(node_index)
index = assignment.Value(routing.NextVar(index))
route.append(routing.IndexToNode(index))
routes.append(route)
return routes Personally I use this loop to display store result... Unfortunately there is not doc on NodeIndex vs Index and half of our examples are broken, I'm currently trying to fix all examples when possible. ProTips: use ```python when writing code block to have syntax coloration (I try to fixed few of your comments but if you can do it yourself ;)) |
Dear Mizux, I've fixed the loop now as you've mentioned, unfortunately, I am still getting un-reasonable solution for a trivial case, I've recorded another video which can see here Two start locations, the algorithm decides to pick the far start location instead of the close one: Ah .. what could be wrong? |
@hopewise any change you are willing to share the source code of the front end tool you developed? I would find it very useful :) |
@ilaif I will try to ask that company I was working with.. as I don't have that source code.. basically what I did is a frontend for testing the algorithm.. and as for the issue I was having above, it was related to calculating distances in the matrix.. it wasn't calculated correctly.. |
That was a react project I wrote while learning about or-tools as well, unfortunately, I don't have access to that react project now.. I love visualization, it makes learning and reasoning much easier.. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I have locations list of length 39, including 1 starting locations, 4 end locations.
In routes solution I got node at 38, 39, 40, 41, so there are 3 nodes out of location's list range, each one in a route.
What can be the reason for that?
The text was updated successfully, but these errors were encountered: