Skip to content

Commit

Permalink
Add Fidelity Level
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorisse committed Oct 30, 2020
1 parent 45083db commit 42337ac
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
21 changes: 21 additions & 0 deletions 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
{
/// <summary>
/// Level of fidelity of the simulation
/// </summary>
public enum Fidelity
{
Low = 0,
Medium= 1,
High = 2
}
}
23 changes: 21 additions & 2 deletions SourceCode/Symu/Environment/SymuEnvironment.cs
Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -94,6 +94,10 @@ public SymuEnvironment()
/// Define level of random for the simulation.
/// </summary>
public RandomLevel RandomLevel { get; set; } = RandomLevel.NoRandom;
/// <summary>
/// Define level of fidelity of the simulation.
/// </summary>
public Fidelity Fidelity { get; set; } = Fidelity.Low;

public byte RandomLevelValue => (byte) RandomLevel;

Expand All @@ -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

Expand Down Expand Up @@ -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();
Expand Down
27 changes: 20 additions & 7 deletions SourceCode/Symu/Environment/SysDynModel.cs
Expand Up @@ -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;
Expand All @@ -33,7 +34,7 @@ public class SysDynModel
private readonly List<SysDynVariableAgent> _variableAgent = new List<SysDynVariableAgent>();
public SysDynModel()
{
throw new NotImplementedException();
_stateMachine = new StateMachine {Optimized = true};
}
public SysDynModel(string xmlFile)
{
Expand Down Expand Up @@ -88,19 +89,31 @@ public float GetVariable(string variableName)
/// Set the simulation
/// </summary>
/// <param name="pauseInterval"></param>
/// <param name="deltaTime"></param>
/// <param name="fidelity"></param>
/// <param name="timeUnits"></param>
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();
}
}
}
13 changes: 12 additions & 1 deletion SourceCode/SymuForm/SymuForm.cs
Expand Up @@ -354,11 +354,22 @@ protected void SetDelay(int value)
{
Engine.Environment.SetDelay(value);
}

/// <summary>
/// Level of stochastic random
/// </summary>
/// <param name="value"></param>
protected void SetRandomLevel(int value)
{
Engine.Environment.SetRandomLevel(value);
}
/// <summary>
/// Level of fidelity of the simulation
/// </summary>
/// <param name="value"></param>
protected void SetFidelity(int value)
{
Engine.Environment.SetFidelity(value);
}

protected void SetTimeStepType(TimeStepType type)
{
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/SymuTests/Resources/sysdyn.xmile
Expand Up @@ -5,7 +5,7 @@
<name>SysDyn</name>
<vendor>Symu</vendor>
</header>
<sim_specs method="Euler" time_units="Time">
<sim_specs method="Euler" time_units="Daily">
<start>0</start>
<stop>12</stop>
<dt>0.25</dt>
Expand Down

0 comments on commit 42337ac

Please sign in to comment.