Skip to content

Commit

Permalink
Add InfluenceModel, LearningModel
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed May 18, 2020
1 parent 8c4a77c commit e6fb447
Show file tree
Hide file tree
Showing 63 changed files with 1,238 additions and 931 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

using System.Collections.Generic;
using SymuEngine.Classes.Agents;
using SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Agents.Models.Templates;
using SymuEngine.Classes.Task;
using SymuEngine.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System;
using System.Linq;
using SymuEngine.Classes.Agents;
using SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Task;
using SymuEngine.Environment;
using SymuEngine.Messaging.Messages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Collections.Generic;
using System.Linq;
using SymuEngine.Classes.Agents;
using SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Agents.Models.Templates;
using SymuEngine.Classes.Task;
using SymuEngine.Environment;
Expand Down
81 changes: 59 additions & 22 deletions Symu examples/SymuBeliefsAndInfluence/Home.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 29 additions & 2 deletions Symu examples/SymuBeliefsAndInfluence/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ private void LoadSettings()
{
DisplayButtons();

OrganizationEntity.Models.Influence.On = true;
OrganizationEntity.Models.Influence.RateOfAgentsOn = 1;

InfluenceModel.Checked = OrganizationEntity.Models.Influence.On;
RateOfAgentsOn.Text = OrganizationEntity.Models.Influence.RateOfAgentsOn.ToString();

tbWorkers.Text = _environment.WorkersCount.ToString(CultureInfo.InvariantCulture);
tbInfluencers.Text = _environment.InfluencersCount.ToString(CultureInfo.InvariantCulture);
tbKnowledge.Text = _environment.KnowledgeCount.ToString(CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -90,11 +96,14 @@ protected override void OnStopped()

private void Button1_Click(object sender, EventArgs e)
{

OrganizationEntity.Models.Influence.On = InfluenceModel.Checked;

#region influencer
_environment.InfluencerTemplate.Cognitive.KnowledgeAndBeliefs.HasBelief = HasBeliefs.Checked;
_environment.InfluencerTemplate.Cognitive.MessageContent.CanSendBeliefs = CanSendBeliefs.Checked;
_environment.InfluencerTemplate.Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel= BeliefLevelService.GetValue(InfluencerBeliefLevel.SelectedItem.ToString());

_environment.InfluencerTemplate.Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel =
BeliefLevelService.GetValue(InfluencerBeliefLevel.SelectedItem.ToString());
#endregion

#region Worker
Expand Down Expand Up @@ -418,5 +427,23 @@ private void MandatoryRatio_TextChanged(object sender, EventArgs e)
MessageBox.Show(exception.Message);
}
}

private void RateOfAgentsOn_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Models.Influence.RateOfAgentsOn = float.Parse(RateOfAgentsOn.Text);
RateOfAgentsOn.BackColor = SystemColors.Window;
}
catch (FormatException)
{
RateOfAgentsOn.BackColor = Color.Red;
}
catch (ArgumentOutOfRangeException exception)
{
RateOfAgentsOn.BackColor = Color.Red;
MessageBox.Show(exception.Message);
}
}
}
}
3 changes: 2 additions & 1 deletion Symu examples/SymuBeliefsAndInfluence/Home.resx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
* Workers performing tasks according to their beliefs, asking advice from influencers if necessary
* Influencers with string beliefs trying to influence workers

