Skip to content

Commit

Permalink
Refactoring ResourceNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Sep 1, 2020
1 parent 641dbb8 commit 0cfc36a
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 300 deletions.
4 changes: 2 additions & 2 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public bool AcceptNewInteraction(IAgentId senderId)
return true;
}

if (Environment.WhitePages.MetaNetwork.Interactions.HasActiveInteraction(AgentId, senderId))
if (Environment.WhitePages.MetaNetwork.Interaction.HasActiveInteraction(AgentId, senderId))
{
return true;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ public bool AcceptNewInteraction(IAgentId senderId)
{
// Message.Sender is now part of agent interaction sphere
var interaction = new Interaction(AgentId, senderId);
Environment.WhitePages.MetaNetwork.Interactions.AddInteraction(interaction);
Environment.WhitePages.MetaNetwork.Interaction.AddInteraction(interaction);
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ protected CognitiveAgent(IAgentId agentId, SymuEnvironment environment, Cognitiv
/// <summary>
/// If agent has an email, get the email database of the agent
/// </summary>
protected Database Email => Environment.WhitePages.MetaNetwork.Resources.GetResource<Database>(AgentId, AgentId.Id) ;
protected Database Email => HasEmail ? Environment.WhitePages.MetaNetwork.Resource.GetResource<Database>(AgentId.Id) : null;

/// <summary>
/// If agent has an email
/// </summary>
public bool HasEmail => Environment.WhitePages.MetaNetwork.Resources.Exists(AgentId, AgentId.Id);
public bool HasEmail => Environment.WhitePages.MetaNetwork.AgentResource.Exists(AgentId, AgentId.Id);

//TODO => all the models should be included in the cognitive architecture
/// <summary>
Expand Down Expand Up @@ -131,7 +131,7 @@ protected override void Initialize()
{
// Organization databases are used by every one
var agentResource = new AgentResource(database.Id, new ResourceUsage(0), 100);
Environment.WhitePages.MetaNetwork.Resources.Add(AgentId, agentResource);
Environment.WhitePages.MetaNetwork.AgentResource.Add(AgentId, agentResource);
}
// intentionally before base.Initialize()
base.Initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class InfluenceModel

//_agentId = agentId;
//_networkInfluences = network.Influences;
_agentNetwork = network.Agents;
_agentNetwork = network.Agent;
_beliefsModel = beliefsModel;
_model = model;

Expand Down
12 changes: 6 additions & 6 deletions SourceCode/Symu/Environment/SymuEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ public virtual void InitializeIteration()
/// </summary>
public void InitializeInteractionNetwork()
{
foreach (var groupId in WhitePages.MetaNetwork.Groups.GetGroups().ToList())
foreach (var groupId in WhitePages.MetaNetwork.AgentGroup.GetGroups().ToList())
{
var agentIds = WhitePages.MetaNetwork.Groups.GetAgents(groupId, new ClassId(SymuYellowPages.Actor))
var agentIds = WhitePages.MetaNetwork.AgentGroup.GetAgents(groupId, new ClassId(SymuYellowPages.Actor))
.ToList();

var count = agentIds.Count;
Expand All @@ -212,7 +212,7 @@ public void InitializeInteractionNetwork()
{
var agentId2 = agentIds[j];
var interaction = new Interaction(agentId1, agentId2);
WhitePages.MetaNetwork.Interactions.AddInteraction(interaction);
WhitePages.MetaNetwork.Interaction.AddInteraction(interaction);
}
}
}
Expand Down Expand Up @@ -456,7 +456,7 @@ public void SetDatabases()
foreach (var database in Organization.Databases.Select(databaseEntity =>
new Database(databaseEntity, Organization.Models, WhitePages.MetaNetwork)))
{
WhitePages.MetaNetwork.Resources.Add(database);
WhitePages.MetaNetwork.Resource.Add(database);
}
}

Expand All @@ -469,7 +469,7 @@ public void SetDatabases()
/// </summary>
public void ScheduleEvents()
{
foreach (var symuEvent in WhitePages.MetaNetwork.Events.List.Cast<SymuEvent>())
foreach (var symuEvent in WhitePages.MetaNetwork.Event.List.Cast<SymuEvent>())
{
symuEvent.Schedule(Schedule.Step);
}
Expand All @@ -482,7 +482,7 @@ public void AddEvent(SymuEvent symuEvent)
throw new ArgumentNullException(nameof(symuEvent));
}

WhitePages.MetaNetwork.Events.Add(symuEvent);
WhitePages.MetaNetwork.Event.Add(symuEvent);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/AgentDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Symu.Common.Interfaces;
using Symu.Common.Interfaces.Agent;
using Symu.Common.Interfaces.Entity;
using Symu.DNA.Resources;
using Symu.DNA.OneModeNetworks.Resource;

#endregion

Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/AgentGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using Symu.Common.Interfaces;
using Symu.Common.Interfaces.Agent;
using Symu.DNA.Groups;
using Symu.DNA.TwoModesNetworks.AgentGroup;

#endregion

Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/AgentPortfolio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Symu.Common.Interfaces;
using Symu.Common.Interfaces.Agent;
using Symu.Common.Interfaces.Entity;
using Symu.DNA.Resources;
using Symu.DNA.OneModeNetworks.Resource;

#endregion

Expand Down
3 changes: 2 additions & 1 deletion SourceCode/Symu/Repository/Entity/AgentResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
using Symu.Common.Interfaces;
using Symu.Common.Interfaces.Agent;
using Symu.Common.Interfaces.Entity;
using Symu.DNA.Resources;
using Symu.DNA.OneModeNetworks.Resource;
using Symu.DNA.TwoModesNetworks.AgentResource;

#endregion

Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using Symu.Common.Interfaces.Entity;
using Symu.DNA;
using Symu.DNA.OneModeNetworks.Knowledge;
using Symu.DNA.Resources;
using Symu.DNA.OneModeNetworks.Resource;
using Symu.DNA.TwoModesNetworks.AgentKnowledge;

#endregion
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using System;
using Symu.Common.Interfaces.Agent;
using Symu.DNA.TwoModesNetworks.Interactions;
using Symu.DNA.TwoModesNetworks.Interaction;
using static Symu.Common.Constants;

#endregion
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Repository/Entity/ResourceUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endregion

using System;
using Symu.DNA.Resources;
using Symu.DNA.OneModeNetworks.Resource;

namespace Symu.Repository.Entity
{
Expand Down
26 changes: 13 additions & 13 deletions SourceCode/Symu/Repository/WhitePages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public WhitePages(OrganizationModels models)

public bool Any()
{
return MetaNetwork.Agents.Any();
return MetaNetwork.Agent.Any();
}

#region Initialize / remove agent
Expand Down Expand Up @@ -148,22 +148,22 @@ public bool ExistsAndStarted(IAgentId agentId)

public bool ExistsAgent(IAgentId agentId)
{
return MetaNetwork.Agents.Exists(agentId);
return MetaNetwork.Agent.Exists(agentId);
}

public void AddAgent(IAgent agent)
{
MetaNetwork.Agents.Add(agent);
MetaNetwork.Agent.Add(agent);
}

public TAgent GetAgent<TAgent>(IAgentId agentId) where TAgent : IAgent
{
return MetaNetwork.Agents.Get<TAgent>(agentId);
return MetaNetwork.Agent.Get<TAgent>(agentId);
}

public ReactiveAgent GetAgent(IAgentId agentId)
{
return (ReactiveAgent)MetaNetwork.Agents.Get(agentId);
return (ReactiveAgent)MetaNetwork.Agent.Get(agentId);
}

/// <summary>
Expand All @@ -172,7 +172,7 @@ public ReactiveAgent GetAgent(IAgentId agentId)
/// <returns></returns>
public IEnumerable<IAgentId> AllAgentIds()
{
return MetaNetwork.Agents.GetKeys();
return MetaNetwork.Agent.GetKeys();
}

/// <summary>
Expand All @@ -181,7 +181,7 @@ public IEnumerable<IAgentId> AllAgentIds()
/// <returns></returns>
public IEnumerable<ReactiveAgent> AllAgents()
{
return MetaNetwork.Agents.GetValues().Cast<ReactiveAgent>();
return MetaNetwork.Agent.GetValues().Cast<ReactiveAgent>();
}

/// <summary>
Expand All @@ -190,15 +190,15 @@ public IEnumerable<ReactiveAgent> AllAgents()
/// <returns></returns>
public IEnumerable<CognitiveAgent> AllCognitiveAgents()
{
return MetaNetwork.Agents.GetValues().OfType<CognitiveAgent>();
return MetaNetwork.Agent.GetValues().OfType<CognitiveAgent>();
}

/// <summary>
/// The number of agents in the environment
/// </summary>
public ushort FilteredAgentsByClassCount(IClassId classKey)
{
return MetaNetwork.Agents.CountByClassId(classKey);
return MetaNetwork.Agent.CountByClassId(classKey);
}

/// <summary>
Expand All @@ -207,7 +207,7 @@ public ushort FilteredAgentsByClassCount(IClassId classKey)
/// <returns>The name fragment that the agent names should contain</returns>
public IEnumerable<IAgentId> FilteredAgentIdsByClassId(IClassId classId)
{
return MetaNetwork.Agents.FilteredKeysByClassId(classId);
return MetaNetwork.Agent.FilteredKeysByClassId(classId);
}

/// <summary>
Expand All @@ -216,7 +216,7 @@ public IEnumerable<IAgentId> FilteredAgentIdsByClassId(IClassId classId)
/// <returns>The name fragment that the agent names should contain</returns>
public IEnumerable<ReactiveAgent> FilteredAgentsByClassId(IClassId classId)
{
return MetaNetwork.Agents.FilteredByClassId(classId).Cast<ReactiveAgent>();
return MetaNetwork.Agent.FilteredByClassId(classId).Cast<ReactiveAgent>();
}

/// <summary>
Expand All @@ -225,7 +225,7 @@ public IEnumerable<ReactiveAgent> FilteredAgentsByClassId(IClassId classId)
/// <returns>The name fragment that the agent names should contain</returns>
public IEnumerable<CognitiveAgent> FilteredCognitiveAgentsByClassId(IClassId classId)
{
return MetaNetwork.Agents.FilteredByClassId(classId).OfType<CognitiveAgent>();
return MetaNetwork.Agent.FilteredByClassId(classId).OfType<CognitiveAgent>();
}

/// <summary>
Expand Down Expand Up @@ -308,7 +308,7 @@ public ushort FilteredStoppedAgentsByClassIdCount(IClassId classId)

public IAgentId GetAgentId(IId componentId)
{
return MetaNetwork.Agents.GetAgentId(componentId);
return MetaNetwork.Agent.GetAgentId(componentId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void HandleTriads(ushort agentsCount)
/// </summary>
public void HandleLinks(ushort agentsCount)
{
var actualLinks = Environment.WhitePages.MetaNetwork.Interactions.Count;
var actualLinks = Environment.WhitePages.MetaNetwork.Interaction.Count;
var maxLinks = Combinatorics.Combinations(agentsCount, 2);
var sphere = new DensityStruct(actualLinks, maxLinks, Environment.Schedule.Step);
Links.Add(sphere);
Expand Down
4 changes: 2 additions & 2 deletions SourceCode/SymuTests/Classes/Agents/CognitiveAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ public void AcceptNewInteractionTest()
public void AcceptNewInteractionTest1()
{
_agent.Cognitive.InteractionPatterns.IsPartOfInteractionSphere = true;
_environment.WhitePages.MetaNetwork.Interactions.AddInteraction(_interaction);
_environment.WhitePages.MetaNetwork.Interaction.AddInteraction(_interaction);
Assert.IsTrue(_agent.AcceptNewInteraction(_agent2.AgentId));
}

Expand Down Expand Up @@ -1316,7 +1316,7 @@ public void TryRecoverBlockerIncompleteKnowledgeTest()
_environment.WhitePages.MetaNetwork.AddAgentToGroup(agentGroup, group.AgentId);
_environment.WhitePages.MetaNetwork.AddAgentToGroup(teammateGroup, group.AgentId);
var interaction = new Interaction(_agent.AgentId, teammate.AgentId);
_environment.WhitePages.MetaNetwork.Interactions.AddInteraction(interaction);
_environment.WhitePages.MetaNetwork.Interaction.AddInteraction(interaction);
teammate.KnowledgeModel.AddKnowledge(_knowledge.Id, KnowledgeLevel.FullKnowledge, 0, -1);
teammate.KnowledgeModel.InitializeExpertise(0);
_agent.KnowledgeModel.GetAgentKnowledge(_knowledge.Id).SetKnowledgeBit(0, 1, 0);
Expand Down
96 changes: 0 additions & 96 deletions SourceCode/SymuTests/Helpers/TestAgentResource.cs

This file was deleted.

0 comments on commit 0cfc36a

Please sign in to comment.