Skip to content

Commit

Permalink
Update Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Jul 4, 2020
1 parent 559a37e commit 3fceb33
Show file tree
Hide file tree
Showing 37 changed files with 191 additions and 116 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Remove InteractionSphereModel.FrequencyOfSphereUpdate
* Schedule Bug fixe
* AgentEntity.Parent is now an AgentId

## 0.8.0 [](https://github.com/lmorisse/symu/compare/v0.8.0..v0.7.0) by [lmorisse](https://github.com/lmorisse)
* Refactoring IterationResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override void SetOrganization(OrganizationEntity organization)
}

/// <summary>
/// Add Organization knowledge
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
Expand All @@ -79,7 +79,7 @@ public override void AddOrganizationKnowledges()
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);
Organization.AddKnowledge(knowledge);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public override void SetOrganization(OrganizationEntity organization)
}

/// <summary>
/// Add Organization knowledge
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.AddOrganizationKnowledges();
base.AddOrganizationKnowledges();
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);
var knowledge = new Knowledge((ushort) i, i.ToString(), 10);
Organization.AddKnowledge(knowledge);
_activities.Add(i.ToString());
//Beliefs are created based on knowledge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Symu.Classes.Organization;
using Symu.Classes.Scenario;
using Symu.Engine;
using Symu.Environment;
using Symu.Repository.Networks.Knowledges;
using SymuGroupAndInteraction.Classes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void SetOrganization(OrganizationEntity organization)
}

/// <summary>
/// Add Organization knowledge
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
Expand All @@ -59,7 +59,7 @@ public override void AddOrganizationKnowledges()
}

/// <summary>
/// Add Organization database
/// Add Organization database
/// </summary>
public override void AddOrganizationDatabase()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#region using directives

using System;
using System.Collections.Generic;
using Symu.Classes.Organization;
using Symu.Classes.Task;
using Symu.Common;
Expand Down Expand Up @@ -57,17 +56,17 @@ public override void SetOrganization(OrganizationEntity organization)
}

/// <summary>
/// Add Organization knowledge
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.AddOrganizationKnowledges();
base.AddOrganizationKnowledges();
// KnowledgeCount are added for tasks initialization
// Adn Beliefs are created based on knowledge
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);
Organization.AddKnowledge(knowledge);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#region using directives

using System;
using System.Collections.Generic;
using Symu.Classes.Agents;
using Symu.Classes.Organization;
using Symu.Classes.Task;
Expand Down Expand Up @@ -46,7 +45,7 @@ public override void SetOrganization(OrganizationEntity organization)
}

/// <summary>
/// Add Organization knowledge
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
Expand All @@ -56,10 +55,9 @@ public override void AddOrganizationKnowledges()
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);
Organization.AddKnowledge(knowledge);
}

}

public override void SetAgents()
Expand Down
1 change: 0 additions & 1 deletion Symu source code/Symu/Classes/Agents/Agent.Act.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Symu.Classes.Task;
using Symu.Common;
using Symu.Environment;
using Symu.Messaging.Messages;
using Symu.Repository;
Expand Down
21 changes: 9 additions & 12 deletions Symu source code/Symu/Classes/Agents/Agent.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Symu.Classes.Task.Manager;
using Symu.Common;
using Symu.Messaging.Manager;
Expand Down Expand Up @@ -188,10 +187,6 @@ public bool AcceptNewInteraction(AgentId senderId)

var sender = Environment.WhitePages.GetAgent(senderId);
// sender may be stopped since he accept this new interaction
if (sender == null)
{
///todo remove
}
if (!Cognitive.InteractionPatterns.IsPartOfInteractionSphere ||
!sender.Cognitive.InteractionPatterns.IsPartOfInteractionSphere)
{
Expand Down Expand Up @@ -442,9 +437,9 @@ public virtual void OnAfterSendMessage(Message message)
}

