def ErdosRenyiKnotting(): """ Finds the relationship between the probability in an Erdos Renyi graph (p) and the odds that this graph has a knot. """ for num_vert in [5,15,30]: p = .01 ps = [] vs = [Vertex(str(v)) for v in range(num_vert)] ys = [] for k in range(100): knot_count = 0 for i in range(100): drg = DirectedGraph(vs) drg.add_random_arcs(p) #~ c = CircleLayout(drg) if drg.has_knot(): knot_count += 1 knot_prob = knot_count/100.0 ys.append(knot_prob) ps.append(p) p += .01 pyplot.figure(1) pyplot.plot(ps,ys,'o') pyplot.xlabel('p') pyplot.ylabel('Odds of having a knot') pyplot.legend(('5 Vertices','15 Vertices','30 Vertices')) pyplot.show()
def ErdosRenyiClustering(): """ Creates an Erdos-Renyi graph of 1000 vertices and iterates through p, checking the clustering coefficient each time. Uses pylot to graph all that stuff, to see if there's anything interesting """ import matplotlib.pyplot as pyplot vs = [Vertex(str(v)) for v in range(100)] cs = [] ps = [] p = 0.01 for i in range(100): drg = DirectedGraph(vs) drg.add_random_arcs(p) ps.append(p) cs.append(drg.clustering_coefficient()) p += 0.01 pyplot.plot(ps,cs) pyplot.xlabel('p') pyplot.ylabel('clustering coefficient') pyplot.show()
def test_random_directed_graph(self): vs = [Vertex(str(x)) for x in range(100)] rdg = DirectedGraph(vs) rdg.add_random_arcs(p=.2) self.assertFalse(rdg.is_complete())