-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
260 changed files
with
6,650 additions
and
2,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<configuration> | ||
<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.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> | ||
</configuration> |
116 changes: 116 additions & 0 deletions
116
Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#region Licence | ||
|
||
// Description: Symu - SymuGroupAndInteraction | ||
// Website: https://symu.org | ||
// Copyright: (c) 2020 laurent morisseau | ||
// License : the program is distributed under the terms of the GNU General Public License | ||
|
||
#endregion | ||
|
||
#region using directives | ||
|
||
using System.Collections.Generic; | ||
using SymuEngine.Classes.Agents; | ||
using SymuEngine.Common; | ||
using SymuEngine.Environment; | ||
using SymuEngine.Repository.Networks.Knowledges; | ||
using SymuTools.Math.ProbabilityDistributions; | ||
|
||
#endregion | ||
|
||
namespace SymuGroupAndInteraction.Classes | ||
{ | ||
public class ExampleEnvironment : SymuEnvironment | ||
{ | ||
public byte GroupsCount { get; set; } = 2; | ||
public byte WorkersCount { get; set; } = 5; | ||
public byte Knowledge { get; set; } = 0; | ||
public byte Activities { get; set; } = 0; | ||
public KnowledgeLevel KnowledgeLevel { get; set; } = KnowledgeLevel.FullKnowledge; | ||
|
||
public override void SetModelForAgents() | ||
{ | ||
base.SetModelForAgents(); | ||
Organization.Templates.Human.Cognitive.InteractionPatterns.IsolationIsRandom = false; | ||
Organization.Templates.Human.Cognitive.InteractionPatterns.AgentCanBeIsolated = Frequency.Never; | ||
Organization.Models.FollowGroupFlexibility = true; | ||
Organization.Models.InteractionSphere.SphereUpdateOverTime = true; | ||
Organization.Models.InteractionSphere.On = true; | ||
var knowledges = new List<Knowledge>(); | ||
var activities = new List<string>(); | ||
for (var i = 0; i < GroupsCount; i++) | ||
{ | ||
// knowledge length of 10 is arbitrary in this example | ||
var knowledge = new Knowledge((ushort) i, i.ToString(), 10); | ||
WhitePages.Network.AddKnowledge(knowledge); | ||
knowledges.Add(knowledge); | ||
activities.Add(i.ToString()); | ||
//Beliefs are created based on knowledge | ||
} | ||
|
||
for (var i = 0; i < GroupsCount; i++) | ||
{ | ||
var group = new GroupAgent(Organization.NextEntityIndex(), this); | ||
|
||
for (var j = 0; j < WorkersCount; j++) | ||
{ | ||
var actor = new PersonAgent(Organization.NextEntityIndex(), this) | ||
{ | ||
GroupId = group.Id | ||
}; | ||
WhitePages.Network.AddMemberToGroup(actor.Id, 100, group.Id); | ||
//Beliefs are added with knowledge | ||
SetKnowledge(actor, knowledges, i); | ||
SetActivity(actor.Id, activities, i, group.Id); | ||
} | ||
} | ||
} | ||
|
||
private void SetKnowledge(Agent actor, IReadOnlyList<Knowledge> knowledges, int i) | ||
{ | ||
switch (Knowledge) | ||
{ | ||
case 0: | ||
// same Knowledge for all | ||
actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[0], | ||
KnowledgeLevel, | ||
Organization.Templates.Human.Cognitive.InternalCharacteristics); | ||
|
||
break; | ||
case 1: | ||
// Knowledge is by group | ||
actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[i], | ||
KnowledgeLevel, | ||
Organization.Templates.Human.Cognitive.InternalCharacteristics); | ||
break; | ||
case 2: | ||
// Knowledge is randomly defined for agentId | ||
var index = DiscreteUniform.Sample(0, GroupsCount - 1); | ||
actor.Cognitive.KnowledgeAndBeliefs.AddKnowledge(knowledges[index], | ||
KnowledgeLevel, | ||
Organization.Templates.Human.Cognitive.InternalCharacteristics); | ||
break; | ||
} | ||
} | ||
|
||
private void SetActivity(AgentId agentId, IReadOnlyList<string> activities, int i, AgentId groupId) | ||
{ | ||
switch (Activities) | ||
{ | ||
case 0: | ||
// same activity for all | ||
WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[0], groupId); | ||
break; | ||
case 1: | ||
// Activity is by group | ||
WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[i], groupId); | ||
break; | ||
case 2: | ||
// Activity is randomly defined for agentId | ||
var index = DiscreteUniform.Sample(0, GroupsCount - 1); | ||
WhitePages.Network.NetworkActivities.AddActivity(agentId, activities[index], groupId); | ||
break; | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#region Licence | ||
|
||
// Description: Symu - SymuGroupAndInteraction | ||
// Website: https://symu.org | ||
// Copyright: (c) 2020 laurent morisseau | ||
// License : the program is distributed under the terms of the GNU General Public License | ||
|
||
#endregion | ||
|
||
#region using directives | ||
|
||
using SymuEngine.Classes.Agents; | ||
using SymuEngine.Environment; | ||
|
||
#endregion | ||
|
||
namespace SymuGroupAndInteraction.Classes | ||
{ | ||
public sealed class GroupAgent : Agent | ||
{ | ||
public const byte ClassKey = 1; | ||
|
||
public GroupAgent(ushort agentKey, SymuEnvironment environment) : base( | ||
new AgentId(agentKey, ClassKey), | ||
environment) | ||
{ | ||
SetCognitive(Environment.Organization.Templates.Standard); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#region Licence | ||
|
||
// Description: Symu - SymuGroupAndInteraction | ||
// Website: https://symu.org | ||
// Copyright: (c) 2020 laurent morisseau | ||
// License : the program is distributed under the terms of the GNU General Public License | ||
|
||
#endregion | ||
|
||
#region using directives | ||
|
||
using System; | ||
using SymuEngine.Classes.Agents; | ||
using SymuEngine.Environment; | ||
using SymuEngine.Messaging.Messages; | ||
using SymuEngine.Repository; | ||
|
||
#endregion | ||
|
||
namespace SymuGroupAndInteraction.Classes | ||
{ | ||
public sealed class PersonAgent : Agent | ||
{ | ||
public const byte ClassKey = SymuYellowPages.Actor; | ||
|
||
public PersonAgent(ushort agentKey, SymuEnvironment environment) : base( | ||
new AgentId(agentKey, ClassKey), | ||
environment) | ||
{ | ||
SetCognitive(Environment.Organization.Templates.Human); | ||
// Communication medium | ||
Cognitive.InteractionCharacteristics.PreferredCommunicationMediums = | ||
CommunicationMediums.FaceToFace; | ||
} | ||
|
||
/// <summary> | ||
/// Agent is member of a group | ||
/// </summary> | ||
public AgentId GroupId { get; set; } | ||
|
||
|
||
protected override void ActClassKey(Message message) | ||
{ | ||
if (message is null) | ||
{ | ||
throw new ArgumentNullException(nameof(message)); | ||
} | ||
|
||
base.ActClassKey(message); | ||
switch (message.Subject) | ||
{ | ||
case SymuYellowPages.Actor: | ||
ActActor(message); | ||
break; | ||
} | ||
} | ||
|
||
private void ActActor(Message message) | ||
{ | ||
switch (message.Action) | ||
{ | ||
case MessageAction.Ask: | ||
AskActor(message); | ||
break; | ||
} | ||
} | ||
|
||
private void AskActor(Message message) | ||
{ | ||
// New interaction has already been accepted | ||
// Let's reply positively | ||
var reply = Message.ReplyMessage(message); | ||
Send(reply); | ||
} | ||
|
||
public override void ActEndOfDay() | ||
{ | ||
base.ActEndOfDay(); | ||
// Time for a coffee break and have interaction with other agents | ||
Send(GroupId, MessageAction.Stop, SymuYellowPages.WorkingDay, CommunicationMediums.FaceToFace); | ||
} | ||
} | ||
} |
Oops, something went wrong.