def build_potential_graphs(cycle_mapping):
  graphs = {}
  base_decider = InequalityDecider()
  base_decider.add_cycle_mapping(problem_def, cycle_mapping)
  decider = base_decider.freeze()
  for result, inputs in problem_def.iteritems():
    my_cycles    = tuple(map(operator.itemgetter(1), filter(lambda a: a[0]==result, cycle_mapping)))
    other_cycles = map(operator.itemgetter(1), filter(lambda a: a[0]!=result, cycle_mapping))

    all_states   = set(map(lambda s: string.join(s, ""), itertools.permutations(["a","a","b","b","c"])))
    other_states = all_states-set(itertools.chain(*my_cycles))
    for input in inputs:
      graphs[input] = (decider.build_transition_graph(my_cycles, other_states, input), my_cycles[0][0])
  return graphs
    all_states   = set(map(lambda s: string.join(s, ""), itertools.permutations(["a","a","b","b","c"])))
    other_states = all_states-set(itertools.chain(*my_cycles))
    for input in inputs:
      graphs[input] = (decider.build_transition_graph(my_cycles, other_states, input), my_cycles[0][0])
  return graphs

result = list()

for i in xrange(len(cliques)):
  if i % total_slices == my_slice:
    clique        = cliques[i]
    print "starting %d %s"%(i, str(clique))
    cycle_mapping = map(lambda c: (c[0], tuple(cycles[c[1]])), clique)
    decider = InequalityDecider()
    decider.add_cycle_mapping(problem_def, cycle_mapping)
    if decider.satisfiable():
      print " satisfiable"
      graphs      = build_potential_graphs(cycle_mapping)

      good_states = list()
      for state in set(map(lambda s: string.join(s, ""), itertools.permutations(["a","a","b","b","c"]))):
        try:
          decider = InequalityDecider()
          decider.add_cycle_mapping(problem_def, cycle_mapping)
          for input, graph_plus in graphs.iteritems():
            path = nx.shortest_path(graph_plus[0], state, graph_plus[1])
            for f, t in zip(path[:-1], path[1:]):
              decider.add_transition(f, t, input)

          if decider.satisfiable():
def build_decider(prefix):
  basedecider = InequalityDecider()
  basedecider.add_cycle_mapping(problem_def, cycle_mapping)
  for transition in prefix:
    basedecider.add_transition(*transition)
  return basedecider.freeze()