Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit d749cc0

Browse files
committed
[Feat] Add simplified isomorphism check
1 parent 66b8ac2 commit d749cc0

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/SubgraphDetection/DataStructure/SimpleMindsporeGraph/smsgraph.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,35 +221,38 @@ def get_level(scope: Scope):
221221
for name, scope in self._scope_node.items():
222222
scope.type = name[name.rfind("/") + 1:]
223223
else:
224-
# TODO:implementation of isomorphism check
225-
226-
# isomorphism check step.1: check level, size and connected node count
224+
# isomorphism check: check level, size and connected node count
225+
# TODO: detailed isomorphism check (very expensive, may be unnecessary)
227226
scope_basic_info_buffer = {
228-
scope_name: "{level}-{size}-{upstream}-{downstream}".format(
227+
scope_name: hash("{level}-{size}-{upstream}-{downstream}-{upstream_type}-{downstream_hash}".format(
229228
level=scope_name.count("/"),
230229
size=len(scope.member),
231230
upstream=len(scope.upstream),
232231
downstream=len(scope.downstream),
233-
)
232+
upstream_type=hash("".join(self._normal_node[n].type for n in scope.upstream)),
233+
downstream_hash=hash("".join(self._normal_node[n].type for n in scope.downstream)),
234+
))
234235
for scope_name, scope in self._scope_node.items()
235236
}
236237
isomorphic_scope_candidate = []
237238
scope_basic_info_buffer_reverse = {}
238239
for scope_id, info in scope_basic_info_buffer.items():
239240
if info not in scope_basic_info_buffer_reverse.keys():
240241
scope_basic_info_buffer_reverse[info] = [
241-
scope_id[scope_id.rfind("/") + 1:]
242+
scope_id
242243
]
243244
else:
244245
scope_basic_info_buffer_reverse[info].append(
245-
scope_id[scope_id.rfind("/") + 1:]
246+
scope_id
246247
)
247248
for info, scope_ids in scope_basic_info_buffer_reverse.items():
248249
if len(scope_ids) > 1:
249250
isomorphic_scope_candidate.append(scope_ids)
250251

251-
# isomorphism check step.2: check in detailed
252-
pass
252+
for candidate in isomorphic_scope_candidate:
253+
scope_type = hash(candidate[0])
254+
for s in candidate:
255+
self._scope_node[s].type = str(scope_type)
253256

254257
def get_level_node(self, level: int) -> Dict[int, Union[SNode, Scope]]:
255258
"""

src/SubgraphDetection/DataStructure/Subgraph/subgraph_core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def grow(
7777
Returns:
7878
The new core grow from self
7979
"""
80-
# TODO:check if node_pattern, grow_nodes, keep_instance_index is valid
8180

8281
# do some copy
8382
new_core = SubgraphCore(nodes=None)

src/SubgraphDetection/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Config:
2323
# The maximum node number of a subgraph, subgraph instance with more nodes will not be detected
2424
MAX_SUBGRAPH_NODE_NUMBER: int = 36
2525

26-
# Penalty terms are imposed on sub-sub-graph in zthresholds to avoid multiple level subgraphs
26+
# Penalty terms are imposed on sub-sub-graph in thresholds to avoid multiple level subgraphs
2727
SUB_SUB_GRAPH_THRESHOLD_PENALTY: int = 2
2828

2929
# Whether to check the result after finish calculation

0 commit comments

Comments
 (0)