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
Example #2
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()
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()
    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

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)
Example #5
0
  # use list/set to remove duplicates
  return reversed(sorted(list(set([clique] + children)), key=len))

output = set()

total_slices = 399
basedir      = sys.argv[2]
my_slice     = int(sys.argv[4])

for vertex in itertools.product(problem_def.keys(), xrange(len(cycles))):
  if index(vertex) % total_slices == my_slice:
    graph = nx.read_gpickle("%s/pruned_graphs/%d-%d.gpickle.bz2"%(basedir, vertex[0], vertex[1]))
    print "processing %s (%d nodes)"%(str(vertex), len(graph))

    for clique in subgraph_cliques(graph, vertex, valid_decoding):
      print " is valid %s"%str(clique)
      consistents = set()
      for subclique in subcombine(clique, vertex):
        # we dont need to process a subclique in case a super-clique has been found to be consistent
        if not any(subclique < c for c in consistents):
          cycle_mapping = map(lambda c: (c[0], cycles[c[1]]), subclique)
          decider = InequalityDecider()
          decider.add_cycle_mapping(problem_def, cycle_mapping)
          if decider.satisfiable():
            print "  is consistent %s"%str(subclique)
            consistents.add(subclique)
            output.add(tuple(sorted(subclique, key=index)))

with open("%s/cliques/%d.pickle"%(basedir, my_slice), "w") as f:
  pickle.dump(list(output), f)