Skip to content

Commit

Permalink
Refactoring MetaNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Aug 19, 2020
1 parent 672bfeb commit 0c0ae11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
14 changes: 13 additions & 1 deletion SourceCode/Symu/Environment/SymuEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,22 @@ public virtual void InitializeIteration()
SetKnowledges();
SetAgents();
// Intentionally after SetAgents
WhitePages.MetaNetwork.InitializeNetworkLinks();
InitializeNetworkLinks();
WhitePages.SetStarted();
}

/// <summary>
/// Initialize the network links.
/// For performance it is not done in AddMemberToGroup at initialization
/// </summary>
public void InitializeNetworkLinks()
{
foreach (var groupId in WhitePages.MetaNetwork.Groups.GetGroups().ToList())
{
WhitePages.MetaNetwork.Links.AddLinks(WhitePages.MetaNetwork.Groups.GetAgents(groupId, new ClassId(SymuYellowPages.Actor)).ToList());
}
}

/// <summary>
/// Stop Agent is managed by the WhitePages services responsible of Agent Lifecycle Management
/// </summary>
Expand Down
25 changes: 11 additions & 14 deletions SourceCode/Symu/Repository/Networks/MetaNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

#region using directives

using System;
using System.Collections.Generic;
using System.Linq;
using Symu.Common.Interfaces;
using Symu.Classes.Agents;
using Symu.Classes.Organization;
using Symu.Repository.Networks.Activities;
using Symu.Repository.Networks.Beliefs;
using Symu.Repository.Networks.Databases;
Expand Down Expand Up @@ -153,6 +152,11 @@ public void RemoveAgent(IAgentId agentId)
/// </param>
public void AddAgentToGroup(IAgentId agentId, float allocation, IAgentId groupId, bool addLink)
{
if (agentId == null)
{
throw new ArgumentNullException(nameof(agentId));
}

lock (Groups)
{
Groups.AddGroup(groupId);
Expand All @@ -170,18 +174,6 @@ public void AddAgentToGroup(IAgentId agentId, float allocation, IAgentId groupId
Resources.AddMemberToGroup(agentId, groupId);
}

/// <summary>
/// Initialize the network links.
/// For performance it is not done in AddMemberToGroup at initialization
/// </summary>
public void InitializeNetworkLinks()
{
foreach (var groupId in Groups.GetGroups().ToList())
{
Links.AddLinks(Groups.GetAgents(groupId, new ClassId(SymuYellowPages.Actor)).ToList());
}
}

/// <summary>
/// Remove an agent to a group
/// It doesn't handle roles
Expand All @@ -190,6 +182,11 @@ public void InitializeNetworkLinks()
/// <param name="groupId"></param>
public void RemoveAgentFromGroup(IAgentId agentId, IAgentId groupId)
{
if (agentId == null)
{
throw new ArgumentNullException(nameof(agentId));
}

if (!Groups.Exists(groupId))
{
return;
Expand Down

0 comments on commit 0c0ae11

Please sign in to comment.