Skip to content

Commit

Permalink
Refactoring InteractionSphere
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Aug 19, 2020
1 parent dd206fd commit 672bfeb
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 38 deletions.
1 change: 1 addition & 0 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Murphies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Symu.Common;
using Symu.Messaging.Messages;
using Symu.Repository;
using Symu.Repository.Networks.Sphere;
using Symu.Results.Blocker;
using static Symu.Common.Constants;

Expand Down
3 changes: 2 additions & 1 deletion SourceCode/Symu/Classes/Agents/CognitiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Symu.Messaging.Messages;
using Symu.Repository;
using Symu.Repository.Networks.Databases;
using Symu.Repository.Networks.Sphere;

#endregion

Expand Down Expand Up @@ -188,7 +189,7 @@ public IEnumerable<AgentId> GetAgentIdsForNewInteractions()
public IEnumerable<AgentId> GetAgentIdsForInteractions(InteractionStrategy interactionStrategy)
{
return Environment.WhitePages.MetaNetwork.InteractionSphere
.GetAgentIdsForInteractions(AgentId, interactionStrategy, Cognitive.InteractionPatterns).Cast<AgentId>().ToList();
.GetAgentIdsForInteractions(AgentId, interactionStrategy).Cast<AgentId>().ToList();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using Symu.Common;
using Symu.Common.Math.ProbabilityDistributions;
using Symu.Repository.Networks.Sphere;

#endregion

Expand Down
1 change: 1 addition & 0 deletions SourceCode/Symu/Classes/Organization/OrganizationModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Symu.Common;
using Symu.Engine;
using Symu.Repository.Networks.Beliefs;
using Symu.Repository.Networks.Sphere;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Common;
using Symu.Common.Interfaces;

Expand Down Expand Up @@ -127,19 +126,6 @@ public void Add(IAgentId agentId, AgentExpertise expertise)
}
}

public void Add(IAgentId agentId, ushort knowledgeId, KnowledgeLevel level,
InternalCharacteristics internalCharacteristics)
{
if (internalCharacteristics == null)
{
throw new ArgumentNullException(nameof(internalCharacteristics));
}

AddAgentId(agentId);
AddKnowledge(agentId, knowledgeId, level, internalCharacteristics.MinimumRemainingKnowledge,
internalCharacteristics.TimeToLive);
}

public void Add(IAgentId agentId, ushort knowledgeId, KnowledgeLevel level, float minimumKnowledge,
short timeToLive)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#region using directives

using System;
using Symu.Classes.Organization;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#endregion

namespace Symu.Classes.Organization
namespace Symu.Repository.Networks.Sphere
{
/// <summary>
/// Model for interaction sphere settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#region using directives

using System;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Common;
using Symu.Common.Math;

Expand Down
19 changes: 5 additions & 14 deletions SourceCode/Symu/Repository/Networks/Sphere/InteractionSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Classes.Organization;
using Symu.Common;
using Symu.Common.Interfaces;
using Symu.Common.Math.ProbabilityDistributions;
Expand Down Expand Up @@ -89,7 +86,7 @@ public void SetSphere(bool initialization, List<IAgentId> agentIds, MetaNetwork
}

/// <summary>
/// Clone sphere randomly based on InteractionPatterns
/// Clone sphere randomly
/// </summary>
/// <param name="agentIds"></param>
public void SetSphereRandomly(IReadOnlyList<IAgentId> agentIds)
Expand Down Expand Up @@ -122,7 +119,7 @@ public void SetSphereRandomly(IReadOnlyList<IAgentId> agentIds)
}

/// <summary>
/// Update sphere randomly based on InteractionPatterns with new agent
/// Update sphere randomly with new agent
/// </summary>
/// <param name="agentIds"></param>
/// <param name="network"></param>
Expand Down Expand Up @@ -358,17 +355,11 @@ public static float SetSocialProximity(IAgentId agentId1, IAgentId agentId2, Net
/// Filtered with interactionStrategy and limit with number of new interactions
/// </summary>
/// <param name="agentId"></param>
/// <param name="interactionStrategy">can come from InteractionPatterns, but passed in parameter for unit test</param>
/// <param name="interactionPatterns"></param>
/// <param name="interactionStrategy"></param>
/// <returns></returns>
public IEnumerable<IAgentId> GetAgentIdsForInteractions(IAgentId agentId,
InteractionStrategy interactionStrategy,
InteractionPatterns interactionPatterns)
InteractionStrategy interactionStrategy)
{
if (interactionPatterns is null)
{
throw new ArgumentNullException(nameof(interactionPatterns));
}

if (!_model.On || _agentIndex is null || !_agentIndex.ContainsKey(agentId))
{
Expand Down Expand Up @@ -481,7 +472,7 @@ public static float SetSocialProximity(IAgentId agentId1, IAgentId agentId2, Net
/// Filtered with interactionStrategy and limit with number of new interactions
/// </summary>
/// <param name="agentId"></param>
/// <param name="interactionStrategy">can come from InteractionPatterns, but passed in parameter for unit test</param>
/// <param name="interactionStrategy"></param>
/// <returns></returns>
public IEnumerable<IAgentId> GetAgentIdsForNewInteractions(IAgentId agentId,
InteractionStrategy interactionStrategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#endregion

namespace Symu.Classes.Agents.Models.CognitiveModels
namespace Symu.Repository.Networks.Sphere
{
/// <summary>
/// Enum the different interaction strategy used in InteractionPatterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Common;
using Symu.Repository.Networks.Sphere;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public void Initialize()
public void GeAgentIdsForInteractionsTest()
{
InteractionSphere.SetSphere(true, _iAgents, _network);
Assert.AreEqual(0, InteractionSphere.GetAgentIdsForInteractions(_agentId1, InteractionStrategy.Homophily,
new InteractionPatterns()).Count());
Assert.AreEqual(0, InteractionSphere.GetAgentIdsForInteractions(_agentId1, InteractionStrategy.Homophily).Count());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Symu.Classes.Organization;
using Symu.Common;
using Symu.Common.Interfaces;
using Symu.Repository.Networks.Sphere;
using Symu.Results.Organization;
using SymuTests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,21 @@ private void SetKnowledge(CognitiveAgent actor, IReadOnlyList<Knowledge> knowled
case 0:
// same Knowledge for all
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[0].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
actor.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge,
actor.Cognitive.InternalCharacteristics.TimeToLive);
break;
case 1:
// Knowledge is by group
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[i].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
actor.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge,
actor.Cognitive.InternalCharacteristics.TimeToLive);
break;
case 2:
// Knowledge is randomly defined for agentId
var index = DiscreteUniform.Sample(0, GroupsCount - 1);
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[index].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
actor.Cognitive.InternalCharacteristics.MinimumRemainingKnowledge,
actor.Cognitive.InternalCharacteristics.TimeToLive);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions Symu examples/SymuGroupAndInteraction/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Symu.Environment;
using Symu.Forms;
using Symu.Repository.Networks.Knowledges;
using Symu.Repository.Networks.Sphere;
using SymuGroupAndInteraction.Classes;

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Symu.Classes.Scenario;
using Symu.Engine;
using Symu.Repository.Networks.Knowledges;
using Symu.Repository.Networks.Sphere;
using SymuGroupAndInteraction.Classes;

#endregion
Expand Down

0 comments on commit 672bfeb

Please sign in to comment.