Skip to content

Commit

Permalink
Extract ReactiveAgent interface
Browse files Browse the repository at this point in the history
IAgent
  • Loading branch information
lmorisse committed Aug 31, 2020
1 parent fbc5b27 commit 0d746ef
Show file tree
Hide file tree
Showing 43 changed files with 119 additions and 112 deletions.
10 changes: 5 additions & 5 deletions SourceCode/Symu/Classes/Agents/AgentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public AgentEntity()
{
}

public AgentEntity(UId id, byte classId)
public AgentEntity(IId id, byte classId)
{
AgentId = new AgentId(id, classId);
}

public AgentEntity(UId id, byte classId, string name) : this(id, classId)
public AgentEntity(IId id, byte classId, string name) : this(id, classId)
{
if (string.IsNullOrEmpty(name))
{
Expand All @@ -41,7 +41,7 @@ public AgentEntity(UId id, byte classId, string name) : this(id, classId)
Name = name;
}

public AgentEntity(UId id, byte classId, string name, AgentId parent) : this(id, classId, name)
public AgentEntity(IId id, byte classId, string name, IAgentId parent) : this(id, classId, name)
{
Parent = parent;
}
Expand All @@ -50,10 +50,10 @@ public AgentEntity(UId id, byte classId, string name, AgentId parent) : this(id,
/// The Id of the agent. Each entity must have a unique Id
/// FIPA Norm : AID
/// </summary>
public AgentId AgentId { get; set; }
public IAgentId AgentId { get; set; }

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

public void CopyTo(AgentEntity entity)
{
Expand Down
6 changes: 3 additions & 3 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.Tasking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public virtual void SwitchingContextModel()
/// Key => step
/// Value => time spent
/// </summary>
public Dictionary<UId, float> TimeSpent { get; } = new Dictionary<UId, float>();
public Dictionary<IId, float> TimeSpent { get; } = new Dictionary<IId, float>();

/// <summary>
/// Impact of the Communication channels on the time spent
Expand All @@ -222,7 +222,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,
UId keyActivity)
IId keyActivity)
{
if (keyActivity == null || keyActivity.IsNull)
{
Expand All @@ -240,7 +240,7 @@ public virtual void SwitchingContextModel()
/// </summary>
/// <param name="keyActivity"></param>
/// <param name="timeSpent"></param>
public void AddTimeSpent(UId keyActivity, float timeSpent)
public void AddTimeSpent(IId keyActivity, float timeSpent)
{
if (keyActivity == null)
{
Expand Down
24 changes: 12 additions & 12 deletions SourceCode/Symu/Classes/Agents/CognitiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private CognitiveAgent()
/// <param name="agentId"></param>
/// <param name="environment"></param>
/// <remarks> Make constructor private and create a factory method to create an agent that call the Initialize method</remarks>
protected CognitiveAgent(AgentId agentId, SymuEnvironment environment) : base(agentId, environment)
protected CognitiveAgent(IAgentId agentId, SymuEnvironment environment) : base(agentId, environment)
{
_cognitiveTemplate = environment.Organization.Templates.Standard;
}
Expand All @@ -61,7 +61,7 @@ protected CognitiveAgent(AgentId agentId, SymuEnvironment environment) : base(ag
/// <param name="environment"></param>
/// <param name="template"></param>
/// <remarks> Make constructor private and create a factory method to create an agent that call the Initialize method</remarks>
protected CognitiveAgent(AgentId agentId, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(agentId, environment)
protected CognitiveAgent(IAgentId agentId, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(agentId, environment)
{
_cognitiveTemplate = template;
}
Expand Down Expand Up @@ -170,36 +170,36 @@ protected virtual void SetCognitive()
/// based on the interaction strategy of the interaction patterns :
/// Filtered with interactionStrategy and limit with number of new interactions
/// </summary>
public IEnumerable<AgentId> GetAgentIdsForNewInteractions()
public IEnumerable<IAgentId> GetAgentIdsForNewInteractions()
{
if (!Environment.Organization.Models.InteractionSphere.IsAgentOn())
{
// Agent don't want to have new interactions today
return new List<AgentId>();
return new List<IAgentId>();
}

var agentIds = Environment.WhitePages.MetaNetwork.InteractionSphere.GetAgentIdsForNewInteractions(AgentId,
Cognitive.InteractionPatterns.NextInteractionStrategy()).Cast<AgentId>().ToList();
return FilterAgentIdsToInteract(agentIds);
Cognitive.InteractionPatterns.NextInteractionStrategy());
return FilterAgentIdsToInteract(agentIds.ToList());
}

/// <summary>
/// List of AgentId for interactions : there is Active link (difference with GetAgentIdsForNewInteractions)
/// based on the interaction strategy of the interaction patterns :
/// Filtered with interactionStrategy and limit with number of new interactions
/// </summary>
public IEnumerable<AgentId> GetAgentIdsForInteractions(InteractionStrategy interactionStrategy)
public IEnumerable<IAgentId> GetAgentIdsForInteractions(InteractionStrategy interactionStrategy)
{
return Environment.WhitePages.MetaNetwork.InteractionSphere
.GetAgentIdsForInteractions(AgentId, interactionStrategy).Cast<AgentId>().ToList();
.GetAgentIdsForInteractions(AgentId, interactionStrategy);
}

/// <summary>
/// Filter the good number of agents based on Cognitive.InteractionPatterns
/// </summary>
/// <param name="agentIds"></param>
/// <returns>List of AgentIds the agent can interact with via message</returns>
public IEnumerable<AgentId> FilterAgentIdsToInteract(List<AgentId> agentIds)
public IEnumerable<IAgentId> FilterAgentIdsToInteract(List<IAgentId> agentIds)
{
if (agentIds == null)
{
Expand Down Expand Up @@ -348,7 +348,7 @@ public void AddSubscribe(Message message)
/// </summary>
/// <param name="agentId"></param>
/// <param name="subject"></param>
public void Subscribe(AgentId agentId, byte subject)
public void Subscribe(IAgentId agentId, byte subject)
{
var message = new Message(AgentId, agentId, MessageAction.Add, SymuYellowPages.Subscribe, subject);
if (Schedule.Step == 0)
Expand All @@ -365,15 +365,15 @@ public void Subscribe(AgentId agentId, byte subject)
/// <summary>
/// UnSubscribe to the Message subject
/// </summary>
public void Unsubscribe(AgentId agentId, byte subject)
public void Unsubscribe(IAgentId agentId, byte subject)
{
Send(agentId, MessageAction.Remove, SymuYellowPages.Subscribe, subject);
}

/// <summary>
/// UnSubscribe to all subjects
/// </summary>
public void Unsubscribe(AgentId agentId)
public void Unsubscribe(IAgentId agentId)
{
Send(agentId, MessageAction.Remove, SymuYellowPages.Subscribe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Symu.Classes.Agents.Models.CognitiveModels
/// <remarks>From Construct Software</remarks>
public class ActivityModel
{
private readonly AgentId _agentId;
private readonly IAgentId _agentId;
private readonly ActivityNetwork _networkActivities;

/// <summary>
Expand All @@ -40,7 +40,7 @@ public class ActivityModel
/// <param name="agentId"></param>
/// <param name="cognitiveArchitecture"></param>
/// <param name="network"></param>
public ActivityModel(AgentId agentId, CognitiveArchitecture cognitiveArchitecture, SymuMetaNetwork network)
public ActivityModel(IAgentId agentId, CognitiveArchitecture cognitiveArchitecture, SymuMetaNetwork network)
{
if (cognitiveArchitecture == null)
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public void AddActivities(IEnumerable<IActivity> activities)
/// <summary>
/// List of the activities on which an agent is working, filtered by groupId
/// </summary>
public IEnumerable<IActivity> GetGroupActivities(AgentId groupId)
public IEnumerable<IActivity> GetGroupActivities(IAgentId groupId)
{
return _networkActivities.GetActivities(_agentId, groupId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Symu.Classes.Agents.Models.CognitiveModels
public class BeliefsModel
{
private readonly RandomGenerator _model;
private readonly AgentId _agentId;
private readonly IAgentId _agentId;
private readonly KnowledgeAndBeliefs _knowledgeAndBeliefs;
private readonly MessageContent _messageContent;
private readonly BeliefNetwork _networkBeliefs;
Expand All @@ -50,7 +50,7 @@ public class BeliefsModel
/// <param name="cognitiveArchitecture"></param>
/// <param name="network"></param>
/// <param name="model"></param>
public BeliefsModel(AgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
public BeliefsModel(IAgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
SymuMetaNetwork network, RandomGenerator model)
{
if (entity is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Symu.Classes.Agents.Models.CognitiveModels
public class InfluenceModel
{
private readonly RandomGenerator _model;
private readonly AgentId _agentId;
private readonly IAgentId _agentId;
private readonly InfluenceNetwork _networkInfluences;
private readonly BeliefsModel _beliefsModel;

Expand All @@ -47,7 +47,7 @@ public class InfluenceModel
/// <param name="network"></param>
/// <param name="beliefsModel"></param>
/// <param name="model"></param>
public InfluenceModel(AgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
public InfluenceModel(IAgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
SymuMetaNetwork network, BeliefsModel beliefsModel, RandomGenerator model)
{
if (entity is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Symu.Classes.Agents.Models.CognitiveModels
/// <remarks>From Construct Software</remarks>
public class KnowledgeModel
{
private readonly AgentId _agentId;
private readonly IAgentId _agentId;
private readonly KnowledgeAndBeliefs _knowledgeAndBeliefs;
private readonly MessageContent _messageContent;
private readonly KnowledgeNetwork _knowledgeNetwork;
Expand All @@ -46,7 +46,7 @@ public class KnowledgeModel
/// <param name="entity"></param>
/// <param name="cognitiveArchitecture"></param>
/// <param name="network"></param>
public KnowledgeModel(AgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
public KnowledgeModel(IAgentId agentId, ModelEntity entity, CognitiveArchitecture cognitiveArchitecture,
SymuMetaNetwork network)
{
if (entity is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Symu.Classes.Agents.Models.CognitiveModels
/// <remarks>From Construct Software</remarks>
public class LearningModel : ModelEntity
{
private readonly AgentId _id;
private readonly IAgentId _id;
private readonly InternalCharacteristics _internalCharacteristics;
private readonly KnowledgeNetwork _knowledgeNetwork;
private readonly byte _randomLevel;
Expand Down Expand Up @@ -68,7 +68,7 @@ public float GetKnowledgePotential()
return Expertise.GetAgentKnowledges<AgentKnowledge>().Sum(l => l.GetKnowledgePotential());
}

public LearningModel(AgentId agentId, OrganizationModels models, KnowledgeNetwork knowledgeNetwork,
public LearningModel(IAgentId agentId, OrganizationModels models, KnowledgeNetwork knowledgeNetwork,
CognitiveArchitecture cognitiveArchitecture)
{
if (models == null)
Expand Down
12 changes: 6 additions & 6 deletions SourceCode/Symu/Classes/Agents/ReactiveAgent.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ public void SendToMany(IEnumerable<IAgentId> receivers, MessageAction action, by
}
}

public void SendToMany(IEnumerable<AgentId> receivers, MessageAction action, byte content,
public void SendToMany(IEnumerable<IAgentId> receivers, MessageAction action, byte content,
MessageAttachments parameter)
{
SendToMany(receivers, action, content, parameter, CommunicationMediums.System);
}

public void SendToMany(IEnumerable<AgentId> receivers, MessageAction action, byte content,
public void SendToMany(IEnumerable<IAgentId> receivers, MessageAction action, byte content,
MessageAttachments parameter, CommunicationMediums communicationMedium)
{
if (receivers is null)
Expand Down Expand Up @@ -422,25 +422,25 @@ public void ReplyDelayed(Message message, ushort delay)
/// A conversation identifier, for the cases when a conversation involves multiple messages
/// that refer to the same topic
/// </param>
public void Reply(AgentId receiverId, MessageAction action, byte content)
public void Reply(IAgentId receiverId, MessageAction action, byte content)
{
var message = new Message(AgentId, receiverId, action, content);
Reply(message);
}

public void Reply(AgentId receiverId, MessageAction action, byte content, object parameter)
public void Reply(IAgentId receiverId, MessageAction action, byte content, object parameter)
{
var message = new Message(AgentId, receiverId, action, content, parameter);
Reply(message);
}

public void Reply(AgentId receiverId, MessageAction action, byte content, MessageAttachments parameter)
public void Reply(IAgentId receiverId, MessageAction action, byte content, MessageAttachments parameter)
{
var message = new Message(AgentId, receiverId, action, content, parameter);
Reply(message);
}

public void Reply(AgentId receiverId, MessageAction action, byte content, MessageAttachments parameter,
public void Reply(IAgentId receiverId, MessageAction action, byte content, MessageAttachments parameter,
CommunicationMediums communicationMedium)
{
var message = new Message(AgentId, receiverId, action, content, parameter, communicationMedium);
Expand Down
12 changes: 9 additions & 3 deletions SourceCode/Symu/Classes/Agents/ReactiveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@

namespace Symu.Classes.Agents
{
public interface IAgent
{
IAgentId AgentId {get;
set;
}
}
/// <summary>
/// An abstract base class for agents.
/// You must define your own agent derived classes derived
/// </summary>
public abstract partial class ReactiveAgent
public abstract partial class ReactiveAgent: IAgent
{
/// <summary>
/// constructor for generic new()
Expand All @@ -40,7 +46,7 @@ protected ReactiveAgent()
/// </summary>
/// <param name="agentId"></param>
/// <param name="environment"></param>
protected ReactiveAgent(AgentId agentId, SymuEnvironment environment)
protected ReactiveAgent(IAgentId agentId, SymuEnvironment environment)
{
AgentId = agentId;
Environment = environment ?? throw new ArgumentNullException(nameof(environment));
Expand All @@ -63,7 +69,7 @@ protected ReactiveAgent(AgentId agentId, SymuEnvironment environment)
/// 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.
/// </summary>
public AgentId AgentId { get; set; }
public IAgentId AgentId { get; set; }

/// <summary>
/// State of the agent
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Classes/Organization/OrganizationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public OrganizationEntity(string name) : base(new UId(0), Class, name)
/// </summary>
public MurphyCollection Murphies { get; } = new MurphyCollection();

public UId NextEntityId()
public IId NextEntityId()
{
return new UId(EntityIndex++);
}
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Classes/Scenario/ScenarioEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ScenarioEntity : AgentEntity
{
public const byte Class = SymuYellowPages.Scenario;

public ScenarioEntity(UId id) : base(id, Class)
public ScenarioEntity(IId id) : base(id, Class)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Symu/Classes/Task/SymuTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SymuTask(ushort day)
/// <summary>
/// the Key of the ParentId (group, process, ...) in which the task must be performed
/// </summary>
public UId KeyActivity { get; set; }
public IId KeyActivity { get; set; }

/// <summary>
/// Type of the task use to have specific behaviour
Expand Down
4 changes: 2 additions & 2 deletions SourceCode/Symu/Messaging/Tracker/MessagesTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public void ClearMessagesSent(ushort stepNumber)
LastSentMessages.ClearSteps(stepNumber - NumberOfSteps);
}

public List<Message> MessagesReceivedByAgent(ushort step, AgentId agentId)
public List<Message> MessagesReceivedByAgent(ushort step, IAgentId agentId)
{
return LastSentMessages.ReceivedByAgent(step, agentId);
}

public List<Message> MessagesSentByAgent(ushort step, AgentId agentId)
public List<Message> MessagesSentByAgent(ushort step, IAgentId agentId)
{
return LastSentMessages.SentByAgent(step, agentId);
}
Expand Down
4 changes: 2 additions & 2 deletions SourceCode/Symu/Messaging/Tracker/TimeStampedMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public List<Message> ByContent(ushort step, byte content)
return _messages.ContainsKey(step) ? _messages[step].ToList().FindAll(m => m.Subject == content) : null;
}

public List<Message> ReceivedByAgent(ushort step, AgentId agentId)
public List<Message> ReceivedByAgent(ushort step, IAgentId agentId)
{
return _messages.ContainsKey(step)
? _messages[step].ToList().FindAll(m => m.Receiver.Equals(agentId))
: null;
}

public List<Message> SentByAgent(ushort step, AgentId agentId)
public List<Message> SentByAgent(ushort step, IAgentId agentId)
{
return _messages.ContainsKey(step) ? _messages[step].ToList().FindAll(m => m.Sender.Equals(agentId)) : null;
}
Expand Down

0 comments on commit 0d746ef

Please sign in to comment.