forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue4.py
executable file
·42 lines (32 loc) · 1.03 KB
/
issue4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
from ortools.constraint_solver import pywrapcp
def main():
solver = pywrapcp.Solver("time limit test")
n = 10
x = [solver.IntVar(1, n, "x[%i]" % i) for i in range(n)]
solver.Add(solver.AllDifferent(x, True))
solution = solver.Assignment()
solution.Add(x)
db = solver.Phase(x,
solver.CHOOSE_FIRST_UNBOUND,
solver.ASSIGN_MIN_VALUE)
time_limit = 2000
branch_limit = 100000000
failures_limit = 100000000
solutions_limit = 10000000
limits = (
solver.Limit(
time_limit, branch_limit, failures_limit, solutions_limit, True))
search_log = solver.SearchLog(1000)
solver.NewSearch(db, [limits, search_log])
num_solutions = 0
while solver.NextSolution():
print("x:", [x[i].Value() for i in range(n)])
num_solutions += 1
solver.EndSearch()
print("num_solutions:", num_solutions)
print("failures:", solver.Failures())
print("branches:", solver.Branches())
print("wall_time:", solver.WallTime())
if __name__ == "__main__":
main()