11
11
ortools_version = Version (ortools .__version__ )
12
12
ortools6 = Version ("6.0.0" ) <= ortools_version < Version ("7" )
13
13
ortools7 = Version ("7.0.0" ) <= ortools_version < Version ("8" )
14
- if not ortools6 and not ortools7 :
15
- raise ImportError ("No valid version of ortools installed. Please install ortools 6 or 7." )
14
+ ortools8 = Version ("8.0.0" ) <= ortools_version < Version ("9" )
15
+ ortools9 = Version ("9.0.0" ) <= ortools_version < Version ("10" )
16
+ if not ortools6 and not ortools7 and not ortools8 and not ortools9 :
17
+ raise ImportError ("No valid version of ortools installed. Please install ortools 6 or 7 or 8 or 9." )
16
18
17
19
18
20
class IncompleteSolutionError (Exception ):
@@ -101,12 +103,12 @@ def _seriate(dists: numpy.ndarray, approximation_multiplier=1000, timeout=2.0) -
101
103
102
104
if ortools6 :
103
105
routing = pywrapcp .RoutingModel (size + 1 , 1 , size )
104
- elif ortools7 :
106
+ elif ortools7 or ortools8 or ortools9 :
105
107
manager = pywrapcp .RoutingIndexManager (size + 1 , 1 , size )
106
108
routing = pywrapcp .RoutingModel (manager )
107
109
108
110
def dist_callback (x , y ):
109
- if ortools7 :
111
+ if ortools7 or ortools8 or ortools9 :
110
112
x = manager .IndexToNode (x )
111
113
y = manager .IndexToNode (y )
112
114
if x == size or y == size or x == y :
@@ -125,7 +127,7 @@ def dist_callback(x, y):
125
127
routing .SetArcCostEvaluatorOfAllVehicles (dist_callback )
126
128
search_parameters = pywrapcp .RoutingModel .DefaultSearchParameters ()
127
129
search_parameters .time_limit_ms = int (timeout * 1000 )
128
- elif ortools7 :
130
+ elif ortools7 or ortools8 or ortools9 :
129
131
routing .SetArcCostEvaluatorOfAllVehicles (routing .RegisterTransitCallback (dist_callback ))
130
132
search_parameters = pywrapcp .DefaultRoutingSearchParameters ()
131
133
search_parameters .time_limit .FromMilliseconds (int (timeout * 1000 ))
@@ -142,7 +144,7 @@ def dist_callback(x, y):
142
144
while not routing .IsEnd (index ):
143
145
if ortools6 :
144
146
node = routing .IndexToNode (index )
145
- elif ortools7 :
147
+ elif ortools7 or ortools8 or ortools9 :
146
148
node = manager .IndexToNode (index )
147
149
if node < size :
148
150
route .append (node )
0 commit comments