Skip to content

Commit

Permalink
Finalization SymuBeliefsAndInfluence
Browse files Browse the repository at this point in the history
updating nugets
  • Loading branch information
lmorisse committed May 20, 2020
1 parent 93686a9 commit bf39213
Show file tree
Hide file tree
Showing 89 changed files with 1,446 additions and 1,035 deletions.
24 changes: 19 additions & 5 deletions Symu examples/SymuBeliefsAndInfluence/App.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.5.0" newVersion="1.2.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.5.0" newVersion="1.4.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Licence

// Description: Symu - SymuGroupAndInteraction
// Description: Symu - SymuBeliefsAndInfluence
// Website: https://symu.org
// Copyright: (c) 2020 laurent morisseau
// License : the program is distributed under the terms of the GNU General Public License
Expand All @@ -16,9 +16,7 @@
using SymuEngine.Common;
using SymuEngine.Environment;
using SymuEngine.Messaging.Messages;
using SymuEngine.Repository.Networks.Beliefs;
using SymuEngine.Repository.Networks.Knowledges;
using SymuTools.Math.ProbabilityDistributions;

#endregion

Expand All @@ -40,6 +38,7 @@ public override void SetModelForAgents()
base.SetModelForAgents();

#region Common

Organization.Models.Generator = RandomGenerator.RandomUniform;
Organization.Models.FollowGroupKnowledge = true;
Organization.Models.FollowGroupFlexibility = true;
Expand All @@ -59,15 +58,17 @@ public override void SetModelForAgents()
for (var i = 0; i < KnowledgeCount; i++)
{
// knowledge length of 10 is arbitrary in this example
var knowledge = new Knowledge((ushort)i, i.ToString(), 10);
var knowledge = new Knowledge((ushort) i, i.ToString(), 10);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);
}

#endregion

var agentIds = new List<AgentId>();

#region Influencer

InfluencerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
InfluencerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
InfluencerTemplate.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
Expand All @@ -86,9 +87,11 @@ public override void SetModelForAgents()
Influencers.Add(actor);
agentIds.Add(actor.Id);
}

#endregion

#region worker

WorkerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
WorkerTemplate.Cognitive.InteractionPatterns.IsolationIsRandom = false;
WorkerTemplate.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never;
Expand Down Expand Up @@ -117,9 +120,8 @@ private void SetKnowledge(Agent actor, IReadOnlyList<Knowledge> knowledges)
{
actor.KnowledgeModel.AddKnowledge(knowledges[i].Id,
KnowledgeLevel.FullKnowledge,
Organization.Templates.Human.Cognitive.InternalCharacteristics);
Organization.Templates.Human.Cognitive.InternalCharacteristics);
actor.BeliefsModel.AddBelief(knowledges[i].Id);

}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Symu examples/SymuBeliefsAndInfluence/Classes/InfluencerAgent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Licence

// Description: Symu - SymuGroupAndInteraction
// Description: Symu - SymuBeliefsAndInfluence
// Website: https://symu.org
// Copyright: (c) 2020 laurent morisseau
// License : the program is distributed under the terms of the GNU General Public License
Expand All @@ -10,9 +10,7 @@
#region using directives

using System;
using System.Linq;
using SymuEngine.Classes.Agents;
using SymuEngine.Classes.Task;
using SymuEngine.Environment;
using SymuEngine.Messaging.Messages;
using SymuEngine.Repository;
Expand All @@ -24,6 +22,7 @@ namespace SymuBeliefsAndInfluence.Classes
public sealed class InfluencerAgent : Agent
{
public const byte ClassKey = SymuYellowPages.Actor;

public InfluencerAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey),
environment)
Expand All @@ -50,9 +49,10 @@ public override void ActMessage(Message message)
break;
}
}

/// <summary>
/// Influencer send back its own belief if he can send beliefs
/// which has an impact on the beliefs of the worker if he can receive them
/// Influencer send back its own belief if he can send beliefs
/// which has an impact on the beliefs of the worker if he can receive them
/// </summary>
/// <param name="message"></param>
private void AskBelief(Message message)
Expand Down
19 changes: 11 additions & 8 deletions Symu examples/SymuBeliefsAndInfluence/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Licence

// Description: Symu - SymuGroupAndInteraction
// Description: Symu - SymuBeliefsAndInfluence
// Website: https://symu.org
// Copyright: (c) 2020 laurent morisseau
// License : the program is distributed under the terms of the GNU General Public License
Expand Down Expand Up @@ -28,17 +28,19 @@ namespace SymuBeliefsAndInfluence.Classes
public sealed class PersonAgent : Agent
{
public const byte ClassKey = SymuYellowPages.Actor;
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);

public PersonAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey),
environment)
{
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);

public override void GetNewTasks()
{
var task = new SymuTask(TimeStep.Step)
Expand All @@ -50,7 +52,6 @@ public override void GetNewTasks()
}

/// <summary>
///
/// </summary>
/// <param name="task"></param>
/// <param name="blocker"></param>
Expand All @@ -61,17 +62,19 @@ public override void TryRecoverBlockerIncompleteBelief(SymuTask task, Blocker bl
{
throw new ArgumentNullException(nameof(task));
}

if (blocker is null)
{
throw new ArgumentNullException(nameof(blocker));
}

// RiskAversionThreshold has been exceeded =>
// Worker don't want to do the task, the task is blocked in base method
// Ask advice from influencers
var attachments = new MessageAttachments
{
KnowledgeId = (ushort)blocker.Parameter,
KnowledgeBit = (byte)blocker.Parameter2
KnowledgeId = (ushort) blocker.Parameter,
KnowledgeBit = (byte) blocker.Parameter2
};
SendToMany(Influencers, MessageAction.Ask, SymuYellowPages.Belief, attachments, CommunicationMediums.Email);
}
Expand Down
33 changes: 4 additions & 29 deletions Symu examples/SymuBeliefsAndInfluence/Home.Designer.cs

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

0 comments on commit bf39213

Please sign in to comment.