Exemplo n.º 1
0
def test_windmill_graph():
    for n in range(2, 20, 3):
        for k in range(2, 20, 3):
            G = nx.windmill_graph(n, k)
            assert G.number_of_nodes() == (k - 1) * n + 1
            assert G.number_of_edges() == n * k * (k - 1) / 2
            assert G.degree(0) == G.number_of_nodes() - 1
            for i in range(1, G.number_of_nodes()):
                assert G.degree(i) == k - 1
    pytest.raises(nx.NetworkXError, nx.ring_of_cliques, 1, 3)
    pytest.raises(nx.NetworkXError, nx.ring_of_cliques, 15, 0)
Exemplo n.º 2
0
def test_windmill_graph():
    for n in range(2,20):
        for k in range(2,20):
            G = nx.windmill_graph(n,k)
            assert_equal(G.number_of_nodes(), (k-1)*n+1)
            assert_equal(G.number_of_edges(), n*k*(k-1)/2)
            assert_equal(G.degree(0), G.number_of_nodes()-1)
            for i in range(1, G.number_of_nodes()):
                assert_equal(G.degree(i), k-1)
    assert_raises(nx.NetworkXError, nx.ring_of_cliques, 1, 3)
    assert_raises(nx.NetworkXError, nx.ring_of_cliques, 15, 0)
Exemplo n.º 3
0
def test_windmill_graph():
    for n in range(2, 20, 3):
        for k in range(2, 20, 3):
            G = nx.windmill_graph(n, k)
            assert_equal(G.number_of_nodes(), (k - 1) * n + 1)
            assert_equal(G.number_of_edges(), n * k * (k - 1) / 2)
            assert_equal(G.degree(0), G.number_of_nodes() - 1)
            for i in range(1, G.number_of_nodes()):
                assert_equal(G.degree(i), k - 1)
    assert_raises(nx.NetworkXError, nx.ring_of_cliques, 1, 3)
    assert_raises(nx.NetworkXError, nx.ring_of_cliques, 15, 0)
Exemplo n.º 4
0
            "% infected at the end: {0:.2f}%".format(infected_percentage))
    plt.show()


Simulate(G, plot_all=True, plot_final=True)
Simulate(G, plot_all=True, plot_final=True)

G1 = nx.relaxed_caveman_graph(10, 6, 0.3, seed=17)

Populate(G1)
infection_seed = np.random.randint(len(G1.nodes()))
G1.nodes[infection_seed]['I'] = 'red'

nx.draw_networkx(G1, node_color=Color(G1), with_labels=False, node_size=30)

G2 = nx.windmill_graph(4, 5)

Populate(G2)
infection_seed = np.random.randint(len(G2.nodes()))
G2.nodes[infection_seed]['I'] = 'red'

nx.draw_networkx(G2, node_color=Color(G2), with_labels=False, node_size=30)

new_infections = []
infected_history = [1]

Simulate(G1, plot_all=True)

new_infections = []
infected_history = [1]
Exemplo n.º 5
0
i=int(input("enter i value")) #To choose type of the graph

if i == 1:
	G =  nx.cycle_graph(n)#creates cycle graph of n nodes
	print(nx.info(G))
	A = nx.adjacency_matrix(G)
	sp.set_printoptions(linewidth=sp.inf)
	sp.set_printoptions(threshold=sys.maxsize)
	print(A.todense(),file=open("cycle_graph\%d.txt"%(n),'w')) #Outputs the adjacency matrix to a textfile and stores it in a folder called 'cycle graph'
	nx.draw(G)
	plt.show()
elif i == 2:
	G =  nx.wheel_graph(n) #creates wheel graph of n nodes
	print(nx.info(G))
	A = nx.adjacency_matrix(G) #creates an adjacency matrix for graph G
	sp.set_printoptions(linewidth=sp.inf)
	sp.set_printoptions(threshold=sys.maxsize)
	print(A.todense(),file=open("wheel_graph\%d.txt"%(n),'w')) #Outputs the adjacency matrix to a textfile and stores it in a folder called 'wheel graph'
	nx.draw(G)
	plt.show()
elif i == 3:
	k=int(input("enter k value")) %Clique size
	G =  nx.windmill_graph(n,k) #creates wheel graph of n nodes
	print(nx.info(G))
	A = nx.adjacency_matrix(G)
	sp.set_printoptions(linewidth=sp.inf)
	sp.set_printoptions(threshold=sys.maxsize)
	print(A.todense(),file=open("windmill_graph\%d_%d.txt"%(n,k),'w')) #Outputs the adjacency matrix to a textfile and stores it in a folder called 'wheel graph'
	nx.draw(G)
	plt.show()
Exemplo n.º 6
0
# coding: utf-8
"""
@author Liuchen
2019
"""

import networkx as nx
import utils
import dgcnn_models as dgcnn

# G = nx.generators.erdos_renyi_graph(300, 0.1)  # nx 生成ER随机网络
G = nx.windmill_graph(100, 5)  # nx生成的一种特殊结构的网络

# 使用说明:
#         把数据构造出一个networkx 的Graphs,替换这里的G即可。若每个节点有属性向量,可作为各节点的 “feature” 属性,
#     然后在create_dataset方法中将has_feature设为True即可。
#             例: G.nodes[0]['feature'] = [0., 1., 0., 1.]
#                 为G中的节点0添加了"feature"属性,值为[0., 1., 0., 1.]
#     注意:要么所有节点都没有feature,要么全都有且长度一致

train_set, val_set, test_set = utils.create_dataset(G,
                                                    val_num=100,
                                                    test_num=100,
                                                    hop=1,
                                                    max_hop_nodes=None,
                                                    link_percent=1.0,
                                                    has_feature=False,
                                                    embedding_dim=64,
                                                    inject_neg_links=True,
                                                    multi_process=True)
class_num = len(train_set[0].label)  # 类别数量