Skip to content

Commit

Permalink
update IterationResult
Browse files Browse the repository at this point in the history
FollowTask
FollowBlocker
  • Loading branch information
lmorisse committed May 18, 2020
1 parent 2c86b73 commit 9968a7c
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public override void SetModelForAgents()
Organization.Models.Generator = RandomGenerator.RandomUniform;
Organization.Models.FollowGroupKnowledge = true;
Organization.Models.FollowGroupFlexibility = true;
Organization.Models.FollowTasks = true;
Organization.Models.InteractionSphere.On = true;
Organization.Models.InteractionSphere.SphereUpdateOverTime = true;
Organization.Models.InteractionSphere.FrequencyOfSphereUpdate = TimeStepType.Monthly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public bool Exists(int type, ushort step)
}

/// <summary>
/// Clear the list of blockers
/// Initialize the list of blockers
/// </summary>
public void Clear()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void DequeueStartedAgent()
}

/// <summary>
/// Clear the class
/// Initialize the class
/// </summary>
public void Clear()
{
Expand Down
5 changes: 3 additions & 2 deletions Symu source code/SymuEngine/Environment/SymuEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ public virtual void InitializeIteration()
{
Messages.Clear();
State.Clear();
IterationResult.Clear();
WhitePages.Clear();
WhitePages.Network.NetworkKnowledges.Model =
Organization.Models.Generator;
WhitePages.Network.NetworkBeliefs.Model =
Organization.Models.Generator;
SetModelForAgents();
// Intentionally after SetModelForAgents
IterationResult.Initialize();
WhitePages.Network.InitializeNetworkLinks();
WhitePages.SetStarted();
}
Expand Down Expand Up @@ -373,7 +374,7 @@ public void PostStep()
{
WhitePages.AllAgents().ToList().ForEach(a => a.PostStep());
Messages.ClearMessagesSent(TimeStep.Step);
IterationResult.PostStep(TimeStep.Step);
IterationResult.PostStep();
TimeStep.Step++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void IncrementMessagesPerPeriod(CommunicationMediums messageType, bool se
}

/// <summary>
/// Clear numberMessagesPerPeriod done at the beginning of every new period (interaction step)
/// Initialize numberMessagesPerPeriod done at the beginning of every new period (interaction step)
/// </summary>
public void ClearMessagesPerPeriod()
{
Expand Down
2 changes: 1 addition & 1 deletion Symu source code/SymuEngine/Repository/Networks/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Network(AgentTemplates agentTemplates, OrganizationModels models)
/// </summary>
public InteractionSphere InteractionSphere { get; }

#region Clear & remove Agents
#region Initialize & remove Agents

public void Clear()
{
Expand Down
2 changes: 1 addition & 1 deletion Symu source code/SymuEngine/Repository/WhitePages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public WhitePages(AgentTemplates agentTemplates, OrganizationModels models)

public Network Network { get; }

#region Clear / remove agent
#region Initialize / remove agent

/// <summary>
/// CLear agents between two iterations
Expand Down
11 changes: 11 additions & 0 deletions Symu source code/SymuEngine/Results/Blocker/BlockerResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ namespace SymuEngine.Results.Blocker
/// </summary>
public class BlockerResults
{
/// <summary>
/// If set to true, blockerResults will be filled with value
/// </summary>
private readonly bool _followBlockers;
public BlockerResults(bool followBlockers)
{
_followBlockers = followBlockers;
}
/// <summary>
/// Key => step
/// Value => BlockerResult for the step
Expand Down Expand Up @@ -61,12 +69,15 @@ public class BlockerResults

public void AddBlockerInProgress(ushort step)
{
if (!_followBlockers) { return;}
SetStep(step);
_results[step].InProgress++;
}

public void BlockerDone(BlockerResolution resolution, ushort step)
{
if (!_followBlockers) { return; }

SetStep(step);
switch (resolution)
{
Expand Down
14 changes: 6 additions & 8 deletions Symu source code/SymuEngine/Results/IterationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public IterationResult(SymuEnvironment environment)
/// The important factor is how fast the organizations reaches this state and what happens along the way
/// Focus on the time at which stability is reached
/// In nonlinear stochastics systems with noise, a standard measure is the 90 % point (90% of its final theoretical)
/// value)
/// </summary>
public OrganizationFlexibility OrganizationFlexibility { get; private set; }

Expand All @@ -59,25 +58,25 @@ public IterationResult(SymuEnvironment environment)
/// <summary>
/// Get the Task blockers metrics
/// </summary>
public BlockerResults Blockers { get; private set; }
public BlockerResults Blockers { get; private set; }

/// <summary>
/// Get the Tasks model metrics
/// </summary>
public TaskResults Tasks { get; private set; }
public TaskResults Tasks { get; private set; }

public float Capacity { get; set; }

//Specific results
public List<PostProcessResult> SpecificResults { get; } = new List<PostProcessResult>();

public virtual void Clear()
public virtual void Initialize()
{
OrganizationFlexibility = new OrganizationFlexibility(_environment);
OrganizationKnowledgeAndBelief = new OrganizationKnowledgeAndBelief(_environment.WhitePages.Network,
_environment.Organization.Models);
Blockers = new BlockerResults();
Tasks = new TaskResults();
Blockers = new BlockerResults(_environment.Organization.Models.FollowBlockers);
Tasks = new TaskResults(_environment.Organization.Models.FollowTasks);
Iteration = 0;
Step = 0;
Success = false;
Expand All @@ -92,8 +91,7 @@ public virtual void Clear()
/// Triggered at each end of step by SymuEnvironment.
/// Use to process metrics
/// </summary>
/// <param name="step"></param>
public void PostStep(ushort step)
public void PostStep()
{
Tasks.SetResults(_environment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public OrganizationKnowledgeAndBelief(Network network, OrganizationModels models
public List<KnowledgeAndBeliefStruct> KnowledgeObsolescence { get; } = new List<KnowledgeAndBeliefStruct>();

/// <summary>
/// Clear of results
/// Initialize of results
/// </summary>
public void Clear()
{
Expand Down
9 changes: 9 additions & 0 deletions Symu source code/SymuEngine/Results/Task/TaskResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ namespace SymuEngine.Results.Task
/// </summary>
public class TaskResults
{
/// <summary>
/// If set to true, TaskResults will be filled with value
/// </summary>
private readonly bool _followTasks;
public TaskResults(bool followTasks)
{
_followTasks = followTasks;
}
/// <summary>
/// Key => step
/// Value => TaskResult for the step
Expand Down Expand Up @@ -59,6 +67,7 @@ public class TaskResults

public void SetResults(SymuEnvironment environment)
{
if (!_followTasks) { return; }
if (environment == null)
{
throw new ArgumentNullException(nameof(environment));
Expand Down
14 changes: 14 additions & 0 deletions Symu source code/SymuEngineTests/Classes/Agents/AgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SymuEngine.Classes.Agents.Models.CognitiveModel;
using SymuEngine.Classes.Agents.Models.Templates.Communication;
using SymuEngine.Classes.Organization;
using SymuEngine.Classes.Task;
using SymuEngine.Common;
using SymuEngine.Engine;
using SymuEngine.Messaging.Messages;
Expand Down Expand Up @@ -1249,5 +1250,18 @@ public void AcceptNewInteractionTest5()
}

#endregion

#region blocker
[TestMethod]
public void AddBlockerTest()
{
_environment.Organization.Models.FollowBlockers = true;
_environment.IterationResult.Initialize();
var task = new SymuTask(0);
Assert.IsNotNull(_agent.AddBlocker(task, 0, 1, 0));
Assert.IsTrue(task.IsBlocked);
Assert.AreEqual(1, _environment.IterationResult.Blockers.BlockersStillInProgress);
}
#endregion
}
}

0 comments on commit 9968a7c

Please sign in to comment.