示例#1
0
 def test_single_vertex(self) :
     G=nx.DiGraph()
     G.add_node('x')
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     self.assertSetEqual(set(peb.variables()),set(['x']))
     self.assertSetSetEqual(peb,[[(True,'x')],[(False,'x')]])
示例#2
0
 def test_single_vertex(self):
     G = nx.DiGraph()
     G.add_node('x')
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     self.assertSetEqual(set(peb.variables()), set(['x']))
     self.assertSetSetEqual(peb, [[(True, 'x')], [(False, 'x')]])
示例#3
0
 def test_path(self) :
     G=nx.path_graph(10,nx.DiGraph())
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     clauses = \
         [[(True,0)]] + \
         [[(False,i-1),(True,i)] for i in xrange(1,10)] + \
         [[(False,9)]]
     self.assertListEqual(list(peb.variables()),range(10))
     self.assertSetSetEqual(peb,clauses)
示例#4
0
 def test_path(self):
     G = nx.path_graph(10, nx.DiGraph())
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     clauses = \
         [[(True,0)]] + \
         [[(False,i-1),(True,i)] for i in range(1,10)] + \
         [[(False,9)]]
     self.assertListEqual(list(peb.variables()), list(range(10)))
     self.assertSetSetEqual(peb.clauses(), clauses)
示例#5
0
 def test_pyramid(self) :
     G=nx.DiGraph()
     G.add_node(10)
     for i in xrange(0,10) :
         G.add_node(i)
         G.add_edge(i,10)
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     clauses = \
         [[(True,i)] for i in xrange(10)] + \
         [[(False,i) for i in xrange(10)] + [(True,10)]] + \
         [[(False,10)]]
     self.assertListEqual(list(peb.variables()),range(11))
     self.assertSetSetEqual(list(peb),clauses)
示例#6
0
 def test_pyramid(self):
     G = nx.DiGraph()
     G.add_node(10)
     for i in range(0, 10):
         G.add_node(i)
         G.add_edge(i, 10)
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     clauses = \
         [[(True,i)] for i in range(10)] + \
         [[(False,i) for i in range(10)] + [(True,10)]] + \
         [[(False,10)]]
     self.assertListEqual(list(peb.variables()), list(range(11)))
     self.assertSetSetEqual(peb.clauses(), clauses)
示例#7
0
 def test_pyramid(self):
     G = nx.DiGraph()
     G.add_edges_from([(1, 4), (2, 4), (2, 5), (3, 5), (4, 6), (5, 6)])
     G.name = 'Pyramid of height 2'
     F = PebblingFormula(G)
     self.checkFormula(sys.stdin, F,
                       ["cnfgen", "-q", "peb", "--pyramid", 2])
示例#8
0
 def test_tree(self):
     for sz in range(1, 5):
         G = nx.balanced_tree(2, sz, nx.DiGraph()).reverse()
         G = nx.relabel_nodes(
             G, dict(list(zip(G.nodes(), reversed(G.nodes())))), True)
         G.name = 'Complete binary tree of height {}'.format(sz)
         F = PebblingFormula(G)
         self.checkFormula(sys.stdin, F,
                           ["cnfgen", "-q", "peb", "--tree", sz])
示例#9
0
 def test_null_graph(self) :
     G=nx.DiGraph()
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     self.assertCnfEqual(peb,CNF())
示例#10
0
 def test_null_graph(self):
     G = nx.DiGraph()
     peb = PebblingFormula(G)
     self.assertTrue(peb._check_coherence())
     self.assertCnfEqual(peb, CNF())
示例#11
0
 def test_cycle(self):
     G = nx.cycle_graph(10, nx.DiGraph())
     with self.assertRaises(ValueError):
         PebblingFormula(G)