Skip to content
Snippets Groups Projects
Commit 95613970 authored by Jarrod Pas's avatar Jarrod Pas
Browse files

Fix bugs in community detection base

parent 030475fa
No related branches found
No related tags found
2 merge requests!3Version 0.2,!1Full rewrite
...@@ -140,7 +140,7 @@ class Community: ...@@ -140,7 +140,7 @@ class Community:
return 0 return 0
return sum( return sum(
edge['duration'] edge['weight']
for other, edge in graph[node].items() for other, edge in graph[node].items()
if other in node.community if other in node.community
) )
...@@ -153,7 +153,7 @@ class Community: ...@@ -153,7 +153,7 @@ class Community:
return 0 return 0
return sum( return sum(
edge['duration'] edge['weight']
for other, edge in graph[node].items() for other, edge in graph[node].items()
if other not in node.community if other not in node.community
) )
...@@ -165,11 +165,11 @@ class Community: ...@@ -165,11 +165,11 @@ class Community:
if node not in graph: if node not in graph:
return 0 return 0
return len( return len([
other other
for other in node.community for other in node.community
if graph.has_edge(node, node) if graph.has_edge(node, node)
) ])
def community_betweenness(self, node_a, node_b): def community_betweenness(self, node_a, node_b):
"""Return community betweenness for 2 nodes.""" """Return community betweenness for 2 nodes."""
...@@ -181,12 +181,12 @@ class Community: ...@@ -181,12 +181,12 @@ class Community:
return float('inf') return float('inf')
return sum( return sum(
graph[a][b]['duration'] graph[a][b]['weight']
for a, b in product(community_a, community_b) for a, b in product(community_a, community_b)
if graph.has_edge(a, b) if graph.has_edge(a, b)
) )
def nodal_contribution_factor(self, node_a, node_b): def nodal_contribution(self, node_a, node_b):
"""Return nodal contribution factor of node_a in node_b's community.""" """Return nodal contribution factor of node_a in node_b's community."""
graph = self.graph_old graph = self.graph_old
community_b = self[node_b] community_b = self[node_b]
...@@ -195,7 +195,7 @@ class Community: ...@@ -195,7 +195,7 @@ class Community:
return 0 return 0
return sum( return sum(
graph[node_a][b]['duration'] graph[node_a][b]['weight']
for b in community_b for b in community_b
if graph.has_edge(node_a, b) if graph.has_edge(node_a, b)
) )
...@@ -231,9 +231,9 @@ class LouvainCommunity(Community): ...@@ -231,9 +231,9 @@ class LouvainCommunity(Community):
class CommunityNode(Node): class CommunityNode(Node):
"""Base node for community based forwarding heuristics.""" """Base node for community based forwarding heuristics."""
def __init__(self, name, community=None, **options): def __init__(self, community=None, **options):
"""Create a community based node.""" """Create a community based node."""
super().__init__(name, **options) super().__init__(**options)
if community is None: if community is None:
raise ValueError('No community set') raise ValueError('No community set')
self._community = community self._community = community
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment