Skip to content

Commit

Permalink
Using IAgentId in MetaNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Aug 17, 2020
1 parent 93e3f41 commit d7026eb
Show file tree
Hide file tree
Showing 79 changed files with 774 additions and 620 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Symu.Common;
using Symu.Environment;
using Symu.Repository.Networks.Knowledges;
using Symu.Tools.Interfaces;

#endregion

Expand Down Expand Up @@ -88,19 +89,19 @@ public override void SetAgents()
{
base.SetAgents();

var agentIds = new List<AgentId>();
var agentIds = new List<IAgentId>();

for (var j = 0; j < InfluencersCount; j++)
{
var actor = new InfluencerAgent(Organization.NextEntityIndex(), this, InfluencerTemplate);
Influencers.Add(actor);
agentIds.Add(actor.Id);
agentIds.Add(actor.AgentId);
}

for (var j = 0; j < WorkersCount; j++)
{
var actor = new PersonAgent(Organization.NextEntityIndex(), this, WorkerTemplate);
agentIds.Add(actor.Id);
agentIds.Add(actor.AgentId);
}

WhitePages.MetaNetwork.Links.AddLinks(agentIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace SymuBeliefsAndInfluence.Classes
{
public sealed class InfluencerAgent : CognitiveAgent
{
public const byte ClassKey = SymuYellowPages.Actor;
public const byte Class = SymuYellowPages.Actor;

public InfluencerAgent(ushort agentKey, SymuEnvironment environment,
CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down
6 changes: 3 additions & 3 deletions Symu examples/SymuBeliefsAndInfluence/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ namespace SymuBeliefsAndInfluence.Classes
{
public sealed class PersonAgent : CognitiveAgent
{
public const byte ClassKey = SymuYellowPages.Actor;
public const byte Class = SymuYellowPages.Actor;

public PersonAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

public IEnumerable<Knowledge> Knowledges => Environment.Organization.Knowledges;
public IEnumerable<AgentId> Influencers => ((ExampleEnvironment) Environment).Influencers.Select(x => x.Id);
public IEnumerable<AgentId> Influencers => ((ExampleEnvironment) Environment).Influencers.Select(x => x.AgentId);

/// <summary>
/// Customize the cognitive architecture of the agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public override void SetAgents()
{
var actor = new PersonAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human)
{
GroupId = group.Id
GroupId = group.AgentId
};
WhitePages.MetaNetwork.AddAgentToGroup(actor.Id, 100, group.Id, false);
WhitePages.MetaNetwork.AddAgentToGroup(actor.AgentId, 100, group.AgentId, false);
//Beliefs are added with knowledge
SetKnowledge(actor, Organization.Knowledges, i);
SetActivity(actor.Id, _activities, i, group.Id);
SetActivity(actor.AgentId, _activities, i, group.AgentId);
}
}
}
Expand All @@ -91,18 +91,18 @@ private void SetKnowledge(CognitiveAgent actor, IReadOnlyList<Knowledge> knowled
{
case 0:
// same Knowledge for all
WhitePages.MetaNetwork.Knowledge.Add(actor.Id, knowledges[0].Id, KnowledgeLevel,
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[0].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
break;
case 1:
// Knowledge is by group
WhitePages.MetaNetwork.Knowledge.Add(actor.Id, knowledges[i].Id, KnowledgeLevel,
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[i].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
break;
case 2:
// Knowledge is randomly defined for agentId
var index = DiscreteUniform.Sample(0, GroupsCount - 1);
WhitePages.MetaNetwork.Knowledge.Add(actor.Id, knowledges[index].Id, KnowledgeLevel,
WhitePages.MetaNetwork.Knowledge.Add(actor.AgentId, knowledges[index].Id, KnowledgeLevel,
actor.Cognitive.InternalCharacteristics);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuGroupAndInteraction/Classes/GroupAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace SymuGroupAndInteraction.Classes
{
public sealed class GroupAgent : ReactiveAgent
{
public const byte ClassKey = 1;
public const byte Class = 1;

public GroupAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey), environment)
new AgentId(agentKey, Class), environment)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuGroupAndInteraction/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace SymuGroupAndInteraction.Classes
{
public sealed class PersonAgent : CognitiveAgent
{
public const byte ClassKey = SymuYellowPages.Actor;
public const byte Class = SymuYellowPages.Actor;

public PersonAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void AddOrganizationDatabase()
{
base.AddOrganizationDatabase();

var wikiEntity = new DataBaseEntity(Organization.Id, Organization.Communication.Email);
var wikiEntity = new DataBaseEntity(Organization.AgentId, Organization.Communication.Email);
Organization.AddDatabase(wikiEntity);
}

Expand All @@ -82,7 +82,7 @@ public override void SetAgents()
DoesNotLearnAgent = new LearnAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human);
ExpertAgent = new ExpertAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human);
// Active link between expert and LearnByAskingAgent to be able to exchange information
WhitePages.MetaNetwork.Links.AddLink(LearnByAskingAgent.Id, ExpertAgent.Id);
WhitePages.MetaNetwork.Links.AddLink(LearnByAskingAgent.AgentId, ExpertAgent.AgentId);
}
}
}
4 changes: 2 additions & 2 deletions Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace SymuLearnAndForget.Classes
{
public sealed class ExpertAgent : CognitiveAgent
{
public const byte ClassKey = 2;
public const byte Class = 2;

public ExpertAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace SymuLearnAndForget.Classes
{
public class LearnAgent : CognitiveAgent
{
public const byte ClassKey = 2;
public const byte Class = 2;

public LearnAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
Wiki = Environment.WhitePages.MetaNetwork.Databases.Repository.List.First();
Knowledge = GetKnowledge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void GetNewTasks()
KnowledgeId = Knowledge.Id,
KnowledgeBit = Knowledge.GetRandomBitIndex()
};
Send(((ExampleEnvironment) Environment).ExpertAgent.Id, MessageAction.Ask, SymuYellowPages.Knowledge,
Send(((ExampleEnvironment) Environment).ExpertAgent.AgentId, MessageAction.Ask, SymuYellowPages.Knowledge,
attachments, CommunicationMediums.Email);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ public override void SetAgents()
{
var actor = new PersonAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human)
{
GroupId = group.Id
GroupId = group.AgentId
};
CommunicationTemplate communication = new EmailTemplate();
var entity = new DataBaseEntity(actor.Id, communication);
var entity = new DataBaseEntity(actor.AgentId, communication);
var email = new Database(entity, Organization.Models, WhitePages.MetaNetwork.Knowledge);
WhitePages.MetaNetwork.Databases.Add(actor.Id, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.Id, 100, group.Id, false);
WhitePages.MetaNetwork.Databases.Add(actor.AgentId, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.AgentId, 100, group.AgentId, false);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuMessageAndTask/Classes/GroupAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace SymuMessageAndTask.Classes
{
public sealed class GroupAgent : ReactiveAgent
{
public const byte ClassKey = 1;
public const byte Class = 1;

public GroupAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey), environment)
new AgentId(agentKey, Class), environment)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuMessageAndTask/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace SymuMessageAndTask.Classes
{
public sealed class PersonAgent : CognitiveAgent
{
public const byte ClassKey = 2;
public const byte Class = 2;

public PersonAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public override void SetAgents()
{
var actor = new PersonAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human)
{
GroupId = group.Id
GroupId = group.AgentId
};
CommunicationTemplate communication = new EmailTemplate();
var entity = new DataBaseEntity(actor.Id, communication);
var entity = new DataBaseEntity(actor.AgentId, communication);
var email = new Database(entity, Organization.Models, WhitePages.MetaNetwork.Knowledge);
WhitePages.MetaNetwork.Databases.Add(actor.Id, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.Id, 100, group.Id, false);
WhitePages.MetaNetwork.Databases.Add(actor.AgentId, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.AgentId, 100, group.AgentId, false);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuMurphiesAndBlockers/Classes/GroupAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace SymuMurphiesAndBlockers.Classes
{
public sealed class GroupAgent : ReactiveAgent
{
public const byte ClassKey = 1;
public const byte Class = 1;

public GroupAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey), environment)
new AgentId(agentKey, Class), environment)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace SymuMurphiesAndBlockers.Classes
/// </summary>
public sealed class InternetAccessAgent : CognitiveAgent
{
public const byte ClassKey = 1;
public const byte Class = 1;

public InternetAccessAgent(ushort agentKey, SymuEnvironment environment,
CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down
8 changes: 4 additions & 4 deletions Symu examples/SymuMurphiesAndBlockers/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace SymuMurphiesAndBlockers.Classes
{
public sealed class PersonAgent : CognitiveAgent
{
public const byte ClassKey = SymuYellowPages.Actor;
public const byte Class = SymuYellowPages.Actor;

public PersonAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public override void GetNewTasks()
{
Weight = 1,
// Creator is randomly a person of the group - for the incomplete information murphy
Creator = Environment.WhitePages.FilteredAgentIdsByClassKey(ClassKey).Shuffle().First()
Creator = Environment.WhitePages.FilteredAgentIdsByClassId(Class).Shuffle().First()
};
task.SetKnowledgesBits(Model, Knowledges, 1);
Post(task);
Expand All @@ -104,7 +104,7 @@ public override void GetNewTasks()
attachments.Add(task);
attachments.KnowledgeId = knowledgeId;
attachments.KnowledgeBit = knowledgeBit;
Send(Internet.Id, MessageAction.Ask, SymuYellowPages.Help, attachments,
Send(Internet.AgentId, MessageAction.Ask, SymuYellowPages.Help, attachments,
CommunicationMediums.ViaAPlatform);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ public void OnlyKnowledgeTest10()
_environment.Organization.Murphies.IncompleteKnowledge.RateOfIncorrectGuess = 1;

_simulation.Process();
Assert.AreNotEqual(0,_environment.IterationResult.Tasks.Incorrectness);
if (_environment.IterationResult.Tasks.Done > 0)
{
Assert.AreNotEqual(0, _environment.IterationResult.Tasks.Incorrectness);
Assert.AreNotEqual(0, _environment.IterationResult.Tasks.Cancelled);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override void SetAgents()
base.SetAgents();

var group = new GroupAgent(Organization.NextEntityIndex(), this);
_groupId = group.Id;
_groupId = group.AgentId;
for (var j = 0; j < WorkersCount; j++)
{
AddPersonAgent();
Expand All @@ -80,10 +80,10 @@ private PersonAgent AddPersonAgent()
GroupId = _groupId
};
CommunicationTemplate communication = new EmailTemplate();
var entity = new DataBaseEntity(actor.Id, communication);
var entity = new DataBaseEntity(actor.AgentId, communication);
var email = new Database(entity, Organization.Models, WhitePages.MetaNetwork.Knowledge);
WhitePages.MetaNetwork.Databases.Add(actor.Id, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.Id, 100, _groupId, false);
WhitePages.MetaNetwork.Databases.Add(actor.AgentId, email);
WhitePages.MetaNetwork.AddAgentToGroup(actor.AgentId, 100, _groupId, false);
return actor;
}

Expand All @@ -101,7 +101,7 @@ public void KnowledgeEvent(object sender, EventArgs e)
var knowledge = new Knowledge(KnowledgeCount, KnowledgeCount.ToString(), 10);
WhitePages.MetaNetwork.AddKnowledge(knowledge);

foreach (var person in WhitePages.FilteredCognitiveAgentsByClassKey(PersonAgent.ClassKey))
foreach (var person in WhitePages.FilteredCognitiveAgentsByClassId(PersonAgent.Class))
{
person.KnowledgeModel.AddKnowledge(knowledge.Id, KnowledgeLevel.BasicKnowledge, 0.15F, -1);
person.KnowledgeModel.InitializeKnowledge(knowledge.Id, Schedule.Step);
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuScenariosAndEvents/Classes/GroupAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace SymuScenariosAndEvents.Classes
{
public sealed class GroupAgent : ReactiveAgent
{
public const byte ClassKey = 1;
public const byte Class = 1;

public GroupAgent(ushort agentKey, SymuEnvironment environment) : base(
new AgentId(agentKey, ClassKey), environment)
new AgentId(agentKey, Class), environment)
{
}
}
Expand Down
6 changes: 3 additions & 3 deletions Symu examples/SymuScenariosAndEvents/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace SymuScenariosAndEvents.Classes
{
public sealed class PersonAgent : CognitiveAgent
{
public const byte ClassKey = SymuYellowPages.Actor;
public const byte Class = SymuYellowPages.Actor;

public PersonAgent(ushort agentKey, SymuEnvironment environment, CognitiveArchitectureTemplate template) : base(
new AgentId(agentKey, ClassKey), environment, template)
new AgentId(agentKey, Class), environment, template)
{
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public override void GetNewTasks()
// Weight is randomly distributed around 1, but has a minimum of 0
Weight = Math.Max(0, Normal.Sample(1, 0.1F * Environment.Organization.Models.RandomLevelValue)),
// Creator is randomly a person of the group - for the incomplete information murphy
Creator = Environment.WhitePages.FilteredAgentIdsByClassKey(ClassKey).Shuffle().First()
Creator = Environment.WhitePages.FilteredAgentIdsByClassId(Class).Shuffle().First()
};
task.SetKnowledgesBits(Model, Knowledges, 1);
Post(task);
Expand Down

0 comments on commit d7026eb

Please sign in to comment.