Skip to content

Commit 81fd18f

Browse files
committed
fix: compatible with ortools 8 and ortools 9.
Signed-off-by: Zou Guangxian <[email protected]>
1 parent 0af55a2 commit 81fd18f

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy==1.15.1
2-
scipy==1.0.1
3-
ortools==6.9.5824
4-
packaging==16.8
1+
numpy>=1.15.1
2+
scipy>=1.0.1
3+
ortools>=6.9.5824
4+
packaging>=16.8

seriate.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
ortools_version = Version(ortools.__version__)
1212
ortools6 = Version("6.0.0") <= ortools_version < Version("7")
1313
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.")
1618

1719

1820
class IncompleteSolutionError(Exception):
@@ -101,12 +103,12 @@ def _seriate(dists: numpy.ndarray, approximation_multiplier=1000, timeout=2.0) -
101103

102104
if ortools6:
103105
routing = pywrapcp.RoutingModel(size + 1, 1, size)
104-
elif ortools7:
106+
elif ortools7 or ortools8 or ortools9:
105107
manager = pywrapcp.RoutingIndexManager(size + 1, 1, size)
106108
routing = pywrapcp.RoutingModel(manager)
107109

108110
def dist_callback(x, y):
109-
if ortools7:
111+
if ortools7 or ortools8 or ortools9:
110112
x = manager.IndexToNode(x)
111113
y = manager.IndexToNode(y)
112114
if x == size or y == size or x == y:
@@ -125,7 +127,7 @@ def dist_callback(x, y):
125127
routing.SetArcCostEvaluatorOfAllVehicles(dist_callback)
126128
search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
127129
search_parameters.time_limit_ms = int(timeout * 1000)
128-
elif ortools7:
130+
elif ortools7 or ortools8 or ortools9:
129131
routing.SetArcCostEvaluatorOfAllVehicles(routing.RegisterTransitCallback(dist_callback))
130132
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
131133
search_parameters.time_limit.FromMilliseconds(int(timeout * 1000))
@@ -142,7 +144,7 @@ def dist_callback(x, y):
142144
while not routing.IsEnd(index):
143145
if ortools6:
144146
node = routing.IndexToNode(index)
145-
elif ortools7:
147+
elif ortools7 or ortools8 or ortools9:
146148
node = manager.IndexToNode(index)
147149
if node < size:
148150
route.append(node)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
download_url="https://github.com/src-d/seriate",
2121
py_modules=["seriate"],
2222
keywords=["seriation"],
23-
install_requires=["numpy>=1.0", "ortools>=6.7.4973,<8", "packaging>=16.0"],
23+
install_requires=["numpy>=1.0", "ortools>=6.7.4973,<=9", "packaging>=16.0"],
2424
tests_require=["scipy>=1.0"],
2525
package_data={"": ["LICENSE.md", "README.md", "requirements.txt"]},
2626
classifiers=[
@@ -31,5 +31,6 @@
3131
"Programming Language :: Python :: 3.6",
3232
"Programming Language :: Python :: 3.7",
3333
"Programming Language :: Python :: 3.8",
34+
"Programming Language :: Python :: 3.9",
3435
],
3536
)

0 commit comments

Comments
 (0)