/// <summary>
/// Agent try send a message to another agent
/// if the receiver is stopping or stopped, the message is not sent
/// otherwise, the message is send to the next step
/// Agent try send a message to another agent
/// if the receiver is stopping or stopped, the message is not sent
/// otherwise, the message is send to the next step
/// </summary>
/// <param name="message"></param>
public void TrySendDelayed(Message message)
Expand All @@ -453,9 +448,9 @@ public void TrySendDelayed(Message message)
}

/// <summary>
/// Agent try send a message to another agent
/// if the receiver is stopping or stopped, the message is not sent
/// otherwise, the message is send with delay
/// Agent try send a message to another agent
/// if the receiver is stopping or stopped, the message is not sent
/// otherwise, the message is send with delay
/// </summary>
/// <param name="message"></param>
/// <param name="step"></param>
Expand All @@ -472,6 +467,7 @@ public void TrySendDelayed(Message message, ushort step)
// receiver is already stopped
return;
}

switch (receiver.State)
{
case AgentState.Stopping:
Expand All @@ -482,7 +478,8 @@ public void TrySendDelayed(Message message, ushort step)
break;
}
}
public void SendDelayed(Message message, ushort step)

private void SendDelayed(Message message, ushort step)
{
Environment.SendDelayedMessage(message, step);
}
Expand Down
23 changes: 13 additions & 10 deletions Symu source code/Symu/Classes/Agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ namespace Symu.Classes.Agents
public abstract partial class Agent
{
private byte _newInteractionCounter;
/// <summary>
/// Day of creation of the agent
/// </summary>
public ushort Created { get; private set; }
/// <summary>
/// Day of stopped of the agent
/// </summary>
public ushort Stopped { get; private set; }

/// <summary>
/// constructor for generic new()
Expand Down Expand Up @@ -72,6 +64,16 @@ protected Agent(AgentId agentId, SymuEnvironment environment, CognitiveArchitect
CreateAgent(agentId, environment, template);
}

/// <summary>
/// Day of creation of the agent
/// </summary>
public ushort Created { get; private set; }

/// <summary>
/// Day of stopped of the agent
/// </summary>
public ushort Stopped { get; private set; }

/// <summary>
/// The name of the agent. Each agent must have a unique name in its environment.
/// Most operations are performed using agent names rather than agent objects.
Expand Down Expand Up @@ -324,8 +326,9 @@ protected void FinalizeModels()
BeliefsModel.InitializeBeliefs();
}
}

/// <summary>
/// Set the state of the agent to Stopping so that the agent will be stopped at the end of this step
/// Set the state of the agent to Stopping so that the agent will be stopped at the end of this step
/// </summary>
public void Stop()
{
Expand Down Expand Up @@ -463,7 +466,7 @@ public void Subscribe(AgentId agentId, byte subject)
if (Schedule.Step == 0)
{
// Not sure the receiver exists already
SendDelayed(message, Schedule.Step);
TrySendDelayed(message);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Symu source code/Symu/Classes/Agents/AgentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AgentEntity(ushort key, byte classKey, string name) : this(key, classKey)
Name = name;
}

public AgentEntity(ushort key, byte classKey, string name, ushort parent) : this(key, classKey, name)
public AgentEntity(ushort key, byte classKey, string name, AgentId parent) : this(key, classKey, name)
{
Parent = parent;
}
Expand All @@ -51,7 +51,7 @@ public AgentEntity(ushort key, byte classKey, string name, ushort parent) : this
public AgentId Id { get; set; }

public string Name { get; set; }
public ushort Parent { get; set; }
public AgentId Parent { get; set; }

public void CopyTo(AgentEntity entity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System;
using Symu.Classes.Agents.Models;
using Symu.Classes.Agents.Models.CognitiveModels;
using Symu.Environment;

#endregion

Expand All @@ -27,6 +26,14 @@ public class InteractionSphereModel : ModelEntity

private float _minSphereDensity;

private float _relativeActivityWeight = 1;

private float _relativeBeliefWeight = 1;

private float _relativeKnowledgeWeight = 1;

private float _socialDemographicWeight = 1;

/// <summary>
/// If set to true, sphere of interaction will be re calculate at the FrequencyOfSphereUpdate.
/// If set to true, agent can initiate new interaction to add an agent in his sphere of interaction.
Expand All @@ -53,6 +60,7 @@ public float MinSphereDensity
{
throw new ArgumentOutOfRangeException("MinSphereDensity should be between [0;1]");
}

if (value > _maxSphereDensity)
{
throw new ArgumentOutOfRangeException("MinSphereDensity should be <= MaxSphereDensity");
Expand All @@ -75,6 +83,7 @@ public float MaxSphereDensity
{
throw new ArgumentOutOfRangeException("MaxSphereDensity should be between [0;1]");
}

if (value < _minSphereDensity)
{
throw new ArgumentOutOfRangeException("MaxSphereDensity should be <= MinSphereDensity");
Expand All @@ -84,8 +93,6 @@ public float MaxSphereDensity
}
}

private float _socialDemographicWeight = 1;

/// <summary>
/// Weight of SocialDemographic in the calculus of DerivedParameter
/// Range[0;1]
Expand All @@ -104,8 +111,6 @@ public float SocialDemographicWeight
}
}

