Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Jun 6, 2020
1 parent cf2a636 commit 1b40d85
Show file tree
Hide file tree
Showing 89 changed files with 375 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System;
using System.Collections.Generic;
using Symu.Classes.Agents;
using Symu.Classes.Agents.Models.Templates;
using Symu.Classes.Agents.Models.CognitiveTemplates;
using Symu.Classes.Organization;
using Symu.Classes.Task;
using Symu.Common;
Expand Down Expand Up @@ -138,7 +138,7 @@ private void SetKnowledge(Agent actor, IReadOnlyList<Knowledge> knowledges)
{
actor.KnowledgeModel.AddKnowledge(knowledges[i].Id,
KnowledgeLevel.FullKnowledge,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
actor.BeliefsModel.AddBelief(knowledges[i].Id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Collections.Generic;
using System.Linq;
using Symu.Classes.Agents;
using Symu.Classes.Agents.Models.Templates;
using Symu.Classes.Agents.Models.CognitiveTemplates;
using Symu.Classes.Blockers;
using Symu.Classes.Task;
using Symu.Environment;
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuBeliefsAndInfluence/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void LoadSettings()
tbInfluencers.Text = _environment.InfluencersCount.ToString(CultureInfo.InvariantCulture);
tbKnowledge.Text = _environment.KnowledgeCount.ToString(CultureInfo.InvariantCulture);

HasBeliefs.Checked = OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasBelief;
HasBeliefs.Checked = OrganizationEntity.AgentTemplates.Human.Cognitive.KnowledgeAndBeliefs.HasBelief;
ThresholdForReacting.Text = OrganizationEntity.Murphies.IncompleteBelief.ThresholdForReacting.ToString(CultureInfo.InvariantCulture);

#region Influencer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public override void SetOrganization(OrganizationEntity organization)

base.SetOrganization(organization);

Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationCyclicity = Cyclicity.None;
Organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
Organization.AgentTemplates.Human.Cognitive.InteractionPatterns.IsolationCyclicity = Cyclicity.None;
Organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
Organization.Models.InteractionSphere.SphereUpdateOverTime = true;
Organization.Models.InteractionSphere.On = true;
Organization.Models.Generator = RandomGenerator.RandomUniform;
Expand Down Expand Up @@ -89,21 +89,21 @@ private void SetKnowledge(Agent actor, IReadOnlyList<Knowledge> knowledges, int
// same Knowledge for all
actor.KnowledgeModel.AddKnowledge(knowledges[0].Id,
KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);

break;
case 1:
// Knowledge is by group
actor.KnowledgeModel.AddKnowledge(knowledges[i].Id,
KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
break;
case 2:
// Knowledge is randomly defined for agentId
var index = DiscreteUniform.Sample(0, GroupsCount - 1);
actor.KnowledgeModel.AddKnowledge(knowledges[index].Id,
KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class GroupAgent : Agent
new AgentId(agentKey, ClassKey),
environment)
{
SetCognitive(Environment.Organization.Templates.Standard);
SetCognitive(Environment.Organization.AgentTemplates.Standard);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class PersonAgent : Agent
new AgentId(agentKey, ClassKey),
environment)
{
SetCognitive(Environment.Organization.Templates.Human);
SetCognitive(Environment.Organization.AgentTemplates.Human);
// Communication medium
Cognitive.InteractionCharacteristics.PreferredCommunicationMediums =
CommunicationMediums.FaceToFace;
Expand Down
24 changes: 12 additions & 12 deletions Symu examples/SymuGroupAndInteraction/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Symu.Classes.Agents.Models.CognitiveModel;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Classes.Scenario;
using Symu.Environment;
using Symu.Forms;
Expand Down Expand Up @@ -65,9 +65,9 @@ private void LoadSettings()
#region Interaction

OrganizationEntity.Models.InteractionSphere.SetInteractionPatterns(InteractionStrategy.Homophily);
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true;
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0.1F;
ThresholdFornewInteraction.Text = OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true;
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0.1F;
ThresholdFornewInteraction.Text = OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns
.ThresholdForNewInteraction.ToString(CultureInfo.InvariantCulture);
MaxDailyInteractions.Text = "2";

Expand Down Expand Up @@ -142,7 +142,7 @@ protected override void UpdateSettings()

#region Interactions

OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions =
AllowNewInteractions.Checked;

#endregion
Expand Down Expand Up @@ -257,7 +257,7 @@ private void Coworkers_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnActivities =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnActivities =
float.Parse(InteractionActivities.Text, CultureInfo.InvariantCulture);
InteractionActivities.BackColor = SystemColors.Window;
}
Expand All @@ -276,7 +276,7 @@ private void DeliberateSearch_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnKnowledge =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnKnowledge =
float.Parse(InteractionKnowledge.Text, CultureInfo.InvariantCulture);
InteractionKnowledge.BackColor = SystemColors.Window;
}
Expand All @@ -295,7 +295,7 @@ private void ThresholdForNewInteraction_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction =
float.Parse(ThresholdFornewInteraction.Text, CultureInfo.InvariantCulture);
ThresholdFornewInteraction.BackColor = SystemColors.Window;
}
Expand All @@ -314,7 +314,7 @@ private void DailyInteractions_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions =
byte.Parse(MaxDailyInteractions.Text, CultureInfo.InvariantCulture);
MaxDailyInteractions.BackColor = SystemColors.Window;
}
Expand All @@ -333,7 +333,7 @@ private void InteractionSocialDemographics_TextChanged(object sender, EventArgs
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnSocialDemographics =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnSocialDemographics =
float.Parse(InteractionSocialDemographics.Text, CultureInfo.InvariantCulture);
InteractionSocialDemographics.BackColor = SystemColors.Window;
}
Expand All @@ -352,7 +352,7 @@ private void InteractionBeliefs_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnBeliefs =
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.InteractionsBasedOnBeliefs =
float.Parse(InteractionBeliefs.Text, CultureInfo.InvariantCulture);
InteractionBeliefs.BackColor = SystemColors.Window;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ private void Homophily_CheckedChanged(object sender, EventArgs e)
return;
}

OrganizationEntity.Templates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(
OrganizationEntity.AgentTemplates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(
InteractionStrategy.Homophily);
InteractionActivities.Text = "0";
InteractionBeliefs.Text = "0";
Expand Down
32 changes: 16 additions & 16 deletions Symu examples/SymuGroupAndInteractionTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Symu.Classes.Agents.Models.CognitiveModel;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Classes.Organization;
using Symu.Classes.Scenario;
using Symu.Engine;
Expand Down Expand Up @@ -46,13 +46,13 @@ public void Initialize()
NumberOfSteps = NumberOfSteps
};
_symu.AddScenario(scenario);
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = false;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = false;
}

