VRP Column generation

178 views
Skip to first unread message

Thomas 1234

unread,
Apr 26, 2021, 9:17:33 AM4/26/21
to or-tools-discuss
Hello,

is it possible to access the created routes while solving the VRP somehow?

I would like to create a list of every route generated by the algorithm while solving the problem.

Thank you in advance.



Laurent Perron

unread,
Apr 26, 2021, 9:21:40 AM4/26/21
to or-tools-discuss
There are no column generation techniques in the solver.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/a2d3b69b-ed86-417c-9d4a-debe43fcfde2n%40googlegroups.com.

Thomas 1234

unread,
Apr 26, 2021, 9:53:12 AM4/26/21
to or-tools-discuss
okay thanks.
 but the solver has to generate tours somehow? can I get them?

Laurent Perron

unread,
Apr 26, 2021, 10:01:08 AM4/26/21
to or-tools-discuss
The solver computes a solution, not individual tours. When it finds them, it reports them in a solution.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Vincent Furnon

unread,
Apr 27, 2021, 8:44:40 AM4/27/21
to or-tools...@googlegroups.com
You can get solutions during the search using the RoutingModel::AddAtSolutionCallback(callback) method which sets the solver to call 'callback' each time a new solution is found. In the context of the callback all variables will be set, so you can get individual tours by iterating on each vehicle, getting its start node, then iterating on its route by getting the value of Next variables until you reach the vehicle's end node (a bit like you would to do to display a solution).
Vincent

Thomas 1234

unread,
Apr 27, 2021, 9:13:47 AM4/27/21
to or-tools-discuss
Tank you,
I think that is what I looked for.

th.b...@gmail.com

unread,
May 6, 2021, 6:43:36 AM5/6/21
to or-tools...@googlegroups.com

I tried to write a callback that iterates trough the tours but somehow it cant get the next nodes. I think the problem ist the red marked part.

 

class solution_found(object):

        def __init__(self, model):

            self.model = model

            self.routing = routing

            self.manager = manager

 

        def __call__(self):

            print(self.model.CostVar().Min())

 

            tours = []

            for vehicle_id in range(data['num_vehicles']):

                t = []

                print(vehicle_id)

                index = self.routing.Start(vehicle_id) #get first node

 

                while not self.routing.IsEnd(index): #append node if not end

                    node_index = self.manager.IndexToNode(index)

                    print(node_index)

                    t.append(node_index)

 

                    index = self.routing.NextVar(index) #get next node

                    print(t)

 

            t.append(self.manager.IndexToNode(index)) #append last node

            tours.append(t) #append tour to list of tours

            print(tours)

 

 

    solution_callback = solution_found(routing)

    routing.AddAtSolutionCallback(solution_callback)

--
You received this message because you are subscribed to a topic in the Google Groups "or-tools-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/or-tools-discuss/rLjOMvwGZ_I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/9d5c5245-e908-4ba5-9b31-13915e28fb1dn%40googlegroups.com.

Vincent Furnon

unread,
May 6, 2021, 8:07:43 AM5/6/21
to or-tools...@googlegroups.com
It should be: index = self.routing.NextVar(index).Value() #get next node

Reply all
Reply to author
Forward
0 new messages