I'm trying to solve a vehicle routing problem with an initial assignment, and it seems that either I'm doing something wrong with setting the search parameters, or the model reaches a local minimum and returns a solution before reaching my desired time limit.
I suspect the former of the two options, but I don't see what I should be doing differently.
Here is how I go about it.
const Assignment *initial_solution =
routing.ReadAssignmentFromRoutes(initial_routes, false);
RoutingSearchParameters searchParameters;
searchParameters.set_local_search_metaheuristic(
LocalSearchMetaheuristic::GUIDED_LOCAL_SEARCH);
searchParameters.mutable_time_limit()->set_seconds(600);
searchParameters.set_log_search(true);
const Assignment *solution = routing.SolveFromAssignmentWithParameters(initial_solution, searchParameters);
where initial_routes
is a valid route.
I would hugely appreciate if anyone could give me any pointers as to what I'm doing wrong.
Edit 1: Following Laurent's suggestion, I tried:
RoutingSearchParameters searchParameters;
searchParameters.set_local_search_metaheuristic(
LocalSearchMetaheuristic::GUIDED_LOCAL_SEARCH);
searchParameters.mutable_time_limit()->set_seconds(600);
searchParameters.set_log_search(true);
routing.CloseModelWithParameters(searchParameters);
const Assignment *solution =
routing.Solve(initial_solution);
(Also tried with SolveFromAssignmentWithParameters with the same results)
Which gives me a following message preceeding a Segmentation fault Invalid RoutingSearchParameters: local_search_neighborhood_operator.use_relocate should be set to BOOL_TRUE or BOOL_FALSE instead of BOOL_UNSPECIFIED (value: 0)
I tried to find the particular option, but the only mention of use_relocate that I found was for RoutingSearchParameters_LocalSearchNeighborhoodOperators
type object.
So then I tried to initialize the searchParameters
to the default search parameters, but they once again seem to not get registered. Instead, I get a warning about the model already being closed.
Thank you again for any ideas.
Edit 2: I found the github issue with the bug ( link ) and the problem turned out to be the order that I do the things in. Fixed following the issue solution, thanks again
Known bug. You need to close the model with the parameters before solving.
And you should use
search_parameters = DefaultRoutingSearchParameters();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.