diff --git a/examples/python/blending.py b/examples/python/blending.py index 4abebb651e..0271fea634 100644 --- a/examples/python/blending.py +++ b/examples/python/blending.py @@ -138,7 +138,7 @@ def main(sol='GLPK'): if __name__ == '__main__': - sol = 'GLPK' + sol = 'CBC' if len(sys.argv) > 1: sol = sys.argv[1] diff --git a/examples/python/einav_puzzle2.py b/examples/python/einav_puzzle2.py index bebecb6e59..a15158f17c 100644 --- a/examples/python/einav_puzzle2.py +++ b/examples/python/einav_puzzle2.py @@ -175,7 +175,7 @@ def main(): num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print "Sum =", objective.best() + print "Sum =", objective.Best() print "row_sums:", [row_sums[i].Value() for i in range(rows)] print "col_sums:", [col_sums[j].Value() for j in range(cols)] for i in range(rows): diff --git a/examples/python/nonogram_default_search.py b/examples/python/nonogram_default_search.py index 46b8016d16..d0e23acb80 100644 --- a/examples/python/nonogram_default_search.py +++ b/examples/python/nonogram_default_search.py @@ -54,12 +54,12 @@ def make_transition_tuples(pattern): p_len = len(pattern) num_states = p_len + sum(pattern) - tuples = pywrapcp.IntTupleSet(3) + tuples = [] # this is for handling 0-clues. It generates # just the minimal state if num_states == 0: - tuples.Insert3(1, 0, 1) + tuples.append((1, 0, 1)) return (tuples, 1) # convert pattern to a 0/1 pattern for easy handling of @@ -73,15 +73,15 @@ def make_transition_tuples(pattern): for i in range(num_states): state = i + 1 if tmp[i] == 0: - tuples.Insert3(state, 0, state) - tuples.Insert3(state, 1, state + 1) + tuples.append((state, 0, state)) + tuples.append((state, 1, state + 1)) else: if i < num_states - 1: if tmp[i + 1] == 1: - tuples.Insert3(state, 1, state + 1) + tuples.append((state, 1, state + 1)) else: - tuples.Insert3(state, 0, state + 1) - tuples.Insert3(num_states, 0, num_states) + tuples.append((state, 0, state + 1)) + tuples.append((num_states, 0, num_states)) return (tuples, num_states) diff --git a/examples/python/nonogram_table.py b/examples/python/nonogram_table.py index 946023c0ba..494755f3ca 100644 --- a/examples/python/nonogram_table.py +++ b/examples/python/nonogram_table.py @@ -104,13 +104,13 @@ def regular(x, Q, S, d, q0, F): # to state zero. This allows us to continue even if we hit a # non-accepted input. - d2 = pywrapcp.IntTupleSet(3) + d2 = [] for i in range(Q + 1): for j in range(S): if i == 0: - d2.Insert3(0, j, 0) + d2.append((0, j, 0)) else: - d2.Insert3(i, j, d[i - 1][j]) + d2.append((i, j, d[i - 1][j])) # If x has index set m..n, then a[m-1] holds the initial state # (q0), and a[i+1] holds the state we're in after processing diff --git a/examples/python/nonogram_table2.py b/examples/python/nonogram_table2.py index 78eb641efa..7d0fb741ca 100644 --- a/examples/python/nonogram_table2.py +++ b/examples/python/nonogram_table2.py @@ -80,12 +80,12 @@ def make_transition_tuples(pattern): p_len = len(pattern) num_states = p_len + sum(pattern) - tuples = pywrapcp.IntTupleSet(3) + tuples = [] # this is for handling 0-clues. It generates # just the minimal state if num_states == 0: - tuples.Insert3(1, 0, 1) + tuples.append((1, 0, 1)) return (tuples, 1) # convert pattern to a 0/1 pattern for easy handling of @@ -99,15 +99,15 @@ def make_transition_tuples(pattern): for i in range(num_states): state = i + 1 if tmp[i] == 0: - tuples.Insert3(state, 0, state) - tuples.Insert3(state, 1, state + 1) + tuples.append((state, 0, state)) + tuples.append((state, 1, state + 1)) else: if i < num_states - 1: if tmp[i + 1] == 1: - tuples.Insert3(state, 1, state + 1) + tuples.append((state, 1, state + 1)) else: - tuples.Insert3(state, 0, state + 1) - tuples.Insert3(num_states, 0, num_states) + tuples.append((state, 0, state + 1)) + tuples.append((num_states, 0, num_states)) return (tuples, num_states) diff --git a/examples/python/regular_table.py b/examples/python/regular_table.py index e798316809..3c6313eeff 100644 --- a/examples/python/regular_table.py +++ b/examples/python/regular_table.py @@ -74,13 +74,13 @@ def regular(x, Q, S, d, q0, F): # to state zero. This allows us to continue even if we hit a # non-accepted input. - d2 = pywrapcp.IntTupleSet(3) + d2 = [] for i in range(Q + 1): for j in range(S): if i == 0: - d2.Insert3(0, j, 0) + d2.append((0, j, 0)) else: - d2.Insert3(i, j, d[i - 1][j]) + d2.append((i, j, d[i - 1][j])) # If x hasindex set m..n, then a[m-1] holds the initial state # (q0), and a[i+1] holds the state we're in after processing diff --git a/examples/python/regular_table2.py b/examples/python/regular_table2.py index 351f9f36cd..25670bcad3 100644 --- a/examples/python/regular_table2.py +++ b/examples/python/regular_table2.py @@ -74,13 +74,13 @@ def regular(x, Q, S, d, q0, F): # to state zero. This allows us to continue even if we hit a # non-accepted input. - d2 = pywrapcp.IntTupleSet(3) + d2 = [] for i in range(Q + 1): for j in range(1, S + 1): if i == 0: - d2.Insert3(0, j, 0) + d2.append((0, j, 0)) else: - d2.Insert3(i, j, d[i - 1][j - 1]) + d2.append((i, j, d[i - 1][j - 1])) solver.Add(solver.TransitionConstraint(x, d2, q0, F)) diff --git a/examples/python/steel_lns.py b/examples/python/steel_lns.py index ba6805dda4..4940bab014 100644 --- a/examples/python/steel_lns.py +++ b/examples/python/steel_lns.py @@ -211,7 +211,7 @@ def main(unused_argv): solver.ASSIGN_MIN_VALUE) # The most important aspect is to limit the time exploring each fragment. inner_limit = solver.FailuresLimit(FLAGS.lns_fail_limit) - continuation_db = solver.SolveOnce(inner_db, inner_limit) + continuation_db = solver.SolveOnce(inner_db, [inner_limit]) # Now, we create the LNS objects. rand = random.Random() diff --git a/examples/python/traffic_lights.py b/examples/python/traffic_lights.py index 38a2bff057..7233cbcb3d 100644 --- a/examples/python/traffic_lights.py +++ b/examples/python/traffic_lights.py @@ -90,11 +90,11 @@ def main(base=10, start=1, len1=1, len2=4): lights = ["r", "ry", "g", "y"] # The allowed combinations - allowed = pywrapcp.IntTupleSet(4) - allowed.InsertAll([(r, r, g, g), - (ry, r, y, r), - (g, g, r, r), - (y, r, ry, r)]) + allowed = [] + allowed.extend([(r, r, g, g), + (ry, r, y, r), + (g, g, r, r), + (y, r, ry, r)]) # # declare variables diff --git a/src/constraint_solver/python/constraint_solver.swig b/src/constraint_solver/python/constraint_solver.swig index cd83efe209..72ca855671 100644 --- a/src/constraint_solver/python/constraint_solver.swig +++ b/src/constraint_solver/python/constraint_solver.swig @@ -975,6 +975,8 @@ namespace operations_research { %unignore Solver::SearchLimitProto; // search_limit.proto %rename (Limit) Solver::MakeLimit; %rename (TimeLimit) Solver::MakeTimeLimit; +%rename (BranchesLimit) Solver::MakeBranchesLimit; +%rename (FailuresLimit) Solver::MakeFailuresLimit; %rename (SolutionsLimit) Solver::MakeSolutionsLimit; %rename (CustomLimit) Solver::MakeCustomLimit; @@ -1144,8 +1146,6 @@ namespace operations_research { // // - MakeEquality() // On IntervalVar. // -// - MakeBranchesLimit() -// - MakeFailuresLimit() // - UpdateLimits() // - GetTime() // diff --git a/src/linear_solver/python/linear_solver.swig b/src/linear_solver/python/linear_solver.swig index 115f18e028..d085d1f17a 100644 --- a/src/linear_solver/python/linear_solver.swig +++ b/src/linear_solver/python/linear_solver.swig @@ -214,7 +214,10 @@ from ortools.linear_solver.linear_solver_natural_api import LinearConstraint self.set_time_limit(x) def WallTime(self): - return self->wall_time() + return self.wall_time() + + def Iterations(self): + return self.iterations() } // %pythoncode }