ReadAssignmentFromRoutes problem

486 views
Skip to first unread message

TeLo

unread,
Sep 5, 2017, 10:22:50 AM9/5/17
to or-tools-discuss
hello or tools experts!

I am having some troubles with the method 

ReadAssignmentFromRoutes


the input i am using to this is similar to this: [ [1, [0,4,17,2,45,3,0]], [2, [0,3,11,5,16,23,0]],....] 

which is a vector of vectors in which my first number is my car number and the array next to it is the customers it visits including the depot (0)  but i can't make it work.... which should be the format to use in this method? and how should the output look like ? 

Thanks  a lot in advance. 
Kindest Regards

Vincent Furnon

unread,
Sep 5, 2017, 10:40:47 AM9/5/17
to or-tools...@googlegroups.com
Are you in python ? If so it's a list of lists, where each sub-list is a list of the nodes on the route; no need to specify the vehicle, the index of the list corresponds to the vehicle index (add an empty list if the vehicle is not used). In your case, [ [0,4,17,2,45,3,0], [0,3,11,5,16,23,0],....].
In other languages it's the same. For instance in C++, it's a vector of vectors, where the ith vector contains the nodes of the route of the ith vehicle.

--
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-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

TeLo

unread,
Sep 5, 2017, 10:58:30 AM9/5/17
to or-tools-discuss
I am trying first with a toy example to see if it works... only have 3 customers (being my first customer, the depot) and 2 vehicles.... my demands vector is then [0,1,1] 

my routes_ as a list of lists are: [[], [2, 1]]

running these lines:

assignment2 = routing.ReadAssignmentFromRoutes(routes_,False)
print(assignment2)

I got the following: 

Assignment(Demand0 (0) | Demand1 (1) | Demand2 (0) | Demand3 (0) | Demand4 (0) | Demand5 (2) | Nexts0 (4) | Nexts1 (5) | Nexts2 (1) | Nexts3 (2) | Active0 (1) | Active1 (1) | Active2 (1) | Active3 (1) | Vehicles0 (0) | Vehicles1 (1) | Vehicles2 (1) | Vehicles3 (1) | Vehicles4 (0) | Vehicles5 (1) | (3))

What does the output mean? and why do i have Demand and Vehicles up to 5?

Thanks 
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
Message has been deleted

Paul Trow

unread,
Oct 5, 2017, 4:58:12 PM10/5/17
to or-tools-discuss
The short answer is that you shouldn't be looking at assignment directly . (assignment is a complex structure containing a lot of internal data for the search algorithm).)  If you want to see the routes of the assignment, you can print them as in this example:


Your toy example works - if you add the following line to your program

print("Total distance: ", assignment2.ObjectiveValue())

the program displays 

  Total distance:  3

which is correct, assuming the distance between all locations is 1.

You can then do something like

final_assignment = routing.SolveFromAssignmentWithParameters(initial_assignment, search_parameters)

but in this case, final_assignment will be the same as assignment2, which is already optimal.

makansij

unread,
Jun 12, 2023, 5:15:48 PM6/12/23
to or-tools-discuss
Is there a similar way to get the routes for TSP?  I read this thread, and I have a similar question here: https://groups.google.com/g/or-tools-discuss/c/5VXTnoumQlQ
Reply all
Reply to author
Forward
0 new messages