예제 #1
0
        /// <summary>
        ///     Take a variable and update the value of that node
        /// </summary>
        /// <param name="variable"></param>
        /// <param name="sim"></param>
        public async Task <bool> TryOptimizeVariable(IVariable variable, SimSpecs sim)
        {
            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable));
            }


            if (await variable.TryOptimize(false, sim) || variable.Equation.Expression?.ParsedExpression == null)
            {
                return(true);
            }

            foreach (var childName in variable.Children.Where(x => !Variables.Exists(x)).ToImmutableList())
            {
                if (!ReferenceVariables.ContainsKey(childName))
                {
                    // For Time & Dt
                    continue;
                }

                var childValue = ReferenceVariables[childName].ToString(CultureInfo.InvariantCulture);
                variable.Equation.Replace(childName, childValue);
                variable.Children.Remove(childName);
            }

            variable.Updated = true;
            return(await variable.TryOptimize(true, sim));
        }
예제 #2
0
 /// <summary>
 ///     Create an instance of the state machine from an xml File
 ///     The stateMachine is Not Initialized - you have to call Initialize after having filled the variables
 /// </summary>
 public StateMachine()
 {
     Models              = new ModelCollection();
     Simulation          = new SimSpecs();
     Simulation.OnTimer += OnTimer;
 }