fix compaptibility layer in swig/python

This commit is contained in:
lperron@google.com
2014-07-22 19:28:00 +00:00
parent a57ba55235
commit 729ed77ecd
11 changed files with 37 additions and 34 deletions

View File

@@ -138,7 +138,7 @@ def main(sol='GLPK'):
if __name__ == '__main__':
sol = 'GLPK'
sol = 'CBC'
if len(sys.argv) > 1:
sol = sys.argv[1]

View File

@@ -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):

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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))

View File

@@ -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()

View File

@@ -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