Beliefs have an impact on different parameters : perform tasks, modify the sphere of interaction, agents beliefs.</value>
Beliefs and influence model have an impact on different parameters :
perform tasks, modify the sphere of interaction, agents beliefs.</value>
</data>
</root>
23 changes: 22 additions & 1 deletion Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SymuBeliefsAndInfluence.Classes;
using SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Organization;
using SymuEngine.Classes.Scenario;
using SymuEngine.Common;
Expand Down Expand Up @@ -41,6 +40,8 @@ public class IntegrationTests
[TestInitialize]
public void Initialize()
{
_organization.Models.Influence.On = true;
_organization.Models.Influence.RateOfAgentsOn = 1;
_environment.SetOrganization(_organization);
_simulation.SetEnvironment(_environment);
var scenario = new TimeStepScenario(_environment)
Expand Down Expand Up @@ -74,6 +75,26 @@ public void HasBeliefsTest()
Assert.AreEqual(100, _environment.IterationResult.OrganizationFlexibility.Triads.First().Density);
}
/// <summary>
/// Influence model off
/// </summary>
[TestMethod]
public void InfluenceModelTest()
{
_environment.Organization.Models.Influence.On = false;
_simulation.Process();
CheckNoChange();
}
/// <summary>
/// Influence model on && rate of agents = 0
/// </summary>
[TestMethod]
public void InfluenceModelTest1()
{
_environment.Organization.Models.Influence.RateOfAgentsOn= 0;
_simulation.Process();
CheckNoChange();
}
/// <summary>
/// No Influencers
/// </summary>
[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuGroupAndInteraction/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Agents.Models.CognitiveModel;
using SymuEngine.Classes.Scenario;
using SymuEngine.Common;
using SymuEngine.Engine.Form;
Expand Down
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 SymuEngine.Classes.Agents.Models.CognitiveArchitecture;
using SymuEngine.Classes.Agents.Models.CognitiveModel;
using SymuEngine.Classes.Organization;
using SymuEngine.Classes.Scenario;
using SymuEngine.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#region using directives

using System.Linq;
using SymuEngine.Common;
using SymuEngine.Environment;
using SymuEngine.Repository.Networks.Databases;
using SymuEngine.Repository.Networks.Knowledges;

#endregion
Expand All @@ -26,13 +28,16 @@ public class ExampleEnvironment : SymuEnvironment
public ExpertAgent ExpertAgent { get; private set; }
public Knowledge Knowledge { get; set; }
public KnowledgeLevel KnowledgeLevel { get; set; }
public Database Wiki => WhitePages.Network.NetworkDatabases.Repository.List.First();

public override void SetModelForAgents()
{
base.SetModelForAgents();
WhitePages.Network.NetworkCommunications.Email.CostToSendLevel = GenericLevel.None;
WhitePages.Network.NetworkCommunications.Email.CostToReceiveLevel = GenericLevel.None;
WhitePages.Network.AddKnowledge(Knowledge);
Wiki.InitializeKnowledge(Knowledge, 0);

LearnFromSourceAgent = new LearnFromSourceAgent(Organization.NextEntityIndex(), this);
LearnFromSourceAgent.Cognitive.KnowledgeAndBeliefs.AddKnowledge(Knowledge, KnowledgeLevel,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ protected override void AfterSetTaskDone(object sender, TaskEventArgs e)
}

// Agent is learning
var realLearning = Cognitive.TasksAndPerformance.LearnByDoing(Knowledge.Id, knowledgeBit,
Cognitive.InternalCharacteristics, TimeStep.Step);
var realLearning = LearningModel.LearnByDoing(Knowledge.Id, knowledgeBit, TimeStep.Step);
// the knowledge is stored in a wiki
Wiki.StoreKnowledge(Knowledge.Id, knowledgeBit, realLearning, TimeStep.Step);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected override void AfterSetTaskDone(object sender, TaskEventArgs e)
bits.InitializeWith0(Knowledge.Length);
// The source has the maximum knowledge bit
bits.SetBit(knowledgeBit, 1);
Cognitive.TasksAndPerformance.Learn(Knowledge.Id, bits,
Environment.Organization.Templates.Email.MaxRateLearnable, Cognitive.InternalCharacteristics,
LearningModel.Learn(Knowledge.Id, bits,
Environment.Organization.Templates.Email.MaxRateLearnable,
TimeStep.Step);
// the information learned is stored in a wiki
// not the total knowledge of the agent, it is tacit knowledge for the agent
Expand Down
6 changes: 3 additions & 3 deletions Symu examples/SymuLearnAndForget/Home.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e6fb447

Please sign in to comment.