Skip to content

Commit

Permalink
Major refactoring to prepare symu.DNA
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Oct 6, 2020
1 parent 9bec19d commit d883bb6
Show file tree
Hide file tree
Showing 177 changed files with 5,085 additions and 4,801 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SymuTools refactored in Symu.Common solution
* Prepare Symu.org for Symu.DNA project
** Extract interfaces from metanetwork
** Move Networks to Symu.DNA repo
** Move networks to Symu.DNA

## 0.91 [](https://github.com/lmorisse/symu/compare/v0.9.1..v0.9.0) by [lmorisse](https://github.com/lmorisse)
* Split Agent into ReactiveAgent and CognitiveAgent
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ organization theory, social networks, socio-cultural environment, information di
With our **academic program**, we will first implement models that you want to use for you.

## Getting Started
The main project is [Symu](https://github.com/lmorisse/Symu/tree/master/Symu%20source%20code/Symu). This is the framework you'll use to build your own application in batch. You can use [SymuForm](https://github.com/lmorisse/Symu/tree/master/Symu%20source%20code/SymuForm) for a GUI mode.
The main project is [Symu](https://github.com/lmorisse/Symu.org/tree/master/SourceCode/Symu). This is the framework you'll use to build your own application in batch. You can use [SymuForm](https://github.com/lmorisse/Symu/tree/master/Symu%20source%20code/SymuForm) for a GUI mode.

### Installing

Symu works only on Windows for the moment.
Symu works only on Windows when you use SymuForm. Otherwise, it can be used on Linux, but it have not been tested.

### Building

Symu is built upon different repositories. We don't use git submodules. So that, to build Symu and its examples solutions, you'll need to check the dependencies manually.

#### Symu dependencies
To build Symu you have to add the Symu.Common.dll as a dependency. You find this library in the [Symu.Common](https://github.com/lmorisse/Symu.Common/releases/latest) repository.
To build Symu examples, you'll need to add Symu.dll, Symu.Forms.dll and Symu.Common.dll as dependencies.
To build Symu you have to add the Symu.Common.dll and Symu.DNA.dll as dependencies. You find this library in the [Symu.Common](https://github.com/lmorisse/Symu.Common/releases/latest) and [Symu.DNA](https://github.com/lmorisse/Symu.DNA/releases/latest) repositories.
To build Symu examples, you'll need to add Symu.dll, Symu.Forms.dll, Symu.Common.dll and Symu.DNA.dll as dependencies.

#### External dependencies
* [Math.net](https://www.math.net/)
Expand Down
5 changes: 4 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# ROADMAP

## FRAMEWORK
* Using social, organizational and dynamic network analysis techniques
* App based on the framework for agnostic organizations
* Implement models :
** Transactional memory
** Send/receive/follow referral
** Risk aversion

## GUI Mode
* Application to use this framework

## EXAMPLES
* Belief and influence

## TECHNICAL
* Persistance XML files
86 changes: 0 additions & 86 deletions SourceCode/Symu/Classes/Agents/AgentEntity.cs

This file was deleted.

2 changes: 1 addition & 1 deletion SourceCode/Symu/Classes/Agents/CognitiveAgent.Act.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private SymuTask ConvertMessageIntoTask(Message message)
TimeToLive = communication.TimeToLive,
Parent = message,
Weight = Environment.Organization.Communication.TimeSpent(message.Medium, false,
Environment.Organization.Models.RandomLevelValue),
Environment.RandomLevelValue),
Assigned = message.Receiver
//todo maybe define a specific KeyActivity to follow the time spent on messaging?
};
Expand Down
18 changes: 10 additions & 8 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
using System.Collections.Generic;
using Symu.Classes.Task.Manager;
using Symu.Common;
using Symu.Common.Interfaces.Agent;
using Symu.Common.Interfaces;
using Symu.Common.Math.ProbabilityDistributions;
using Symu.DNA.Edges;
using Symu.Messaging.Manager;
using Symu.Messaging.Messages;
using Symu.Repository.Entity;
using Symu.Repository.Edges;

#endregion

Expand Down Expand Up @@ -116,7 +117,7 @@ public bool AcceptNewInteraction(IAgentId senderId)
return true;
}

if (Environment.WhitePages.MetaNetwork.AgentAgent.HasActiveInteraction(AgentId, senderId))
if (Environment.Organization.MetaNetwork.ActorActor.HasActiveInteraction(AgentId, senderId))
{
return true;
}
Expand Down Expand Up @@ -144,8 +145,8 @@ public bool AcceptNewInteraction(IAgentId senderId)
if (Environment.Organization.Models.InteractionSphere.SphereUpdateOverTime)
{
// Message.Sender is now part of agent interaction sphere
var interaction = new AgentAgent(AgentId, senderId);
Environment.WhitePages.MetaNetwork.AgentAgent.AddInteraction(interaction);
var interaction = new ActorActor(AgentId, senderId);
Environment.Organization.MetaNetwork.ActorActor.Add(interaction);
}

return true;
Expand All @@ -169,7 +170,7 @@ public override void OnBeforeSendMessage(Message message)
// Impact of the Communication channels on the remaining capacity
var cost =
Environment.Organization.Communication.TimeSpent(message.Medium, true,
Environment.Organization.Models.RandomLevelValue);
Environment.RandomLevelValue);
Capacity.Decrement(cost);
}

