csvファイルから有効リンク情報を読み込み、以下の様にコーディングしました。エッジをprint文で確認すると、以下のcsvファイルをノードとエッジに入れて出力しました。
この時、エッジの指定通りにリンクをつないでくれている要素もあれば、本来は存在しないはずの(0になるはずの)、adj_mat[96,87]に700と返されてしまいました。node1とnode2を両方に有効な重![イメージ説明]capacity(man/min)のグラフとして隣接行列を取得したいのに、存在しないリンクがあるのは何故でしょうか。
この原因と解決方法を知りたいです。よろしくお願いします。
直下はコード内のprint文の返しです。
以下のファイルの頭を抜いてリストにして返す関数
set_file=rw.csv_file_read2(file_name,False)
Node = []
Edges = []
for i in set_file: if (int(i[0]) or int(i[1])) not in Node: Node.append(int(i[0])) Node.append(int(i[1])) if (int(i[0]),int(i[1]), int(i[5])) not in Edges: Edges.append((int(i[0]),int(i[1]), int(i[5]))) Node.sort() print(Edges) G = nx.Graph() G.add_nodes_from(Node) G.add_weighted_edges_from(Edges) adj_mat = nx.to_numpy_matrix(G) print(adj_mat[96,87])
#csvファイルの中身======
"""
node1,node2,link_time(min),link_capacity(台/min),walker_linktime(min),link_capacity(man/min)
1,2,2,360,5,243
1,14,1,360,3,243
1,19,2,360,5,243
2,14,1,360,3,243
2,20,2,360,4,243
2,3,1,360,2,243
3,4,1,360,2,243
3,15,1,360,2,243
3,21,2,360,5,243
4,15,1,360,2,243
4,22,2,360,4,243
4,23,2,360,5,243
4,5,2,360,4,243
4,6,2,360,3,243
4,24,3,360,7,243
5,6,2,360,4,243
5,7,3,360,8,243
6,7,2,360,6,243
7,24,1,360,2,243
7,8,2,360,4,243
7,42,1,360,4,243
7,9,2,360,5,243
7,31,1,360,3,243
7,25,3,360,5,243
8,9,1,360,4,243
9,25,2,360,5,243
9,10,2,360,4,243
10,26,2,360,6,243
10,17,2,360,8,243
10,11,2,360,6,243
11,17,2,360,7,243
11,12,1,360,3,243
11,27,2,360,8,243
12,18,2,360,6,243
12,28,2,360,6,243
12,13,3,360,9,243
14,19,1,360,3,243
14,20,1,360,2,243
15,22,1,360,3,243
16,22,1,360,2,243
16,23,1,360,2,243
17,26,2,360,4,243
18,28,2,360,5,243
19,20,2,360,4,243
19,30,2,360,4,243
19,36,3,360,8,243
19,35,3,360,7,243
20,30,2,360,4,243
20,37,3,360,5,243
20,21,1,360,3,243
21,38,2,360,4,243
21,22,1,360,3,243
22,23,1,360,3,243
22,39,2,360,4,243
23,40,2,360,4,243
23,24,1,360,3,243
24,41,2,360,4,243
25,31,2,360,4,243
25,43,1,360,3,243
25,26,2,360,4,243
26,44,1,360,3,243
26,45,2,360,5,243
26,32,1,360,3,243
26,27,2,360,4,243
27,32,1,360,3,243
27,47,3,360,5,243
27,28,2,360,5,243
28,33,1,360,3,243
28,34,1,360,3,243
28,29,1,360,3,243
29,34,1,360,2,243
30,36,2,360,4,243
30,37,2,360,5,243
31,42,1,360,2,243
31,43,2,360,4,243
32,45,2,360,4,243
32,47,2,360,5,243
33,34,1,360,2,243
35,36,2,360,4,243
36,37,2,360,4,243
36,63,3,360,5,243
37,38,1,360,3,243
37,54,1,360,3,243
38,39,1,360,3,243
38,49,1,360,2,243
38,54,1,360,3,243
39,49,1,360,2,243
39,55,1,360,3,243
39,50,1,360,2,243
39,40,1,360,2,243
40,50,1,360,3,243
40,56,2,360,4,243
40,41,2,360,4,243
41,57,3,360,7,243
41,51,2,360,4,243
41,42,1,360,3,243
42,51,2,360,5,243
42,58,3,360,8,243
42,52,2,360,5,243
42,43,3,360,6,243
43,52,2,360,4,243
43,59,4,360,9,243
43,44,2,360,4,243
44,60,3,360,7,243
44,45,1,360,3,243
45,61,2,360,4,243
45,46,1,360,2,243
45,47,1,360,2,243
47,46,1,360,2,243
47,62,2,360,5,243
47,48,3,360,5,243
47,34,4,360,8,243
48,53,2,360,5,243
48,72,2,360,6,243
49,54,1,360,2,243
49,55,1,360,2,243
50,55,1,360,2,243
50,56,1,360,2,243
51,57,2,360,3,243
51,58,2,360,4,243
52,58,2,360,4,243
52,59,2,360,5,243
54,63,2,360,5,243
54,55,1,360,3,243
55,64,2,360,5,243
55,56,1,360,2,243
56,65,2,360,4,243
56,57,2,360,3,243
57,66,2,360,5,243
57,58,1,360,3,243
58,67,2,360,4,243
58,59,2,360,4,243
59,68,2,360,3,243
59,60,2,360,4,243
60,69,1,360,2,243
60,61,2,360,3,243
61,70,2,360,4,243
61,62,2,360,5,243
62,71,1,360,3,243
62,72,2,360,6,243
62,53,1,360,3,243
63,73,3,360,7,243
63,64,1,360,3,243
64,73,2,360,4,243
64,65,2,360,4,243
65,73,3,360,6,243
65,66,1,360,2,243
66,67,1,360,2,243
67,68,2,360,4,243
68,69,2,360,4,243
69,74,3,360,5,243
69,70,1,360,3,243
70,74,2,360,4,243
70,71,2,360,4,243
71,74,2,360,4,243
71,72,2,360,5,243
75,76,0,0,1,560
76,77,0,0,1,560
77,78,0,0,1,560
78,79,0,0,1,560
79,80,0,0,2,560
80,81,0,0,1,560
81,82,0,0,2,560
83,84,0,0,1,560
84,85,0,0,1,560
85,86,0,0,1,560
86,79,0,0,1,560
87,88,0,0,2,700
88,89,0,0,2,700
89,90,0,0,1,700
90,91,0,0,1,700
91,92,0,0,1,700
92,93,0,0,1,700
93,94,0,0,1,700
94,95,0,0,1,700
95,96,0,0,3,700
96,97,0,0,1,700
88,98,0,0,1,700
98,99,0,0,1,700
99,100,0,0,1,700
100,101,0,0,1,700
101,102,0,0,1,700
102,103,0,0,1,700
103,104,0,0,1,700
1,75,0,0,1,500
2,76,0,0,1,500
4,77,0,0,1,500
5,78,0,0,1,500
7,79,0,0,1,500
9,80,0,0,1,500
10,81,0,0,1,500
13,82,0,0,1,500
19,83,0,0,1,500
21,84,0,0,1,500
23,85,0,0,1,500
24,86,0,0,1,500
35,87,0,0,1,500
36,88,0,0,1,500
38,89,0,0,1,500
39,90,0,0,1,500
40,91,0,0,1,500
41,92,0,0,1,500
42,93,0,0,1,500
45,94,0,0,1,500
47,95,0,0,1,500
34,96,0,0,1,500
29,97,0,0,1,500
63,98,0,0,1,500
64,99,0,0,1,500
65,100,0,0,1,500
67,101,0,0,1,500
70,102,0,0,1,500
71,103,0,0,1,500
72,104,0,0,1,500
"""
コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/07/26 07:06