def draw(self): self.read_nodes() self.Network = self.var_network.get() self.nPoints = sum(int(i) for i in self.lst_Nodes) if self.Network == "GenStar": print "GenStar is the network with points ", self.nPoints self.graph = snap.GenStar(snap.PNGraph, self.nPoints, True) if self.Network == "GenRndGnm": print "GenRndGnm is the network with points ", self.nPoints self.graph = snap.GenRndGnm(snap.PNGraph, self.nPoints, self.nPoints) if self.Network == "GenForestFire": print "GenForestFire is the network with points ", self.nPoints self.graph = snap.GenForestFire(self.nPoints, 0.5, 0.5) if self.Network == "GenFull": print "GenFull is the network with points ", self.nPoints self.graph = snap.GenFull(snap.PNGraph, self.nPoints) if self.Network == "GenCircle": print "GenCircle is the network with points ", self.nPoints self.graph = snap.GenCircle(snap.PNGraph, self.nPoints, 10, 10) self.create_nodes(self.graph)
def generate_friends_network(user_count=10, friends_count=get_friends_count(), prob=get_prob(), network_type='random', conf_model=False): # User list, probability p and network_type is given, construct a graph res = "empty" # generate specific graphs if network_type.lower().find("small") >= 0: # This is a small world network print "Creating a small world network with " + str( user_count) + " users" rnd = snap.TRnd(1, 0) new_graph = snap.GenSmallWorld(user_count, friends_count, prob, rnd) elif network_type.lower().find("ring") >= 0: # A ring graph print "Creating a ring with " + str(user_count) + " users" new_graph = snap.GenCircle(snap.PUNGraph, user_count, friends_count) elif network_type.lower().find("power") >= 0: # Power Law network print "Creating a powerlaw network with " + str(user_count) + " users" new_graph = snap.GenRndPowerLaw(user_count, friends_count, conf_model) else: # A random graph print "Creating a random network with " + str(user_count) + " users" edge_count = user_count * friends_count new_graph = snap.GenRndGnm(snap.PUNGraph, user_count, edge_count) save_graph_in_db(new_graph)
def test_does_not_have_euler_circuit(self): # Let's create a smaller version of the previous circle graph. Then remove one of its edges. # This means that there will be a vertice with odd degree which will "break" the Euler circuit. graph4 = snap.GenCircle(snap.PNGraph,16,4,False) graph4.DelEdge(1,2) result = has_euler_circuit(graph4) self.assertFalse(result)
def test_has_euler_circuit(self): # We are going to create a graph which will be large enough. For this purpose we will # use a generator from the snap library. A circular graph seems to be the easiest pick # in order to satisfy the even degree limitation for all nodes. graph3 = snap.GenCircle(snap.PNGraph,1200,4,False) result = has_euler_circuit(graph3) self.assertTrue(result) self.assertTrue(graph3.GetNodes()>=1000)
def test_has_euler_circuit(self): """ Creates a Circular graph and tests if this graph has a Eurerian Circuit. :return: """ graph = snap.GenCircle(snap.PUNGraph, 10000, 1) result = has_euler_circuit(graph) self.assertTrue(result) self.assertTrue(graph.GetNodes() >= 1000)
def genCircle(N=5242): """ :param - N: number of nodes return type: snap.PUNGraph return: Circle graph with N nodes and N edges. Imagine the nodes form a circle and each node is connected to its two direct neighbors. """ ############################################################################ # TODO: Your code here! Graph = snap.GenCircle(snap.PUNGraph, N, 1, False) # snap.DrawGViz(Graph, snap.gvlDot, 'circle_graph.png', 'circle graph') ############################################################################ return Graph
def base_graph(self): G = None if self.graph_type == 'star': G = snap.GenStar(snap.PUNGraph, self.nnodes, False) elif self.graph_type == 'full': G = snap.GenFull(snap.PUNGraph, self.nnodes) elif self.graph_type == 'circle': G = snap.GenCircle(snap.PUNGraph, self.nnodes, False) elif self.graph_type == 'tree': G = snap.GenTree(snap.PUNGraph, Fanout=2, Levels=10, IsDir=False) elif self.graph_type == 'erdos-renyi' or self.graph_type == 'er': G = snap.GenRndGnm(snap.PUNGraph, self.nnodes, self.nnodes * 5, False) elif self.graph_type == 'barabasi-albert' or self.graph_type == 'ba': G = snap.GenPrefAttach(self.nnodes, 10) else: print "> Defaulting to full mode" G = snap.GenFull(snap.PUNGraph, self.nnodes) return G
def SimpleNetworkGenerator(self, params): #print params Rnd = snap.TRnd(1, 0) G = None try: if params[0] == GlobalParameters.NetworkType[0]: G = snap.GenSmallWorld(int(params[1]), int(params[2]), float(params[3]), Rnd) if params[0] == GlobalParameters.NetworkType[1]: G = snap.GenPrefAttach(int(params[1]), int(params[2]), Rnd) if params[0] == GlobalParameters.NetworkType[2]: G = snap.GenForestFire(int(params[1]), float(params[2]), float(params[3])) if params[0] == GlobalParameters.NetworkType[3]: G = snap.GenRndGnm(snap.PUNGraph, int(params[1]), int(params[2]), False, Rnd) if params[0] == GlobalParameters.NetworkType[4]: G = snap.GenCircle(snap.PUNGraph, int(params[1]), int(params[2]), False) if params[0] == GlobalParameters.NetworkType[5]: G = snap.GenFull(snap.PUNGraph, int(params[1])) return G except: return None
def drawNode(self): global GNodesItemNo if self.Network == "GenStar": print "GenStar is the network with points ",self.nPoints Graph = snap.GenStar(snap.PNGraph, self.nPoints, True) if self.Network == "GenRndGnm": print "GenRndGnm is the network with points ",self.nPoints Graph = snap.GenRndGnm(snap.PNGraph,self.nPoints, self.nPoints) if self.Network == "GenForestFire": print "GenForestFire is the network with points ",self.nPoints Graph = snap.GenForestFire(self.nPoints, 0.5,0.5) if self.Network == "GenFull": print "GenFull is the network with points ",self.nPoints Graph = snap.GenFull(snap.PNGraph,self.nPoints) if self.Network == "GenCircle": print "GenCircle is the network with points ",self.nPoints Graph = snap.GenCircle(snap.PNGraph,self.nPoints,10,10) shape = 0 self.dnodes.reverse() nodeCounter = self.dnodes.pop() for i in Graph.Nodes(): self.node = Node() self.node.id = i.GetId() for EI in Graph.Edges(): if EI.GetSrcNId() == i.GetId(): if EI.GetSrcNId() <> EI.GetDstNId() : self.node.follower.append(EI.GetDstNId()) if shape ==0: self.node.shape = "oval" if shape ==1: self.node.shape = "triangle" if shape ==2: self.node.shape = "rectangle" if shape ==3: self.node.shape = "circle" nodeCounter = nodeCounter - 1 if nodeCounter <=0: if len(self.dnodes)<> 0: nodeCounter = self.dnodes.pop() print "Completed Community: ",shape shape = shape + 1 self.CoordinateSelection() self.Radius = 5 ## if len(self.node.follower) <> 0: ## self.Radius = len(self.node.follower) if self.node.shape == "oval": _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius, self.node.y+self.Radius,outline="#ff00ff",fill="white", width=2) if self.node.shape == "triangle": traingle = [self.node.x,self.node.y,self.node.x+self.Radius,self.node.y+self.Radius] _Oval = Gcanvas.create_oval(traingle,outline="#252568",fill="white", width=2) if self.node.shape == "rectangle": _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius, self.node.y+self.Radius,outline="#474bcc",fill="white", width=2) if self.node.shape == "circle": _Oval = Gcanvas.create_oval(self.node.x,self.node.y,self.node.x+self.Radius, self.node.y+self.Radius,outline="#364949",fill="white", width=2) self.OvalNo[_Oval]=self.node.id#[self.node.x,self.node.y] Gcanvas.tag_bind( _Oval, '<ButtonPress-1>', self.__showAttriInfo) self.itemNo.append(_Oval) self.pAll.append(self.node) GNodesItemNo = self.itemNo
def test_has_euler_circuit(self): graph = snap.GenCircle(snap.PNGraph, 10000, 10) # FILL HERE result = has_euler_circuit(graph) self.assertTrue(result) self.assertTrue(graph.GetNodes() >= 1000)
def circle(): G = snap.GenCircle(snap.PUNGraph, nodes, nodes / 10) snap.SaveEdgeList(G, args.type + '.txt')
#!/usr/bin/env python3 import snap import sys if len(sys.argv) < 3: print("Usage mode: ./{} n_of_vertices out_degree".format(sys.argv[0])) sys.exit(1) n = int(sys.argv[1]) out_d = int(sys.argv[2]) # = round(p*n*(n-1)/2) # my_seed = 42 G = snap.GenCircle(snap.TUNGraph, n, out_d) file_name = "circle_n{}_out{}.txt".format(n,out_d) f = open(file_name, "w") for e in G.Edges(): (u,v) = (e.GetSrcNId(), e.GetDstNId()) f.write("{}\t{}\n".format(u,v)) f.close()