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

Merge branch 'bugfix/communty-detection-not-shared' into 'develop'

Fixes shared community detection not being shared

See merge request !11
parents 6a354843 f23fb8c8
No related branches found
No related tags found
1 merge request!11Fixes shared community detection not being shared
Pipeline #
......@@ -29,6 +29,7 @@ def run_simulation(simulation):
'tick_rate': 5 * 60, # 5 mins
'epoch': epoch,
'k': 3,
'context': {}
}
nodes = {
node_id: simulation.node_type(**node_options)
......
......@@ -307,6 +307,21 @@ class CommunityNode(Node):
]
def shared_community(context, create):
"""
Check context for shared community and return a shared community.
Use this for community detection algorithms that must have one instance
for a set of nodes.
"""
if 'shared-community' in context:
return context['shared-community']
community = create()
context['shared-community'] = community
return community
class LouvainNode(CommunityNode):
"""Wrapper to add louvain community detection automatically to a node."""
......@@ -317,7 +332,9 @@ class LouvainNode(CommunityNode):
Keyword Arguments:
epoch -- how often to recalculate communities
"""
options['community'] = LouvainCommunity(options['epoch'])
def _create():
return LouvainCommunity(options['epoch'])
options['community'] = shared_community(options['context'], _create)
super().__init__(**options)
......@@ -332,7 +349,9 @@ class KCliqueNode(CommunityNode):
epoch -- how often to recalculate communities
k -- initial community size
"""
options['community'] = KCliqueCommunity(options['epoch'], options['k'])
def _create():
return KCliqueCommunity(options['epoch'], options['k'])
options['community'] = shared_community(options['context'], _create)
super().__init__(**options)
......
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