Beispiel #1
0
 def test_local_graph(self):
     n = 1
     f = boolean_map(n)
     formula = local_edges(f, {(0,): [(1,1,1)]})
     sols = solve(formula, n)
     self.assertEqual(len(list(sols)), 1)
     n = 2
     f = boolean_map(n)
     formula = local_edges(f, {(0,0): [(1,2,1), (2,1,-1)]})
     sols = solve(formula, n, max_models=10)
     for sol in sols:
         lig = local_int_graph(sol)
         self.assertTrue((1,2,1) in lig[(0,0)])
         self.assertTrue((2,1,-1) in lig[(0,0)])
         self.assertFalse((1,2,-1) in lig[(0,0)])
         self.assertFalse((2,1,+1) in lig[(0,0)])
     f = boolean_map(n)
     formula = local_edges(f, {(0,0): [(1,2,1), (2,1,-1)], (0,1): [(2,1,1)]}, only=False)
     sols = solve(formula, n, max_models=10)
     with self.assertRaises(StopIteration):
         next(sols)
     formula = local_edges(f, {(0,0): [(1,2,1), (2,1,-1)], (1,1): [(2,1,1)]}, only=False)
     sols = solve(formula, n, max_models=10)
     for sol in sols:
         lig = local_int_graph(sol)
         self.assertTrue((1,2,1) in lig[(0,0)])
         self.assertTrue((2,1,-1) in lig[(0,0)])
Beispiel #2
0
 def test_stepwise_rg(self):
     ms = [3, 2]
     f = random_map(ms)
     uf = to_stepwise(f)
     lig, ligu = local_int_graph(f), local_int_graph(uf)
     self.assertTrue(
         all(e in lig[x] for x in f for e in ligu[x] if e[0] != e[1]))
     f = {x: (1, 2) for x in discrete_states(ms)}
     f[(0, 1)], f[(0, 2)] = (2, 2), (2, 2)
     uf = to_stepwise(f)
     lig, ligu = local_int_graph(f), local_int_graph(uf)
     self.assertFalse(
         all(e in lig[x] for x in f for e in ligu[x] if e[0] == e[1]))
     self.assertFalse(
         all(e in ligu[x] for x in f for e in lig[x] if e[0] == e[1]))
Beispiel #3
0
 def test_global_graph(self):
     n = 3
     f = boolean_map(n)
     formula = global_edges(f, [(1,2,1), (2,3,1), (3,1,-1)])
     sols = solve(formula, n)
     k = 0
     for sol in sols:
         k = k + 1
         lig = local_int_graph(sol)
         for x in f:
             self.assertEqual(lig[x], [(1,2,1), (2,3,1), (3,1,-1)])
         self.assertEqual(global_int_graph(sol), [(1,2,1), (2,3,1), (3,1,-1)])
     self.assertEqual(k, 1)
     formula = global_edges(f, [(1,2,1), (2,3,1)], all_states=False)
     sols = solve(formula, n, max_models=3)
     for sol in sols:
         grg = global_int_graph(sol)
         self.assertTrue((1,2,1) in grg)
         self.assertTrue((2,3,1) in grg)
         self.assertFalse((3,1,-1) in grg)
         self.assertFalse((3,1,1) in grg)
         self.assertFalse((3,2,-1) in grg)
         self.assertFalse((3,2,1) in grg)
     formula = global_edges(f, [(1,2,1), (2,3,1), (3,1,-1)], only=False, all_states=False)
     sols = solve(formula, n, max_models=3)
     for sol in sols:
         grg = global_int_graph(sol)
         self.assertTrue((1,2,1) in grg)
         self.assertTrue((2,3,1) in grg)
         self.assertTrue((3,1,-1) in grg)
Beispiel #4
0
 def test_ig_attr(self):
     ms = [3, 2]
     f = to_stepwise(random_map(ms))
     lig = local_int_graph(f)
     lig1 = local_int_graph(f, graph=local_int_graph_attr_state)
     self.assertTrue(all(e in lig[x] for x in f for e in lig1[x]))
     f = {
         (0, 0): (1, 2),
         (0, 1): (1, 1),
         (0, 2): (1, 0),
         (1, 0): (1, 2),
         (1, 1): (0, 2),
         (1, 2): (1, 1)
     }
     lig = local_int_graph(f)
     lig1 = local_int_graph(f, graph=local_int_graph_attr_state)
     self.assertFalse(all(e in lig[x] for x in f for e in lig1[x]))
Beispiel #5
0
 def test_int_graph(self):
     f1 = read_truth_table(["00 01", "01 00", "11 01", "10 00"])
     f2 = read_truth_table(["00 11", "01 10", "11 11", "10 10"])
     lig1 = local_int_graph(f1)
     lig2 = local_int_graph(f2)
     lg = {
         (0, 0): [(1, 2, -1), (2, 2, -1)],
         (0, 1): [(1, 2, 1), (2, 2, -1)],
         (1, 0): [(1, 2, -1), (2, 2, +1)],
         (1, 1): [(1, 2, 1), (2, 2, +1)]
     }
     self.assertEqual(lig1, lig2)
     self.assertEqual(lig1, lg)
     grg1 = global_int_graph(f1)
     grg2 = global_int_graph(f2)
     gg = [(1, 2, -1), (1, 2, 1), (2, 2, -1), (2, 2, 1)]
     self.assertEqual(grg1, grg2)
     self.assertEqual(grg1, gg)
Beispiel #6
0
 def test_mirror_circuits(self):
     ms = [2, 3, 2]
     for f in [random_map(ms) for i in range(5)]:
         mirror_pairs = [
             p for p in combinations(discrete_states(ms), 2)
             if is_mirror_pair(f, p[0], p[1])
         ]
         if len(mirror_pairs) > 0:
             lig = local_int_graph(f)
             self.assertTrue(
                 any(
                     len(lig[p[0]]) > 0 and len(lig[p[1]]) > 0
                     for p in mirror_pairs))
Beispiel #7
0
f = boolean_map(n)
edges = [(1, 2, 1), (2, 3, -1), (3, 4, 1), (4, 1, -1)]
print("Imposing global interaction graph: {}".format(edges))
sols = solve(global_edges(f, edges), n)
for g in sols:
    print("Interaction graph: {}".format(global_int_graph(g)))
    print("Attractors: {}".format(list(attractors(g))))

edges = [(1, 3, 1), (3, 2, 1), (3, 4, 1), (4, 1, -1)]
print("Imposing global interaction graph: {}".format(edges))
sols = solve(global_edges(f, edges), n)
for g in sols:
    print("Interaction graph: {}".format(global_int_graph(g)))
    print("Attractors: {}".format(list(attractors(g))))

# find Boolean networks with given local graphs and orbit
edges = {(0, 0, 0, 1): [], (1, ) * n: [(1, 1, -1)]}
print("Imposing local interaction graph: {}".format(edges))
path = [(0, ) * n, (0, 1, 0, 0), (1, 1, 0, 0), (1, 0, 0, 0)]
print("Imposing orbit in asynchronous dynamics: {}".format(path))
formula = And(local_edges(f, edges), orbit(f, path))
sol = solve(formula, n, max_models=1)
try:
    sol = next(sol)
    print("Example:")
    pprint(sol)
    print("Local interaction graph:")
    pprint(local_int_graph(sol))
except StopIteration:
    print("No solutions.")