Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
organization Knowledge management
  • Loading branch information
lmorisse committed Jun 12, 2020
1 parent e272a11 commit a6adeb8
Show file tree
Hide file tree
Showing 27 changed files with 282 additions and 85 deletions.
27 changes: 11 additions & 16 deletions Symu examples/SymuBeliefsAndInfluence/Classes/ExampleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ public class ExampleEnvironment : SymuEnvironment
public byte WorkersCount { get; set; } = 5;
public byte InfluencersCount { get; set; } = 2;
public byte KnowledgeCount { get; set; } = 2;
public List<Knowledge> Knowledges { get; private set; }
public List<InfluencerAgent> Influencers { get; } = new List<InfluencerAgent>();
public PromoterTemplate InfluencerTemplate { get; } = new PromoterTemplate();

public SimpleHumanTemplate WorkerTemplate { get; } = new SimpleHumanTemplate();
//public MurphyTask Model { get; } = new MurphyTask();

public override void SetOrganization(OrganizationEntity organization)
{
Expand Down Expand Up @@ -71,29 +69,28 @@ public override void SetOrganization(OrganizationEntity organization)
SetDebug(false);
}

public override void SetAgents()
/// <summary>
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.SetAgents();

#region Common

base.AddOrganizationKnowledges();
// KnowledgeCount are added for tasks initialization
// Adn Beliefs are created based on knowledge
Knowledges = new List<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);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);
var knowledge = new Knowledge((ushort)i, i.ToString(), 10);
Organization.AddKnowledge(knowledge);
}
}

#endregion
public override void SetAgents()
{
base.SetAgents();

var agentIds = new List<AgentId>();

#region Agents

for (var j = 0; j < InfluencersCount; j++)
{
var actor = new InfluencerAgent(Organization.NextEntityIndex(), this, InfluencerTemplate);
Expand All @@ -107,8 +104,6 @@ public override void SetAgents()
agentIds.Add(actor.Id);
}

#endregion

WhitePages.Network.NetworkLinks.AddLinks(agentIds);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class InfluencerAgent : Agent
{
}

public IEnumerable<Knowledge> Knowledges => ((ExampleEnvironment) Environment).Knowledges;
public IEnumerable<Knowledge> Knowledges => Environment.Organization.Knowledges;

/// <summary>
/// Customize the cognitive architecture of the agent
Expand All @@ -53,7 +53,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
foreach (var knowledge in Knowledges)
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuBeliefsAndInfluence/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class PersonAgent : Agent
{
}

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

/// <summary>
Expand All @@ -60,7 +60,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
foreach (var knowledge in Knowledges)
Expand Down
27 changes: 16 additions & 11 deletions Symu examples/SymuGroupAndInteraction/Classes/ExampleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace SymuGroupAndInteraction.Classes
{
public class ExampleEnvironment : SymuEnvironment
{
private readonly List<string> _activities = new List<string>();
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 List<Knowledge> Knowledges { get; } = new List<Knowledge>();

public override void SetOrganization(OrganizationEntity organization)
{
Expand All @@ -47,20 +47,25 @@ public override void SetOrganization(OrganizationEntity organization)
SetDebug(false);
}

public override void SetAgents()
/// <summary>
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.SetAgents();
var activities = new List<string>();
Knowledges.Clear();
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);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);
activities.Add(i.ToString());
var knowledge = new Knowledge((ushort)i, i.ToString(), 10);
Organization.AddKnowledge(knowledge);
_activities.Add(i.ToString());
//Beliefs are created based on knowledge
}
}

public override void SetAgents()
{
base.SetAgents();

for (var i = 0; i < GroupsCount; i++)
{
Expand All @@ -74,8 +79,8 @@ public override void SetAgents()
};
WhitePages.Network.AddMemberToGroup(actor.Id, 100, group.Id);
//Beliefs are added with knowledge
SetKnowledge(actor, Knowledges, i);
SetActivity(actor.Id, activities, i, group.Id);
SetKnowledge(actor, Organization.Knowledges, i);
SetActivity(actor.Id, _activities, i, group.Id);
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions Symu examples/SymuLearnAndForget/Classes/ExampleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,37 @@ public override void SetOrganization(OrganizationEntity organization)

base.SetOrganization(organization);

var wiki = new DataBaseEntity(organization.Id, organization.Communication.Email);
organization.AddDatabase(wiki);
IterationResult.KnowledgeAndBeliefResults.On = true;
Organization.Communication.Email.CostToSendLevel = GenericLevel.None;
Organization.Communication.Email.CostToReceiveLevel = GenericLevel.None;

SetDebug(false);
}

/// <summary>
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.AddOrganizationKnowledges();
Organization.AddKnowledge(Knowledge);
Wiki.InitializeKnowledge(Knowledge, 0);
}

