def test_exceptions(self):
     self.assertRaises(ValueError, CompleteBipartiteGraphEdgeColoring,
                       Graph(5, directed=True))
     gf = GraphFactory(Graph)
     G = gf.make_bipartite(2, 2, False, 1)
     #G.show()
     G.del_edge(Edge(0, 2))  # nie bedzie pelny dwudzielny
     self.assertRaises(ValueError, CompleteBipartiteGraphEdgeColoring, G)
 def test_exceptions(self):
     self.assertRaises(ValueError, BipartiteGraphEdgeColoring,
                       Graph(5, directed=True))
     gf = GraphFactory(Graph)
     G = gf.make_cyclic(4)
     #G.show()
     G.add_edge(Edge(0, 2))  # nie bedzie dwudzielny
     self.assertRaises(ValueError, BipartiteGraphEdgeColoring, G)
示例#3
0
 def test_Kn_even(self):
     N = 10
     self.assertEqual(N % 2, 0)
     gf = GraphFactory(Graph)
     G = gf.make_complete(N)
     algorithm = CompleteGraphEdgeColoring(G)
     algorithm.run()
     for edge in G.iteredges():
         self.assertNotEqual(algorithm.color[edge], None)
     for node in G.iternodes():
         color_set = set()
         for edge in G.iteroutedges(node):
             if edge.source > edge.target:
                 color_set.add(algorithm.color[~edge])
             else:
                 color_set.add(algorithm.color[edge])
         self.assertEqual(len(color_set), G.degree(node))
     #print algorithm.color
     #algorithm.show_colors()
     all_colors = set(algorithm.color[edge] for edge in G.iteredges())
     self.assertEqual(len(all_colors), N - 1)
 def test_cyclic_graph(self):
     N = 8
     assert N % 2 == 0
     gf = GraphFactory(Graph)
     G = gf.make_cyclic(N)
     algorithm = BipartiteGraphEdgeColoring(G)
     algorithm.run()
     for edge in G.iteredges():
         self.assertNotEqual(algorithm.color[edge], None)
     for node in G.iternodes():
         color_set = set()
         for edge in G.iteroutedges(node):
             if edge.source > edge.target:
                 color_set.add(algorithm.color[~edge])
             else:
                 color_set.add(algorithm.color[edge])
         self.assertEqual(len(color_set), G.degree(node))
     #print algorithm.color
     #algorithm.show_colors()
     all_colors = set(algorithm.color[edge] for edge in G.iteredges())
     self.assertEqual(len(all_colors), 2)
 def test_bipartite(self):
     N1 = 10
     N2 = 13
     gf = GraphFactory(Graph)
     G = gf.make_bipartite(N1, N2)
     algorithm = BipartiteGraphEdgeColoring(G)
     algorithm.run()
     for edge in G.iteredges():
         self.assertNotEqual(algorithm.color[edge], None)
     for node in G.iternodes():
         color_set = set()
         for edge in G.iteroutedges(node):
             if edge.source > edge.target:
                 color_set.add(algorithm.color[~edge])
             else:
                 color_set.add(algorithm.color[edge])
         self.assertEqual(len(color_set), G.degree(node))
     #print algorithm.color
     #algorithm.show_colors()
     all_colors = set(algorithm.color[edge] for edge in G.iteredges())
     Delta = max(G.degree(node) for node in G.iternodes())
     self.assertEqual(len(all_colors), Delta)
 def test_Kpq(self):
     N1 = 15
     N2 = 13
     gf = GraphFactory(Graph)
     G = gf.make_bipartite(N1, N2, False, 1)
     self.assertFalse(G.is_directed())
     self.assertEqual(G.v(), N1 + N2)
     self.assertEqual(G.e(), N1 * N2)
     algorithm = BipartiteGraphEdgeColoring(G)
     algorithm.run()
     for edge in G.iteredges():
         self.assertNotEqual(algorithm.color[edge], None)
     for node in G.iternodes():
         color_set = set()
         for edge in G.iteroutedges(node):
             if edge.source > edge.target:
                 color_set.add(algorithm.color[~edge])
             else:
                 color_set.add(algorithm.color[edge])
         self.assertEqual(len(color_set), G.degree(node))
     #print algorithm.color
     #algorithm.show_colors()
     all_colors = set(algorithm.color[edge] for edge in G.iteredges())
     self.assertEqual(len(all_colors), max(N1, N2))
示例#7
0
 def setUp(self):
     self.graph_factory = GraphFactory(Graph)
示例#8
0
#!/usr/bin/python

import timeit
from graphtheory.structures.edges import Edge
from graphtheory.structures.graphs import Graph
from graphtheory.structures.factory import GraphFactory
from graphtheory.forests.treedset import BorieDominatingSet
from graphtheory.forests.treedset import TreeDominatingSet1
from graphtheory.forests.treedset import TreeDominatingSet2

V = 10
E = V - 1  # tree
graph_factory = GraphFactory(Graph)
G = graph_factory.make_tree(V, False)
#G.show()

print "Calculate parameters ..."
print "Nodes:", G.v(), V
print "Edges:", G.e(), E
print "Directed:", G.is_directed()

algorithm = BorieDominatingSet(G)
algorithm.run()
print algorithm.dominating_set
print "borie dset", algorithm.cardinality

algorithm = TreeDominatingSet1(G)
algorithm.run()
print algorithm.dominating_set
print "tree dset1", algorithm.cardinality
示例#9
0
 def setUp(self):
     self.N = 5  # number of nodes
     graph_factory = GraphFactory(Graph)
     self.G = graph_factory.make_complete(self.N, True)
示例#10
0
 def setUp(self):
     self.N = 10           # number of nodes
     self.graph_factory = GraphFactory(Graph)
示例#11
0
#!/usr/bin/python

import unittest
from graphtheory.structures.edges import Edge
from graphtheory.structures.graphs import Graph
from graphtheory.structures.factory import GraphFactory
from graphtheory.seriesparallel.sptools import make_random_spgraph
from graphtheory.seriesparallel.sptools import find_peo_spgraph1
from graphtheory.seriesparallel.sptools import find_peo_spgraph2

print("Testing random sp-graph ...")
G = make_random_spgraph(15)
#G.show()
print("peo1 {}".format(find_peo_spgraph1(G)))
print("peo2 {}".format(find_peo_spgraph2(G)))

print("Testing complete graph ...")
gf = GraphFactory(Graph)
G = gf.make_complete(4)
#G.show()
#print ( "peo1 {}".format(find_peo_spgraph1(G)) )   # ValueError
#print ( "peo2 {}".format(find_peo_spgraph2(G)) )   # ValueError

print("Testing cyclic graph ...")
G = gf.make_cyclic(10)
#G.show()
print("peo1 {}".format(find_peo_spgraph1(G)))
print("peo2 {}".format(find_peo_spgraph2(G)))

# EOF