public void SetInteractionPatterns(InteractionStrategy strategy)
{
_organization.Models.InteractionSphere.SetInteractionPatterns(strategy);
_organization.Templates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(strategy);
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.SetInteractionPatterns(strategy);
}

private int GetNotAcceptedMessages()
Expand All @@ -75,8 +75,8 @@ public void KnowledgeSphereCount(int groupsCount)
SetInteractionPatterns(InteractionStrategy.Knowledge);
_environment.GroupsCount = (byte) groupsCount;
_environment.WorkersCount = 10;
_organization.Templates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true;
_organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 1;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.LimitNumberOfNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 1;
_environment.Knowledge = 1;
_symu.Process();
var links = _environment.WhitePages.Network.NetworkLinks.Count;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void OneGroupsOneMemberTest(int agentCount)
{
_environment.GroupsCount = 0;
_environment.WorkersCount = (byte) agentCount;
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_symu.Process();
Assert.AreEqual(0F, GetNotAcceptedMessages());
Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density);
Expand Down Expand Up @@ -237,8 +237,8 @@ public void TwoGroupsOneMemberTest2()
_environment.GroupsCount = 2;
_environment.WorkersCount = 1;
_environment.Knowledge = 1;
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0;
_symu.Process();
Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density);
Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density);
Expand All @@ -257,8 +257,8 @@ public void TwoGroupsOneMemberTest3()
_environment.WorkersCount = 1;
_environment.Knowledge = 1;
_organization.Models.InteractionSphere.FrequencyOfSphereUpdate = TimeStepType.Daily;
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1;
_symu.Process();
Assert.AreEqual(100F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density);
Assert.AreEqual(0F, _environment.IterationResult.OrganizationFlexibility.Triads.Last().Density);
Expand Down Expand Up @@ -360,9 +360,9 @@ public void NewInteractionWithHomophilyTest(int interactions)
{
_environment.GroupsCount = 2;
_environment.WorkersCount = 3;
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0;
_organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions =
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 0;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions =
(byte) interactions;
_symu.Process();
Assert.AreEqual(40F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density);
Expand All @@ -378,9 +378,9 @@ public void NewInteractionWithHomophily1Test()
{
_environment.GroupsCount = 2;
_environment.WorkersCount = 3;
_organization.Templates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.Templates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1;
_organization.Templates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 5;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.AllowNewInteractions = true;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.ThresholdForNewInteraction = 1;
_organization.AgentTemplates.Human.Cognitive.InteractionPatterns.MaxNumberOfNewInteractions = 5;
_symu.Process();
Assert.AreEqual(100F, _environment.IterationResult.OrganizationFlexibility.Links.Last().Density);
Assert.AreEqual(0, GetNotAcceptedMessages());
Expand Down
16 changes: 8 additions & 8 deletions Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void SetOrganization(OrganizationEntity organization)

base.SetOrganization(organization);

var wiki = new DataBaseEntity(organization.Id, organization.Templates.Email);
var wiki = new DataBaseEntity(organization.Id, organization.Communication.Email);
organization.AddDatabase(wiki);
IterationResult.OrganizationKnowledgeAndBelief.On = true;

Expand All @@ -51,27 +51,27 @@ public override void SetOrganization(OrganizationEntity organization)
public override void SetModelForAgents()
{
base.SetModelForAgents();
WhitePages.Network.NetworkCommunications.Email.CostToSendLevel = GenericLevel.None;
WhitePages.Network.NetworkCommunications.Email.CostToReceiveLevel = GenericLevel.None;
Organization.Communication.Email.CostToSendLevel = GenericLevel.None;
Organization.Communication.Email.CostToReceiveLevel = GenericLevel.None;
WhitePages.Network.AddKnowledge(Knowledge);
Wiki.InitializeKnowledge(Knowledge, 0);

LearnFromSourceAgent = new LearnFromSourceAgent(Organization.NextEntityIndex(), this);
LearnFromSourceAgent.KnowledgeModel.AddKnowledge(Knowledge.Id, KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
LearnByDoingAgent = new LearnByDoingAgent(Organization.NextEntityIndex(), this);
LearnByDoingAgent.KnowledgeModel.AddKnowledge(Knowledge.Id, KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
LearnByAskingAgent = new LearnByAskingAgent(Organization.NextEntityIndex(), this);
LearnByAskingAgent.KnowledgeModel.AddKnowledge(Knowledge.Id, KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
DoesNotLearnAgent = new LearnAgent(Organization.NextEntityIndex(), this);
DoesNotLearnAgent.KnowledgeModel.AddKnowledge(Knowledge.Id, KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
ExpertAgent = new ExpertAgent(Organization.NextEntityIndex(), this);
ExpertAgent.Cognitive.KnowledgeAndBeliefs.HasInitialKnowledge = true;
ExpertAgent.KnowledgeModel.AddKnowledge(Knowledge.Id, KnowledgeLevel.Expert,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.AgentTemplates.Human.Cognitive.InternalCharacteristics);
// CopyTo active link between expert and LearnByAskingAgent to be able to exchange information
WhitePages.Network.NetworkLinks.AddLink(LearnByAskingAgent.Id, ExpertAgent.Id);
}
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class ExpertAgent : Agent
new AgentId(agentKey, ClassKey),
environment)
{
SetCognitive(Environment.Organization.Templates.Human);
SetCognitive(Environment.Organization.AgentTemplates.Human);
Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
}

Expand Down

0 comments on commit 1b40d85

Please sign in to comment.