/// <summary>
/// Add Organization database
/// </summary>
public override void AddOrganizationDatabase()
{
base.AddOrganizationDatabase();

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

public override void SetAgents()
{
base.SetAgents();
Organization.Communication.Email.CostToSendLevel = GenericLevel.None;
Organization.Communication.Email.CostToReceiveLevel = GenericLevel.None;
WhitePages.Network.AddKnowledge(Knowledge);
Wiki.InitializeKnowledge(Knowledge, 0);

LearnFromSourceAgent =
new LearnFromSourceAgent(Organization.NextEntityIndex(), this, Organization.Templates.Human);
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuLearnAndForget/Classes/ExpertAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
KnowledgeModel.AddKnowledge(((ExampleEnvironment) Environment).Knowledge.Id, KnowledgeLevel.Expert,
Expand Down
2 changes: 1 addition & 1 deletion Symu examples/SymuLearnAndForget/Classes/LearnAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
KnowledgeModel.AddKnowledge(((ExampleEnvironment) Environment).Knowledge.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class ExampleEnvironment : SymuEnvironment
public byte KnowledgeCount { get; set; } = 2;

public KnowledgeLevel KnowledgeLevel { get; set; } = KnowledgeLevel.Intermediate;
public List<Knowledge> Knowledges { get; private set; }
public MurphyTask Model => Organization.Murphies.IncompleteKnowledge;

public InternetAccessAgent Internet { get; private set; }
Expand Down Expand Up @@ -57,20 +56,25 @@ public override void SetOrganization(OrganizationEntity organization)
SetDebug(false);
}

public override void SetAgents()
/// <summary>
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.SetAgents();

base.AddOrganizationKnowledges();
// KnowledgeCount are added for tasks initialization
// Adn Beliefs are created based on knowledge
Knowledges = new List<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);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);
var knowledge = new Knowledge((ushort)i, i.ToString(), 10);
Organization.AddKnowledge(knowledge);
}
}

public override void SetAgents()
{
base.SetAgents();

var group = new GroupAgent(Organization.NextEntityIndex(), this);
Internet = new InternetAccessAgent(Organization.NextEntityIndex(), this, Organization.Templates.Internet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public sealed class InternetAccessAgent : Agent
{
}

public IEnumerable<Knowledge> Knowledges => ((ExampleEnvironment) Environment).Knowledges;
public IEnumerable<Knowledge> Knowledges => Environment.Organization.Knowledges;

/// <summary>
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
foreach (var knowledge in Knowledges)
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuMurphiesAndBlockers/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed class PersonAgent : Agent
public AgentId GroupId { get; set; }

private MurphyTask Model => ((ExampleEnvironment) Environment).Model;
public IEnumerable<Knowledge> Knowledges => ((ExampleEnvironment) Environment).Knowledges;
public IEnumerable<Knowledge> Knowledges => Environment.Organization.Knowledges;
public InternetAccessAgent Internet => ((ExampleEnvironment) Environment).Internet;

/// <summary>
Expand All @@ -66,7 +66,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
foreach (var knowledge in Knowledges)
Expand Down
22 changes: 13 additions & 9 deletions Symu examples/SymuScenariosAndEvents/Classes/ExampleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ExampleEnvironment : SymuEnvironment
public byte WorkersCount { get; set; } = 5;
private byte KnowledgeCount { get; } = 2;

public List<Knowledge> Knowledges { get; private set; }
public MurphyTask Model => Organization.Murphies.IncompleteKnowledge;

public override void SetOrganization(OrganizationEntity organization)
Expand All @@ -46,21 +45,27 @@ public override void SetOrganization(OrganizationEntity organization)
SetDebug(false);
}

public override void SetAgents()
/// <summary>
/// Add Organization knowledge
/// </summary>
public override void AddOrganizationKnowledges()
{
base.SetAgents();

base.AddOrganizationKnowledges();
// KnowledgeCount are added for tasks initialization
// Adn Beliefs are created based on knowledge
Knowledges = new List<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);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);
var knowledge = new Knowledge((ushort)i, i.ToString(), 10);
Organization.AddKnowledge(knowledge);
}

}

public override void SetAgents()
{
base.SetAgents();

var group = new GroupAgent(Organization.NextEntityIndex(), this);
_groupId = group.Id;
for (var j = 0; j < WorkersCount; j++)
Expand Down Expand Up @@ -94,7 +99,6 @@ public void KnowledgeEvent(object sender, EventArgs e)
// knowledge length of 10 is arbitrary in this example
var knowledge = new Knowledge(KnowledgeCount, KnowledgeCount.ToString(), 10);
WhitePages.Network.AddKnowledge(knowledge);
Knowledges.Add(knowledge);

foreach (var person in WhitePages.FilteredAgentsByClassKey(PersonAgent.ClassKey))
{
Expand Down
4 changes: 2 additions & 2 deletions Symu examples/SymuScenariosAndEvents/Classes/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public sealed class PersonAgent : Agent
public AgentId GroupId { get; set; }

private MurphyTask Model => ((ExampleEnvironment) Environment).Model;
public List<Knowledge> Knowledges => ((ExampleEnvironment) Environment).Knowledges;
public List<Knowledge> Knowledges => Environment.Organization.Knowledges;

/// <summary>
/// Customize the cognitive architecture of the agent
Expand All @@ -64,7 +64,7 @@ protected override void SetCognitive()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected override void SetModels()
public override void SetModels()
{
base.SetModels();
foreach (var knowledge in Knowledges)
Expand Down
17 changes: 12 additions & 5 deletions Symu source code/Symu/Classes/Agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ protected void SetDefaultModels()
/// Customize the models of the agent
/// After setting the Agent basics models
/// </summary>
protected virtual void SetModels()
public virtual void SetModels()
{
}

Expand All @@ -302,12 +302,19 @@ protected virtual void SetModels()
/// </summary>
protected void FinalizeModels()
{
KnowledgeModel.InitializeExpertise(Schedule.Step);
foreach (var agentKnowledge in KnowledgeModel.Expertise.List)
if (KnowledgeModel.On)
{
BeliefsModel.AddBelief(agentKnowledge.KnowledgeId);
KnowledgeModel.InitializeExpertise(Schedule.Step);
foreach (var agentKnowledge in KnowledgeModel.Expertise.List)
{
BeliefsModel.AddBelief(agentKnowledge.KnowledgeId);
}
}

if (BeliefsModel.On)
{
BeliefsModel.InitializeBeliefs();
}
BeliefsModel.InitializeBeliefs();
}

/// <summary>
Expand Down

0 comments on commit a6adeb8

Please sign in to comment.