Routing Model with Warm Start

896 views
Skip to first unread message

lu...@redmart.com

unread,
Nov 30, 2015, 2:09:17 AM11/30/15
to or-tools-discuss
Hi all,

I would like to use the CP solver to improve the solution of an heuristic I provide. Is it possible to initialize the solver with a warm start point ?

Thanks and Best
LF

Vincent Furnon

unread,
Dec 1, 2015, 12:57:25 PM12/1/15
to or-tools...@googlegroups.com
Yes.
If you want to improve a solution to a routing model, you can pass an assignment to RoutingModel::Solve(Assignment* assignment) which will be used as initial solution.
If you want to improve a solution in the general CP solver, you can use Solver::MakeLocalSearchPhase(Assignment* assignment, LocalSearchPhaseParameters* parameters) as decision builder, assignment being the solution to improve.

Vincent

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lu...@redmart.com

unread,
Dec 2, 2015, 11:02:29 PM12/2/15
to or-tools-discuss
Hi Vince, 

thanks. How to create an assigment object given the routes in Python ? I see that the routing model has a method: ReadAssignmentFromRoutes
which takes an std vector of std vectors as argument. However when I try to pass a list of lists in python I get the following error:

routes = [[0,1,2,3]]
model.ReadAssignmentFromRoutes(routes,True)

TypeError: in method 'RoutingModel_ReadAssignmentFromRoutes', argument 2 of type 'std::vector< std::vector< operations_research::RoutingModel::NodeIndex,std::allocator< operations_research::RoutingModel::NodeIndex > >,std::allocator< std::vector< operations_research::RoutingModel::NodeIndex,std::allocator< operations_research::RoutingModel::NodeIndex > > > > const &'

which would be the correct input format? Is that even exposed by the SWIG layer?

lu...@redmart.com

unread,
Dec 2, 2015, 11:51:40 PM12/2/15
to or-tools-discuss
Please also refer to my github ticket

Laurent Perron

unread,
Dec 3, 2015, 2:59:59 AM12/3/15
to or-tools-discuss
I have pushed the fix to github.

Thanks

TeLo

unread,
Sep 6, 2017, 10:54:46 AM9/6/17
to or-tools-discuss
hi vincent! 

I am trying to do this part of the warm start.... I already got an assignment as a vector of vectors.... now i want to use that warm start for a local search phase... but something is working.... what i have now in my second optimizer is: 

routing = pywrapcp.RoutingModel(num_locations, num_vehicles, 0)
search_parameters2 = pywrapcp.RoutingModel_DefaultSearchParameters()
current_solution= routing.ReadAssignmentFromRoutes(listOfLists,False)
assignment_new = routing.Solve(current_solution)
 search_parameters2.local_search_metaheuristic = (routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
 search_parameters2.time_limit_ms = search_time_limit * 1000

then i am using the callback to print every new solution found like this:
  SolutionCb = Cbs.SolutionFound(routing)
  routing.AddAtSolutionCallback(SolutionCb)

Unfortunately it outputs a 0, which means that it doesnt assign any cost to the new assignment.... is there an additional set up that i need to consider to make it work?

Thanks for your support 
Kindest Regards 
Reply all
Reply to author
Forward
0 new messages