Esempio n. 1
0
def generator(n):
	'''Generator for our social graph.

	Our graph will have n nodes, it will be a Dorogovtsev-Mendes's Graph, and
	it will handle reputation (for 	nodes) and affect (for edges).'''
	
	G = nx.dorogovtsev_goltsev_mendes_graph(1)
	
	'''In this loop we generate a raw network'''
	for i in range(n-3):
		r = random.choice(range(nx.number_of_edges(G)))
		
		e = nx.edges(G)
		e = e[r] #e is the selected edge
		
		nn = G.number_of_nodes() #nn is the new node number

		G.add_node(nn)

		G.add_edge(nn, e[0])
		G.add_edge(nn, e[1])

	'''In this bloc we set reputations'''
	reput = {}
	md = graphlib.max_degree(G)
	for i in range(G.number_of_nodes()):
		reput[i] = random.random() #float(G.degree(i))/float(md)

	nx.set_node_attributes(G,'reput',reput)

	'''And then we set affect'''
	affect = {}
	e = nx.edges(G)
	for i in range(G.number_of_edges()):
		affect[e[i]] = random.random()

	nx.set_edge_attributes(G,'affect',affect)	

	return G
Esempio n. 2
0
		e = nx.edges(G3)
		e = e[r] #e is the selected edge
		
		nn = G3.number_of_nodes() #nn is the new node number

		G3.add_node(nn)

		G3.add_edge(nn, e[0])
		G3.add_edge(nn, e[1])

	listG = [G1,G2,G3]

	for G in listG:
		'''In this bloc we set reputations'''
		reput = {}
		md = graphlib.max_degree(G)
		for i in range(G.number_of_nodes()):
			reput[i] = random.random() #float(G.degree(i))/float(md)

		nx.set_node_attributes(G,'reput',reput)

		'''And then we set affect'''
		affect = {}
		e = nx.edges(G)
		for i in range(G.number_of_edges()):
			affect[e[i]] = random.random()

		nx.set_edge_attributes(G,'affect',affect)
	layout = nx.spring_layout(G3)
	#graphlib.plot_graphs([G1,G2,G3], layout)