diff --git a/algorithm/LPA.py b/algorithm/LPA.py index b98c4ce..8eb55dc 100644 --- a/algorithm/LPA.py +++ b/algorithm/LPA.py @@ -28,6 +28,11 @@ def get_max_neighbor_label(self,node_index): for neighbor_index in self._G.neighbors(node_index): neighbor_label = self._G.node[neighbor_index]["label"] m[neighbor_label] += 1 + + if(not bool(m)): + #return label of the vertex itself if it's an isolated vertex + return [self._G.node[node_index]["label"]] + max_v = max(m.itervalues()) return [item[0] for item in m.items() if item[1] == max_v] @@ -68,4 +73,4 @@ def execute(self): algorithm = LPA(G) communities = algorithm.execute() for community in communities: - print community \ No newline at end of file + print community