Expand Down Expand Up @@ -240,7 +241,8 @@ public void LearnBeliefsFromPostMessage(Message message)
return;
}

InfluenceModel.BeInfluenced(message.Attachments.KnowledgeId, message.Attachments.BeliefBits,
var beliefId = BeliefsModel.GetBeliefIdFromKnowledgeId(message.Attachments.KnowledgeId);
InfluenceModel.BeInfluenced(beliefId, message.Attachments.BeliefBits,
message.Sender, Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel);
}

Expand Down Expand Up @@ -317,7 +319,7 @@ public override void Reply(Message message, bool delayed, ushort delay)
Environment.Organization.Communication.TemplateFromChannel(message.Medium);
ma.KnowledgeBits = KnowledgeModel.FilterKnowledgeToSend(ma.KnowledgeId, ma.KnowledgeBit, communication,
Schedule.Step, out var knowledgeIndexToSend);
ma.BeliefBits = BeliefsModel.FilterBeliefToSend(ma.KnowledgeId, ma.KnowledgeBit, communication);
ma.BeliefBits = BeliefsModel.FilterBeliefToSendFromKnowledgeId(ma.KnowledgeId, ma.KnowledgeBit, communication);
// The agent is asked for his knowledge, so he can't forget it
if (ma.KnowledgeBits != null)
{
Expand Down
39 changes: 21 additions & 18 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Murphies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
using Symu.Classes.Murphies;
using Symu.Classes.Task;
using Symu.Common;
using Symu.Common.Interfaces.Entity;
using Symu.DNA.Networks.TwoModesNetworks.Sphere;
using Symu.Common.Interfaces;
using Symu.DNA.Entities;
using Symu.DNA.GraphNetworks.TwoModesNetworks.Sphere;
using Symu.Messaging.Messages;
using Symu.Repository;
using Symu.Repository.Entity;
using Symu.Results.Blocker;
using static Symu.Common.Constants;

Expand Down Expand Up @@ -161,7 +161,7 @@ public virtual void ReplyHelp(Message message)
break;
}

