def generate_test_instance1(): g = Graph(type=DIRECTED_GRAPH, display='pygame') g.add_edge(0, 1) g.add_edge(1, 2) g.add_edge(2, 0) g.add_edge(2, 3) g.add_edge(3, 4) g.add_edge(5, 6) g.add_edge(6, 7) g.add_edge(7, 8) g.add_edge(8, 6) g.add_edge(6, 9) g.add_edge(10, 11) return g
''' This script implements the graphviz example at location http://www.graphviz.org/Gallery/directed/cluster.html in our graph class. Main purpose of the Graph class is not to be python interface to graphviz. Main purpose is to implement a graph class using the methods in the literature and measuring running time performances. Hence it is teaching/research oriented. This script demonstrates the Graph class's capability as a graphviz interface. ''' from gimpy import Graph, DIRECTED_GRAPH if __name__=='__main__': c = Graph(type=DIRECTED_GRAPH, layout = 'dot') # add edges c.add_edge('start', 'a0') c.add_edge('a0', 'a1') c.add_edge('a1', 'a2') c.add_edge('a2', 'a3') c.add_edge('start', 'b0') c.add_edge('b0', 'b1') c.add_edge('b1', 'b2') c.add_edge('b2', 'b3') c.add_edge('b2', 'a3') c.add_edge('a3', 'end') c.add_edge('b3', 'end') c.add_edge('a3', 'a0') c.add_edge('a1', 'b3') # set node attributes c.set_node_attr('start', 'shape', 'Mdiamond') c.set_node_attr('end', 'shape', 'Msquare')
print 'Warning: Dot2tex can not found.' if PIL_INSTALLED: print 'PIL (Python Imaging Library) is installed.' elif not PIL_INSTALLED: print 'Warning: PIL (Python Imaging Library) can not found.' if XDOT_INSTALLED: print 'Xdot is installed.' elif not XDOT_INSTALLED: print 'Warning: Xdot can not found.' if ETREE_INSTALLED: print 'Etree is installed.' elif not ETREE_INSTALLED: print 'Warning: Etree can not found.' if __name__=="__main__": g = Graph(display='off', layout='dot') g.random(numnodes= 20, density =0.2) # test pygame g.set_display_mode('pygame') g.display() # test xdot g.set_display_mode('xdot') g.display() # test file, layout dot g.set_display_mode('file') g.display(basename='test_graph') # test file, layout dot2tex g.set_display_mode('file') g.set_layout('dot2tex') g.display() # test PIL
def generate_test_instance2(): g = Graph(type=DIRECTED_GRAPH, display='pygame') g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(2, 3) g.add_edge(3, 0) g.add_edge(0, 4) g.add_edge(4, 5) g.add_edge(5, 6) g.add_edge(6, 4) g.add_edge(4, 7) g.add_edge(7, 1) g.add_edge(1, 8) return g
from gimpy import Graph if __name__=='__main__': g = Graph() g.add_edge(1,2) g.add_edge(1,3) g.add_edge(3,4) g.add_edge(3,5) g.add_edge(2,4) g.add_edge(6,7) g.add_edge(7,8) g.add_edge(7,9) g.label_components() g.set_display_mode('pygame') g.label_components(display='pygame')
def __init__(self, **attrs): #constructor method Graph.__init__(self, **attrs)
def generate_test_instance1(): g = Graph(type=DIRECTED_GRAPH, display='pygame') g.add_edge(0,1) g.add_edge(1,2) g.add_edge(2,0) g.add_edge(2,3) g.add_edge(3,4) g.add_edge(5,6) g.add_edge(6,7) g.add_edge(7,8) g.add_edge(8,6) g.add_edge(6,9) g.add_edge(10,11) return g
def generate_test_instance2(): g = Graph(type=DIRECTED_GRAPH, display='pygame') g.add_edge(0,1) g.add_edge(0,2) g.add_edge(2,3) g.add_edge(3,0) g.add_edge(0,4) g.add_edge(4,5) g.add_edge(5,6) g.add_edge(6,4) g.add_edge(4,7) g.add_edge(7,1) g.add_edge(1,8) return g
from gimpy import Graph if __name__ == '__main__': g = Graph() g.add_edge(1, 2) g.add_edge(1, 3) g.add_edge(3, 4) g.add_edge(3, 5) g.add_edge(2, 4) g.add_edge(6, 7) g.add_edge(7, 8) g.add_edge(7, 9) g.label_components() g.set_display_mode('pygame') g.label_components(display='pygame')
''' This script implements the graphviz example at location http://www.graphviz.org/Gallery/directed/cluster.html in our graph class. Main purpose of the Graph class is not to be python interface to graphviz. Main purpose is to implement a graph class using the methods in the literature and measuring running time performances. Hence it is teaching/research oriented. This script demonstrates the Graph class's capability as a graphviz interface. ''' from gimpy import Graph, DIRECTED_GRAPH if __name__ == '__main__': c = Graph(type=DIRECTED_GRAPH, layout='dot') # add edges c.add_edge('start', 'a0') c.add_edge('a0', 'a1') c.add_edge('a1', 'a2') c.add_edge('a2', 'a3') c.add_edge('start', 'b0') c.add_edge('b0', 'b1') c.add_edge('b1', 'b2') c.add_edge('b2', 'b3') c.add_edge('b2', 'a3') c.add_edge('a3', 'end') c.add_edge('b3', 'end') c.add_edge('a3', 'a0') c.add_edge('a1', 'b3') # set node attributes c.set_node_attr('start', 'shape', 'Mdiamond') c.set_node_attr('end', 'shape', 'Msquare')
def __init__(self, **attrs): Graph.__init__(self, **attrs)