private float _relativeBeliefWeight = 1;

/// <summary>
/// Weight of RelativeBelief in the calculus of DerivedParameter
/// Range[0;1]
Expand All @@ -124,8 +129,6 @@ public float RelativeBeliefWeight
}
}

private float _relativeKnowledgeWeight = 1;

/// <summary>
/// Weight of RelativeKnowledge in the calculus of DerivedParameter
/// Range[0;1]
Expand All @@ -144,8 +147,6 @@ public float RelativeKnowledgeWeight
}
}

private float _relativeActivityWeight = 1;

/// <summary>
/// Weight of RelativeBeliefs in the calculus of DerivedParameter
/// Range[0;1]
Expand Down
2 changes: 1 addition & 1 deletion Symu source code/Symu/Classes/Task/Manager/TasksManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private bool SelectNextMessage(CommunicationMediums medium, out SymuTask symuTas
/// manager.OnPrioritizeTasks += PrioritizeManager;
/// public void PrioritizeManager(object sender, TasksEventArgs e)
/// {
/// e.Tasks = e.Tasks.OrderBy(i => i.Created);
/// e.Tasks = e.Tasks.OrderBy(i => i.Created);
/// }
/// </example>
public SymuTask PrioritizeNextTask(IEnumerable<SymuTask> tasks)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Licence

// Description: Symu - Simulation
// Description: SymuBiz - Symu
// 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 @@ -62,6 +62,7 @@ public void CopyTo(TasksManagerMetrics clone)
{
clone.InProgress.Add(inProgress.Key, inProgress.Value);
}

foreach (var done in Done)
{
clone.Done.Add(done.Key, done.Value);
Expand Down
2 changes: 1 addition & 1 deletion Symu source code/Symu/Classes/Task/SymuTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public float Weight
/// Time to live : task may be created have a limited time to live,
/// it will self-destruct if the time is exceeded
/// -1 for unlimited time to live
/// TimeToLive is in days
/// TimeToLive is in days
/// </summary>
/// <example>An information on an IRC channel has a more limited lifetime than an email</example>
/// <example>Slack offer a limited history, some messaging system have a limited storage capacity</example>
Expand Down
5 changes: 0 additions & 5 deletions Symu source code/Symu/Engine/SymuEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public class SymuEngine
/// </summary>
public SimulationResults SimulationResults { get; set; } = new SimulationResults();

/// <summary>
/// The result of the actual iteration
/// </summary>
public IterationResult IterationResult => Environment?.IterationResult;

#region Step level

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Symu source code/Symu/Environment/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public static DateTime ConvertDoubleToDateTime(double days)
}



public static int FrequencyFactor(TimeStepType frequency)
{
var frequencyFactor = 1;
Expand Down

0 comments on commit 3fceb33

Please sign in to comment.