-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphillion_utils.py
96 lines (70 loc) · 2.02 KB
/
graphillion_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
Author: Mio Kinno
Date: 2018.6.11
File: graphillion_utils.py
graphillionを操作しているときによく使う機能をまとめたモジュール
"""
import random
from graphillion import GraphSet
def degree(node):
"""
nodeの字数を返す
arguments:
* node(node label)
returns:
* degree(int)
nodeの次数
"""
return len(GraphSet({}).including(node).graph_size(1))
def flatten_paths(paths):
"""
パス集合を平滑化してリンクを要素とするリストを返す
"""
return [edge for path in paths for edge in path]
def min_hop(terminal):
"""
2頂点間を結ぶパスの最小ホップ数を求める
"""
return len(next(GraphSet.paths(terminal[0], terminal[1]).min_iter()))
def max_hop(terminal):
"""
2頂点間を結ぶパスの最大ホップ数を求める
"""
return len(next(GraphSet.paths(terminal[0], terminal[1]).max_iter()))
def get_min_hop_paths(paths, terminal):
"""
最小ホップ数のパス集合を返す
arguments:
* paths(graphset)
* terminal(tuple (s, t), including start and target node)
returns:
* min_hop_paths(graphset)
"""
return paths.graph_size(min_hop(terminal))
def excluding_multi_elms(graphset, elms):
"""
複数のグラフ要素をグラフセットから削除する
arguments:
* graphset(graphset)
* elms(graph elements, node, edge, graph, graphset)
returns:
* graphset(graphset)
"""
for elm in elms:
graphset = graphset.excluding(elm)
return graphset
def select_sleep_nodes(nodes, terminal, num):
"""
スリープするノードを決定する
arguments:
* nodes(node list)
* terminal(tuple (s, t), including start and target node)
* num(int)
スリープするノードの数
"""
candidate = set(nodes) - set(terminal)
return random.sample(candidate, k=num)
def hamming(graphset, G, upper_limit):
pass
def get_similar_paths(edgelist, terminal, path, upper_limit):
pass