Exemple #1
0
def cycles_compatible(left, right):
  if left[1] == right[1]:
    # same cycle, different inputs, this cannot be part of a consistent mapping
    return False
  elif len(set(cycles[left[1]]).intersection(set(cycles[right[1]]))) == 0:
    # disjoint cycles are always locally compatible
    return True
  elif left[0] == right[0]:
    # this is an adjoint cycle, it can only be compatible if the intersection of states is empty
    # therefore it is not compatible
    return False
  else:
    # there is some overlap, we need to evaluate pairwise consistency explicitly
    decider = InequalityDecider()
    decider.add_cycle(problem_def, left[0], cycles[left[1]])
    decider.add_cycle(problem_def, right[0], cycles[right[1]])
    return decider.satisfiable()
    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():
            good_states.append(state)