ReplyHelpIncomplete(task, blocker, message.Medium, message.Sender.Equals(SymuYellowPages.Actor));
ReplyHelpIncomplete(task, blocker, message.Medium, message.Sender.Equals(ActorEntity.ClassId));
// specifics behaviour
switch (blocker.Type)
{
Expand Down Expand Up @@ -373,7 +373,7 @@ public void CheckBlockerIncompleteKnowledge(SymuTask task)
/// </summary>
/// <param name="task"></param>
/// <param name="knowledgeId"></param>
protected virtual void CheckBlockerIncompleteKnowledge(SymuTask task, IId knowledgeId)
protected virtual void CheckBlockerIncompleteKnowledge(SymuTask task, IAgentId knowledgeId)
{
if (task == null)
{
Expand Down Expand Up @@ -420,7 +420,7 @@ protected virtual void CheckBlockerIncompleteKnowledge(SymuTask task, IId knowle
/// <param name="knowledgeBit"></param>
/// <param name="blocker"></param>
/// <param name="resolution">guessing or searched</param>
public void RecoverBlockerIncompleteKnowledgeByGuessing(SymuTask task, Blocker blocker, IId knowledgeId,
public void RecoverBlockerIncompleteKnowledgeByGuessing(SymuTask task, Blocker blocker, IAgentId knowledgeId,
byte knowledgeBit, BlockerResolution resolution)
{
if (task is null)
Expand Down Expand Up @@ -472,7 +472,7 @@ public virtual void TryRecoverBlockerIncompleteKnowledge(SymuTask task, Blocker
throw new ArgumentNullException(nameof(blocker));
}

var knowledgeId = (IId) blocker.Parameter;
var knowledgeId = (IAgentId) blocker.Parameter;
var knowledgeBit = (byte) blocker.Parameter2;
// Check if he has the right to receive knowledge from others agents
if (!Cognitive.MessageContent.CanReceiveKnowledge)
Expand Down Expand Up @@ -532,7 +532,7 @@ public virtual void TryRecoverBlockerIncompleteKnowledge(SymuTask task, Blocker
/// <param name="knowledgeId"></param>
/// <param name="knowledgeBit"></param>
public virtual void TryRecoverBlockerIncompleteKnowledgeExternally(SymuTask task, Blocker blocker,
IId knowledgeId,
IAgentId knowledgeId,
byte knowledgeBit)
{
RecoverBlockerIncompleteKnowledgeByGuessing(task, blocker, knowledgeId, knowledgeBit,
Expand All @@ -551,7 +551,7 @@ public void ReplyHelpIncompleteKnowledge(SymuTask task, Blocker blocker)
throw new ArgumentNullException(nameof(blocker));
}

task.KnowledgesBits.RemoveFirstMandatory((IId) blocker.Parameter);
task.KnowledgesBits.RemoveFirstMandatory((IAgentId) blocker.Parameter);
}

#endregion
Expand Down Expand Up @@ -593,7 +593,7 @@ public void CheckBlockerIncompleteBeliefs(SymuTask task)
/// Prevent the agent from acting on a particular belief
/// Task may be blocked if it is the case
/// </summary>
public void CheckBlockerIncompleteBelief(SymuTask task, IId knowledgeId)
public void CheckBlockerIncompleteBelief(SymuTask task, IAgentId knowledgeId)
{
if (task is null)
{
Expand All @@ -611,8 +611,9 @@ public void CheckBlockerIncompleteBelief(SymuTask task, IId knowledgeId)
byte mandatoryIndex = 0;
byte requiredIndex = 0;

var belief = Environment.WhitePages.MetaNetwork.Belief.Get<Belief>(knowledgeId);
Environment.Organization.Murphies.IncompleteBelief.CheckBelief(belief, taskBits, BeliefsModel.Beliefs,
var belief = BeliefsModel.GetBeliefFromKnowledgeId(knowledgeId);
var actorBelief = BeliefsModel.GetActorBelief(belief.EntityId);
Environment.Organization.Murphies.IncompleteBelief.CheckBelief(belief, taskBits, actorBelief,
ref mandatoryScore, ref requiredScore,
ref mandatoryIndex, ref requiredIndex);
if (Math.Abs(mandatoryScore + requiredScore) < Tolerance)
Expand All @@ -639,7 +640,7 @@ public void CheckBlockerIncompleteBelief(SymuTask task, IId knowledgeId)
/// <param name="mandatoryIndex"></param>
/// <param name="requiredIndex"></param>
/// <exception cref="ArgumentNullException"></exception>
protected virtual void CheckBlockerIncompleteBelief(SymuTask task, IId knowledgeId, float mandatoryScore,
protected virtual void CheckBlockerIncompleteBelief(SymuTask task, IAgentId knowledgeId, float mandatoryScore,
float requiredScore, byte mandatoryIndex, byte requiredIndex)
{
if (task == null)
Expand All @@ -664,7 +665,7 @@ public void CheckBlockerIncompleteBelief(SymuTask task, IId knowledgeId)
/// Prevent the agent from acting on a particular belief
/// Task may be blocked if it is the case
/// </summary>
public void CheckRiskAversion(SymuTask task, IId knowledgeId)
public void CheckRiskAversion(SymuTask task, IAgentId knowledgeId)
{
if (task is null)
{
Expand All @@ -680,8 +681,9 @@ public void CheckRiskAversion(SymuTask task, IId knowledgeId)
float mandatoryScore = 0;
byte mandatoryIndex = 0;

var belief = Environment.WhitePages.MetaNetwork.Belief.Get<Belief>(knowledgeId);
MurphyIncompleteBelief.CheckRiskAversion(belief, taskBits, BeliefsModel.Beliefs, ref mandatoryScore,
var belief = BeliefsModel.GetBeliefFromKnowledgeId(knowledgeId);
var actorBelief = BeliefsModel.GetActorBelief(knowledgeId);
MurphyIncompleteBelief.CheckRiskAversion(belief, taskBits, actorBelief, ref mandatoryScore,
ref mandatoryIndex, -Cognitive.InternalCharacteristics.RiskAversionValue());
if (!(mandatoryScore <= -Cognitive.InternalCharacteristics.RiskAversionValue()))
{
Expand Down Expand Up @@ -732,7 +734,7 @@ public virtual void TryRecoverBlockerIncompleteBelief(SymuTask task, Blocker blo
}

var murphy = Environment.Organization.Murphies.IncompleteBelief;
var knowledgeId = (IId) blocker.Parameter;
var knowledgeId = (IAgentId) blocker.Parameter;
var knowledgeBit = (byte) blocker.Parameter2;

var teammates = GetAgentIdsForInteractions(InteractionStrategy.Beliefs).ToList();
Expand Down Expand Up @@ -803,8 +805,9 @@ public void RecoverBlockerIncompleteBeliefByGuessing(SymuTask task, Blocker bloc
return;
}

var beliefId = (IId) blocker.Parameter;
var knowledgeId = (IAgentId) blocker.Parameter;
var beliefBit = (byte) blocker.Parameter2;
var beliefId = BeliefsModel.GetBeliefIdFromKnowledgeId(knowledgeId);
InfluenceModel.ReinforcementByDoing(beliefId, beliefBit, Cognitive.KnowledgeAndBeliefs.DefaultBeliefLevel);
}

Expand Down
11 changes: 6 additions & 5 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Tasking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
using Symu.Classes.Agents.Models;
using Symu.Classes.Task;
using Symu.Common.Classes;
using Symu.Common.Interfaces.Entity;
using Symu.Common.Interfaces;

using Symu.Environment;
using Symu.Messaging.Messages;
using static Symu.Common.Constants;
Expand Down Expand Up @@ -212,7 +213,7 @@ public virtual void SwitchingContextModel()
/// Key => step
/// Value => time spent
/// </summary>
public Dictionary<IId, float> TimeSpent { get; } = new Dictionary<IId, float>();
public Dictionary<IAgentId, float> TimeSpent { get; } = new Dictionary<IAgentId, float>();

/// <summary>
/// Impact of the Communication channels on the time spent
Expand All @@ -223,7 +224,7 @@ public virtual void SwitchingContextModel()
/// <param name="send">If set, it is an ask help task, otherwise it is a reply help task</param>
/// <remarks>Impact on capacity is done in OnBeforeSendMessage and OnAfterPostMessage</remarks>
public void ImpactOfTheCommunicationMediumOnTimeSpent(CommunicationMediums medium, bool send,
IId keyActivity)
IAgentId keyActivity)
{
if (keyActivity == null || keyActivity.IsNull)
{
Expand All @@ -232,7 +233,7 @@ public virtual void SwitchingContextModel()

var impact =
Environment.Organization.Communication.TimeSpent(medium, send,
Environment.Organization.Models.RandomLevelValue);
Environment.RandomLevelValue);
AddTimeSpent(keyActivity, impact);
}

Expand All @@ -241,7 +242,7 @@ public virtual void SwitchingContextModel()
/// </summary>
/// <param name="keyActivity"></param>
/// <param name="timeSpent"></param>
public void AddTimeSpent(IId keyActivity, float timeSpent)
public void AddTimeSpent(IAgentId keyActivity, float timeSpent)
{
if (keyActivity == null)
{
Expand Down

0 comments on commit d883bb6

Please sign in to comment.