From 42337ac215601f69540abfec48bce375580afc16 Mon Sep 17 00:00:00 2001 From: lmorisse Date: Fri, 30 Oct 2020 14:57:27 +0100 Subject: [PATCH] Add Fidelity Level --- SourceCode/Symu/Engine/Fidelity.cs | 21 +++++++++++++++ .../Symu/Environment/SymuEnvironment.cs | 23 ++++++++++++++-- SourceCode/Symu/Environment/SysDynModel.cs | 27 ++++++++++++++----- SourceCode/SymuForm/SymuForm.cs | 13 ++++++++- SourceCode/SymuTests/Resources/sysdyn.xmile | 2 +- 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 SourceCode/Symu/Engine/Fidelity.cs diff --git a/SourceCode/Symu/Engine/Fidelity.cs b/SourceCode/Symu/Engine/Fidelity.cs new file mode 100644 index 00000000..bb47127b --- /dev/null +++ b/SourceCode/Symu/Engine/Fidelity.cs @@ -0,0 +1,21 @@ +#region Licence + +// 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 + +#endregion + +namespace Symu.Engine +{ + /// + /// Level of fidelity of the simulation + /// + public enum Fidelity + { + Low = 0, + Medium= 1, + High = 2 + } +} \ No newline at end of file diff --git a/SourceCode/Symu/Environment/SymuEnvironment.cs b/SourceCode/Symu/Environment/SymuEnvironment.cs index 10af7423..ea804e13 100644 --- a/SourceCode/Symu/Environment/SymuEnvironment.cs +++ b/SourceCode/Symu/Environment/SymuEnvironment.cs @@ -43,7 +43,7 @@ public SymuEnvironment() { IterationResult = new IterationResult(this); SysDynModel = new SysDynModel(); - SysDynModel.SetSimulation(0.25F, 1, Schedule.Type); + SysDynModel.SetSimulation(Fidelity, 1, Schedule.Type); } /// @@ -94,6 +94,10 @@ public SymuEnvironment() /// Define level of random for the simulation. /// public RandomLevel RandomLevel { get; set; } = RandomLevel.NoRandom; + /// + /// Define level of fidelity of the simulation. + /// + public Fidelity Fidelity { get; set; } = Fidelity.Low; public byte RandomLevelValue => (byte) RandomLevel; @@ -115,6 +119,21 @@ public void SetRandomLevel(int level) break; } } + public void SetFidelity(int level) + { + switch (level) + { + default: + Fidelity= Fidelity.Low; + break; + case 1: + Fidelity = Fidelity.Medium; + break; + case 2: + Fidelity = Fidelity.High; + break; + } + } #region Events @@ -220,7 +239,7 @@ public virtual void InitializeIteration() Messages.Clear(); //At this point, we must use Environment.Organization.MetaNetwork and not Organization.MetaNetwork MainOrganization = MainOrganizationReference.Clone(); - SysDynModel.Clear(); + SysDynModel.Initialize(); WhitePages.Clear(); IterationResult.Initialize(); SetAgents(); diff --git a/SourceCode/Symu/Environment/SysDynModel.cs b/SourceCode/Symu/Environment/SysDynModel.cs index 799a41e4..085d4aeb 100644 --- a/SourceCode/Symu/Environment/SysDynModel.cs +++ b/SourceCode/Symu/Environment/SysDynModel.cs @@ -16,6 +16,7 @@ using Symu.Classes.Agents; using Symu.Common.Classes; using Symu.Common.Interfaces; +using Symu.Engine; using Symu.SysDyn; using Symu.SysDyn.Model; using Symu.SysDyn.Simulation; @@ -33,7 +34,7 @@ public class SysDynModel private readonly List _variableAgent = new List(); public SysDynModel() { - throw new NotImplementedException(); + _stateMachine = new StateMachine {Optimized = true}; } public SysDynModel(string xmlFile) { @@ -88,19 +89,31 @@ public float GetVariable(string variableName) /// Set the simulation /// /// - /// + /// /// - public void SetSimulation(float deltaTime, ushort pauseInterval, TimeStepType timeUnits) + public void SetSimulation(Fidelity fidelity, ushort pauseInterval, TimeStepType timeUnits) { - _stateMachine.Simulation.DeltaTime = deltaTime; + switch (fidelity) + { + case Fidelity.Low: + _stateMachine.Simulation.DeltaTime = 0.5F; + break; + case Fidelity.Medium: + _stateMachine.Simulation.DeltaTime = 0.25F; + break; + case Fidelity.High: + _stateMachine.Simulation.DeltaTime = 0.125F; + break; + default: + throw new ArgumentOutOfRangeException(nameof(fidelity), fidelity, null); + } _stateMachine.Simulation.PauseInterval = pauseInterval; _stateMachine.Simulation.TimeUnits = timeUnits; } - public void Clear() + public void Initialize() { - _stateMachine.Simulation.Clear(); - _stateMachine.Results.Clear(); + _stateMachine.Initialize(); } } } \ No newline at end of file diff --git a/SourceCode/SymuForm/SymuForm.cs b/SourceCode/SymuForm/SymuForm.cs index adb260f5..03be53f2 100644 --- a/SourceCode/SymuForm/SymuForm.cs +++ b/SourceCode/SymuForm/SymuForm.cs @@ -354,11 +354,22 @@ protected void SetDelay(int value) { Engine.Environment.SetDelay(value); } - + /// + /// Level of stochastic random + /// + /// protected void SetRandomLevel(int value) { Engine.Environment.SetRandomLevel(value); } + /// + /// Level of fidelity of the simulation + /// + /// + protected void SetFidelity(int value) + { + Engine.Environment.SetFidelity(value); + } protected void SetTimeStepType(TimeStepType type) { diff --git a/SourceCode/SymuTests/Resources/sysdyn.xmile b/SourceCode/SymuTests/Resources/sysdyn.xmile index 07824df1..b20371ab 100644 --- a/SourceCode/SymuTests/Resources/sysdyn.xmile +++ b/SourceCode/SymuTests/Resources/sysdyn.xmile @@ -5,7 +5,7 @@ SysDyn Symu - + 0 12
0.25