Empty routes in RoutesToAssignment

54 views
Skip to first unread message

Denzel

unread,
Sep 9, 2025, 10:46:26 AMSep 9
to or-tools-discuss
Hi there,

I'm tackling a VRPTW problem and use the Python library (v9.14) of OR tools to optimize already existing routes. Since the search space is quite big (many vehicles with many nodes per vehicle), I'm using a warm start for the solvers with RoutesToAssignment, where I feed the current route.

A small code example:
routeIndices = []
for r in routeNodes:
routeIndices.append([self.manager.NodeToIndex(n) for n in r])

self.routing.CloseModel()
initialAssignment = self.routing.solver().Assignment()
success = self.routing.RoutesToAssignment(routeIndices, True, True, initialAssignment)
self.logger.debug(f"Warm starting of route {'successful' if success else 'failed'}")

return self.routing.SolveFromAssignmentWithParameters(
initialAssignment, searchParameters
)

Here, routeNodes is a list of node i's per vehicle, e.g. [ [4, 6, 5], [9, 8, 7, 10] ] for a case with 2 vehicles, where [0,1] are the start/end node of vehicle 1 and [2,3] are the start/end node of vehicle 2. 

This does work as expected, however it does not allow me to append vehicles that do not yet have any nodes (except for a start- and endnode to depot). I have already tried to add an empty list [], but they seem to be ignored, and I'm unable to find proper documentation on this. Does anyone know how I can implement this?

Thank you for your time.

Kind regards,
Bart

blind.line

unread,
Sep 9, 2025, 1:57:44 PMSep 9
to or-tools...@googlegroups.com
Hi,

I add empty lists— [] —for as-yet empty routes and I have no problems. 

Perhaps try again with a very simple problem, like one of the toy examples? 

James

On Sep 9, 2025, at 09:46, Denzel <denzel...@gmail.com> wrote:

Hi there,
--
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 visit https://groups.google.com/d/msgid/or-tools-discuss/7948138b-ec15-4324-9058-264694879a48n%40googlegroups.com.
Message has been deleted

Denzel

unread,
Sep 10, 2025, 9:56:06 AMSep 10
to or-tools-discuss
Hi James,
Thanks for your reply! I followed your suggestion and created a toy example from the documentation (though in Python I couldn't find an out of the box example with RoutesToAssignment - but anyways I just added it to a basic VRPTW problem) and I was able to debug my issue. It was helpful to know I was on the right track with the empty lists.
Have a good day!
Op dinsdag 9 september 2025 om 19:57:44 UTC+2 schreef blind.lin...@gmail.com:
Reply all
Reply to author
Forward
0 new messages