Skip to content

Commit

Permalink
Refactoring CommunicationTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Jun 5, 2020
1 parent c31989a commit cf2a636
Show file tree
Hide file tree
Showing 90 changed files with 1,969 additions and 1,055 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Refactoring CommunicationTemplates
* Add CyclicalIsolation by [lmorisse](https://github.com/lmorisse)
* Add PromoterTemplate by [lmorisse](https://github.com/lmorisse)
* Add Iterations and Charts in SymuMessageAndTask example by [lmorisse](https://github.com/lmorisse)
* Refactoring BlockerCollection, BlockerResults and TasksResults by [lmorisse](https://github.com/lmorisse)
* Add MessageResults by [lmorisse](https://github.com/lmorisse)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class ExampleEnvironment : SymuEnvironment
public byte KnowledgeCount { get; set; } = 2;
public List<Knowledge> Knowledges { get; private set; }
public List<InfluencerAgent> Influencers { get; } = new List<InfluencerAgent>();
public SimpleHumanTemplate InfluencerTemplate { get; } = new SimpleHumanTemplate();
public PromoterTemplate InfluencerTemplate { get; } = new PromoterTemplate();
public SimpleHumanTemplate WorkerTemplate { get; } = new SimpleHumanTemplate();
public MurphyTask Model { get; } = new MurphyTask();
//public MurphyTask Model { get; } = new MurphyTask();

public override void SetOrganization(OrganizationEntity organization)
{
Expand Down Expand Up @@ -92,14 +92,11 @@ public override void SetModelForAgents()

#region Influencer

InfluencerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
InfluencerTemplate.Cognitive.InteractionPatterns.IsolationCyclicity = Cyclicity.None;
InfluencerTemplate.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
InfluencerTemplate.Cognitive.InteractionPatterns.AllowNewInteractions = false;
InfluencerTemplate.Cognitive.InteractionCharacteristics.PreferredCommunicationMediums =
CommunicationMediums.Email;
InfluencerTemplate.Cognitive.KnowledgeAndBeliefs.HasInitialBelief = true;
InfluencerTemplate.Cognitive.InternalCharacteristics.InfluenceabilityRateMin = 0;
InfluencerTemplate.Cognitive.InternalCharacteristics.InfluenceabilityRateMax = 0;

for (var j = 0; j < InfluencersCount; j++)
{
Expand All @@ -114,7 +111,7 @@ public override void SetModelForAgents()

#region worker

WorkerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
WorkerTemplate.Cognitive.InteractionPatterns.IsolationCyclicity = Cyclicity.None;
WorkerTemplate.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
WorkerTemplate.Cognitive.InteractionPatterns.AllowNewInteractions = false;
WorkerTemplate.Cognitive.InteractionCharacteristics.PreferredCommunicationMediums =
Expand Down
3 changes: 1 addition & 2 deletions Symu examples/SymuBeliefsAndInfluence/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public sealed class PersonAgent : Agent
SetCognitive(Template);
}

private MurphyTask Model => ((ExampleEnvironment) Environment).Model;
private SimpleHumanTemplate Template => ((ExampleEnvironment) Environment).WorkerTemplate;
public List<Knowledge> Knowledges => ((ExampleEnvironment) Environment).Knowledges;
public IEnumerable<AgentId> Influencers => ((ExampleEnvironment) Environment).Influencers.Select(x => x.Id);
Expand All @@ -47,7 +46,7 @@ public override void GetNewTasks()
{
Weight = 1
};
task.SetKnowledgesBits(Model, Knowledges, 1);
task.SetKnowledgesBits(Environment.Organization.Murphies.IncompleteBelief, Knowledges, 1);
Post(task);
}

Expand Down
27 changes: 14 additions & 13 deletions Symu examples/SymuBeliefsAndInfluence/Home.Designer.cs

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

45 changes: 32 additions & 13 deletions Symu examples/SymuBeliefsAndInfluence/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,42 @@ private void LoadSettings()
tbKnowledge.Text = _environment.KnowledgeCount.ToString(CultureInfo.InvariantCulture);

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

#region Influencer

InfluencerBeliefLevel.Items.AddRange(BeliefLevelService.GetNames());
InfluencerBeliefLevel.SelectedItem = BeliefLevelService.GetName(OrganizationEntity.Templates.Human.Cognitive
InfluencerBeliefLevel.SelectedItem = BeliefLevelService.GetName(_environment.InfluencerTemplate.Cognitive
.KnowledgeAndBeliefs.DefaultBeliefLevel);
MinimumBeliefToSendPerBit.Text = OrganizationEntity.Templates.Human.Cognitive.MessageContent
MinimumBeliefToSendPerBit.Text = _environment.InfluencerTemplate.Cognitive.MessageContent
.MinimumBeliefToSendPerBit.ToString(CultureInfo.InvariantCulture);
MinimumNumberOfBitsOfBeliefToSend.Text = OrganizationEntity.Templates.Human.Cognitive.MessageContent
MinimumNumberOfBitsOfBeliefToSend.Text = _environment.InfluencerTemplate.Cognitive.MessageContent
.MinimumNumberOfBitsOfBeliefToSend.ToString(CultureInfo.InvariantCulture);
MaximumNumberOfBitsOfBeliefToSend.Text = OrganizationEntity.Templates.Human.Cognitive.MessageContent
MaximumNumberOfBitsOfBeliefToSend.Text = _environment.InfluencerTemplate.Cognitive.MessageContent
.MaximumNumberOfBitsOfBeliefToSend.ToString(CultureInfo.InvariantCulture);
InfluentialnessMin.Text = OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics
InfluentialnessMin.Text = _environment.InfluencerTemplate.Cognitive.InternalCharacteristics
.InfluentialnessRateMin.ToString(CultureInfo.InvariantCulture);
InfluentialnessMax.Text = OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics
InfluentialnessMax.Text = _environment.InfluencerTemplate.Cognitive.InternalCharacteristics
.InfluentialnessRateMax.ToString(CultureInfo.InvariantCulture);
CanSendBeliefs.Checked = OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanSendBeliefs;
CanSendBeliefs.Checked = _environment.InfluencerTemplate.Cognitive.MessageContent.CanSendBeliefs;

#endregion

#region Worker

MandatoryRatio.Text = _environment.Model.MandatoryRatio.ToString(CultureInfo.InvariantCulture);
MandatoryRatio.Text = OrganizationEntity.Murphies.IncompleteBelief.MandatoryRatio.ToString(CultureInfo.InvariantCulture);
RiskAversion.Text = _environment.WorkerTemplate.Cognitive.InternalCharacteristics.RiskAversionThreshold
.ToString(CultureInfo.InvariantCulture);
BeliefWeight.Items.AddRange(BeliefWeightLevelService.GetNames());
BeliefWeight.SelectedItem =
BeliefWeightLevelService.GetName(OrganizationEntity.Models.ImpactOfBeliefOnTask);
InfluenceabilityMin.Text = OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics
InfluenceabilityMin.Text = _environment.WorkerTemplate.Cognitive.InternalCharacteristics
.InfluenceabilityRateMin.ToString(CultureInfo.InvariantCulture);
InfluenceabilityMax.Text = OrganizationEntity.Templates.Human.Cognitive.InternalCharacteristics
InfluenceabilityMax.Text = _environment.WorkerTemplate.Cognitive.InternalCharacteristics
.InfluenceabilityRateMax.ToString(CultureInfo.InvariantCulture);
CanReceiveBeliefs.Checked = OrganizationEntity.Templates.Human.Cognitive.MessageContent.CanReceiveBeliefs;
CanReceiveBeliefs.Checked = _environment.WorkerTemplate.Cognitive.MessageContent.CanReceiveBeliefs;
HasInitialBeliefs.Checked =
OrganizationEntity.Templates.Human.Cognitive.KnowledgeAndBeliefs.HasInitialBelief;
_environment.WorkerTemplate.Cognitive.KnowledgeAndBeliefs.HasInitialBelief;

#endregion
}
Expand Down Expand Up @@ -386,7 +387,7 @@ private void MandatoryRatio_TextChanged(object sender, EventArgs e)
{
try
{
_environment.Model.MandatoryRatio = float.Parse(MandatoryRatio.Text, CultureInfo.InvariantCulture);
OrganizationEntity.Murphies.IncompleteBelief.MandatoryRatio = float.Parse(MandatoryRatio.Text, CultureInfo.InvariantCulture);
MandatoryRatio.BackColor = SystemColors.Window;
}
catch (FormatException)
Expand Down Expand Up @@ -478,5 +479,23 @@ private void issuesToolStripMenuItem_Click(object sender, EventArgs e)
}

#endregion

private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
OrganizationEntity.Murphies.IncompleteBelief.ThresholdForReacting = float.Parse(ThresholdForReacting.Text, CultureInfo.InvariantCulture);
ThresholdForReacting.BackColor = SystemColors.Window;
}
catch (FormatException)
{
ThresholdForReacting.BackColor = Color.Red;
}
catch (ArgumentOutOfRangeException exception)
{
ThresholdForReacting.BackColor = Color.Red;
MessageBox.Show(exception.Message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:element name="root" msdata:IsDataCopyTo="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
Expand Down
38 changes: 31 additions & 7 deletions Symu examples/SymuBeliefsAndInfluenceTests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void CheckNoChange()
[TestMethod]
public void NoTaskBlockedTest()
{
_environment.Model.MandatoryRatio = 0;
_environment.Organization.Murphies.IncompleteBelief.MandatoryRatio = 0;
_simulation.Process();
CheckNoChange();
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Constants.Tolerance
Expand All @@ -222,8 +222,9 @@ public void NoTaskBlockedTest()
[TestMethod]
public void NoRiskAversionTest()
{
_environment.Model.MandatoryRatio = 1;
_environment.Organization.Murphies.IncompleteBelief.MandatoryRatio = 1;
_environment.WorkerTemplate.Cognitive.InternalCharacteristics.RiskAversionThreshold = 1;
_environment.Organization.Murphies.IncompleteBelief.ThresholdForReacting = 1;
_simulation.Process();
CheckNoChange();
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Constants.Tolerance
Expand All @@ -236,7 +237,7 @@ public void NoRiskAversionTest()
[TestMethod]
public void NoWeightTest()
{
_environment.Model.MandatoryRatio = 1;
_environment.Organization.Murphies.IncompleteBelief.MandatoryRatio = 1;
_environment.WhitePages.Network.NetworkBeliefs.BeliefWeightLevel = BeliefWeightLevel.NoWeight;
_simulation.Process();
CheckNoChange();
Expand All @@ -246,21 +247,44 @@ public void NoWeightTest()
(_environment.Schedule.Step * _environment.WorkersCount);
Assert.AreEqual(100, tasksDoneRatio);
}

/// <summary>
/// Full risk aversion
/// </summary>
[TestMethod]
public void FullWeightTest()
{
_environment.Model.MandatoryRatio = 1;
_environment.Organization.Murphies.IncompleteBelief.MandatoryRatio = 1;
_environment.WorkerTemplate.Cognitive.InternalCharacteristics.RiskAversionThreshold =
0; // Full risk aversion
0;
_environment.Organization.Murphies.IncompleteBelief.ThresholdForReacting = 1;
_environment.WhitePages.Network.NetworkBeliefs.BeliefWeightLevel = BeliefWeightLevel.FullWeight;
_simulation.Process();
CheckNoChange();
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Constants.Tolerance
? 0
: _environment.IterationResult.Tasks.Done * 100 /
(_environment.Schedule.Step * _environment.WorkersCount);
Assert.AreNotEqual(100, tasksDoneRatio);
Assert.AreEqual(0, tasksDoneRatio);
Assert.AreEqual(_environment.Schedule.Step * _environment.WorkersCount, _environment.IterationResult.Tasks.Cancelled);
}
/// <summary>
/// No risk aversion
/// </summary>
[TestMethod]
public void FullWeightTest1()
{
_environment.Organization.Murphies.IncompleteBelief.MandatoryRatio = 1;
_environment.WorkerTemplate.Cognitive.InternalCharacteristics.RiskAversionThreshold =
1;
_environment.Organization.Murphies.IncompleteBelief.ThresholdForReacting = 1;
_environment.WhitePages.Network.NetworkBeliefs.BeliefWeightLevel = BeliefWeightLevel.FullWeight;
_simulation.Process();
CheckNoChange();
var tasksDoneRatio = _environment.Schedule.Step * _environment.WorkersCount < Constants.Tolerance
? 0
: _environment.IterationResult.Tasks.Done * 100 /
(_environment.Schedule.Step * _environment.WorkersCount);
Assert.AreEqual(100, tasksDoneRatio);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void SetOrganization(OrganizationEntity organization)

base.SetOrganization(organization);

Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationIsRandom = false;
Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationCyclicity = Cyclicity.None;
Organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
Organization.Models.InteractionSphere.SphereUpdateOverTime = true;
Organization.Models.InteractionSphere.On = true;
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuGroupAndInteraction/Home.resx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:element name="root" msdata:IsDataCopyTo="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:element name="root" msdata:IsDataCopyTo="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
Expand Down

0 comments on commit cf2a636

Please sign in to comment.