Added IntTupleSet for Transition

This commit is contained in:
hakank
2012-03-15 18:29:15 +00:00
parent 95db2534b6
commit 46882755af
3 changed files with 21 additions and 19 deletions

View File

@@ -54,12 +54,13 @@ def make_transition_tuples(pattern):
p_len = len(pattern)
num_states = p_len + sum(pattern)
tuples = pywrapcp.IntTupleSet(3)
# this is for handling 0-clues. It generates
# just the minimal state
if num_states == 0:
return [(1, 0, 1)], 1
tuples = []
tuples.Insert3(1, 0, 1)
return (tuples, 1)
# convert pattern to a 0/1 pattern for easy handling of
# the states
@@ -72,15 +73,15 @@ def make_transition_tuples(pattern):
for i in range(num_states):
state = i + 1
if tmp[i] == 0:
tuples.append((state, 0, state))
tuples.append((state, 1, state + 1))
tuples.Insert3(state, 0, state)
tuples.Insert3(state, 1, state + 1)
else:
if i < num_states - 1:
if tmp[i + 1] == 1:
tuples.append((state, 1, state + 1))
tuples.Insert3(state, 1, state + 1)
else:
tuples.append((state, 0, state + 1))
tuples.append((num_states, 0, num_states))
tuples.Insert3(state, 0, state + 1)
tuples.Insert3(num_states, 0, num_states)
return (tuples, num_states)

View File

@@ -78,12 +78,13 @@ def make_transition_tuples(pattern):
p_len = len(pattern)
num_states = p_len + sum(pattern)
tuples = pywrapcp.IntTupleSet(3)
# this is for handling 0-clues. It generates
# just the minimal state
if num_states == 0:
return [(1, 0, 1)], 1
tuples = []
tuples.Insert3(1, 0, 1);
return (tuples, 1)
# convert pattern to a 0/1 pattern for easy handling of
# the states
@@ -96,15 +97,15 @@ def make_transition_tuples(pattern):
for i in range(num_states):
state = i + 1
if tmp[i] == 0:
tuples.append((state, 0, state))
tuples.append((state, 1, state + 1))
tuples.Insert3(state, 0, state)
tuples.Insert3(state, 1, state + 1)
else:
if i < num_states - 1:
if tmp[i + 1] == 1:
tuples.append((state, 1, state + 1))
tuples.Insert3(state, 1, state + 1)
else:
tuples.append((state, 0, state + 1))
tuples.append((num_states, 0, num_states))
tuples.Insert3(state, 0, state + 1)
tuples.Insert3(num_states, 0, num_states)
return (tuples, num_states)

View File

@@ -73,13 +73,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 = []
d2 = pywrapcp.IntTupleSet(3);
for i in range(Q + 1):
for j in range(1, S + 1):
if i == 0:
d2.append((0, j, 0))
d2.Insert3(0, j, 0)
else:
d2.append((i, j, d[i - 1][j - 1]))
d2.Insert3(i, j, d[i - 1][j - 1])
solver.Add(solver.TransitionConstraint(x, d2, q0, F))