Ejemplo n.º 1
0
 def test_exceptions(self):
     self.G.add_edge(Edge(0, 4))
     algorithm = BipartiteGraphBFS(self.G)
     self.assertRaises(ValueError, algorithm.run)
     algorithm = BipartiteGraphDFS(self.G)
     self.assertRaises(ValueError, algorithm.run)
     self.assertRaises(ValueError, BipartiteGraphBFS, Graph(2,
                                                            directed=True))
     self.assertRaises(ValueError, BipartiteGraphDFS, Graph(2,
                                                            directed=True))
Ejemplo n.º 2
0
 def __init__(self, graph):
     """The algorithm initialization.
     
     Parameters
     ----------
     graph : undirected graph
     """
     if graph.is_directed():
         raise ValueError("the graph is directed")
     self.graph = graph
     self.mate = dict((node, None) for node in self.graph.iternodes())
     self.distance = dict()
     self.cardinality = 0
     algorithm = Bipartite(self.graph)
     algorithm.run()
     self.v1 = set()
     self.v2 = set()
     for node in self.graph.iternodes():
         if algorithm.color[node] == 1:
             self.v1.add(node)
         else:
             self.v2.add(node)
     self.Q = Queue()   # for nodes from self.v1
Ejemplo n.º 3
0
 def __init__(self, graph):
     """The algorithm initialization.
     
     Parameters
     ----------
     graph : undirected graph
     """
     if graph.is_directed():
         raise ValueError("the graph is directed")
     self.graph = graph
     self.mate = dict((node, None) for node in self.graph.iternodes())
     self.distance = dict()
     self.cardinality = 0
     algorithm = Bipartite(self.graph)
     algorithm.run()
     self.v1 = set()
     self.v2 = set()
     for node in self.graph.iternodes():
         if algorithm.color[node] == 1:
             self.v1.add(node)
         else:
             self.v2.add(node)
     self.Q = Queue()   # for nodes from self.v1
Ejemplo n.º 4
0
 def test_bipartite_dfs(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BipartiteGraphDFS(self.G)
     algorithm.run(0)
     color_expected = {0: 0, 2: 0, 4: 0, 1: 1, 3: 1, 5: 1}
     self.assertEqual(algorithm.color, color_expected)
Ejemplo n.º 5
0
 def test_bipartite_dfs(self):
     self.assertEqual(self.G.v(), self.N)
     algorithm = BipartiteGraphDFS(self.G)
     algorithm.run(0)
     color_expected = {0: 0, 2: 0, 4: 0, 1: 1, 3: 1, 5: 1}
     self.assertEqual(algorithm.color, color_expected)