Closed Akavall closed 5 years ago
You should change the First Solution Strategy according to the code
https://github.com/google/or-tools/blob/f3fd201e68cf75b7720ff5c3cadc599a1d02b54b/ortools/constraint_solver/routing.cc#L4650-L4660
So, try to use
routing_enums_pb2.FirstSolutionStrategy.PARALLEL_CHEAPEST_INSERTION
instead
using it:
%time ./test.py
times shape: (17, 17)
time_matrix:
[[ 0 8 7 4 5 6 7 6 7 6 7 9 9 7 8 7 10]
[ 8 0 8 5 5 7 2 7 2 7 5 2 1 4 9 1 2]
[ 7 8 0 4 3 1 6 1 6 1 3 8 9 4 1 7 10]
[ 4 5 4 0 1 3 4 3 4 3 3 6 6 3 5 4 7]
[ 5 5 3 1 0 2 3 2 3 2 2 5 5 2 5 3 7]
[ 6 7 1 3 2 0 5 0 5 0 3 7 8 4 2 6 10]
[ 7 2 6 4 3 5 0 5 0 5 3 2 2 2 7 1 4]
[ 6 7 1 3 2 0 5 0 5 0 3 7 8 4 2 6 10]
[ 7 2 6 4 3 5 0 5 0 5 3 2 2 2 7 1 4]
[ 6 7 1 3 2 0 5 0 5 0 3 7 8 4 2 6 10]
[ 7 5 3 3 2 3 3 3 3 3 0 5 6 1 4 4 7]
[ 9 2 8 6 5 7 2 7 2 7 5 0 2 3 9 2 3]
[ 9 1 9 6 5 8 2 8 2 8 6 2 0 5 10 2 1]
[ 7 4 4 3 2 4 2 4 2 4 1 3 5 0 5 3 6]
[ 8 9 1 5 5 2 7 2 7 2 4 9 10 5 0 8 12]
[ 7 1 7 4 3 6 1 6 1 6 4 2 2 3 8 0 3]
[10 2 10 7 7 10 4 10 4 10 7 3 1 6 12 3 0]]
Route for vehicle 0:
0 Time(0,0) -> 15 Time(7,10) -> 1 Time(8,11) -> 5 Time(15,18) -> 9 Time(15,18) -> 2 Time(16,19) -> 10 Time(19,22) -> 6 Time(25,25) -> 11 Time(27,27) -> 16 Time(30,30) -> 12 Time(31,31) -> 0 Time(40,40)
Time of the route: 40min
Route for vehicle 1:
0 Time(0,0) -> 3 Time(15,18) -> 4 Time(16,19) -> 13 Time(18,23) -> 14 Time(25,28) -> 7 Time(30,30) -> 8 Time(35,35) -> 0 Time(42,42)
Time of the route: 42min
Total time of all routes: 82min
./test.py 0.45s user 0.70s system 332% cpu 0.347 total
note:
python3 -m pip show ortools scipy
Name: ortools
Version: 7.1.6720
...
---
Name: scipy
Version: 1.2.1
Thank You @Mizux, it is much faster indeed.
Is there a guide that explains in what situation to use what First Solution Strategy?
I know that there is: https://developers.google.com/optimization/routing/routing_options, but the descriptions here are on the high level side.
I've a question regarding this subject. I would like to use distance and time as variables to generate routes, is this possible?
I am running a script with 8 pickup/deliveries and 17 nodes, and it takes over 1 minute on my machine. This seems very slow. Am I missing anything?
Here is the code that I am using: