public async Task <bool> TryOptimize(bool setInitialValue, SimSpecs sim) { if (Equation == null) { return(true); } // No variables or itself var canBeOptimized = !Children.Any() && Equation.CanBeOptimized(FullName); if (!canBeOptimized) { return(Equation == null); } if (setInitialValue) { if (Equation.Variables.Count == 1 && Equation.Variables[0] == FullName) { Equation.Replace(FullName, Value.ToString(CultureInfo.InvariantCulture)); } var value = await Equation.InitialValue(Model); AdjustValue(value); } Equation = null; return(true); }
public void SimSpecsTest() { _sim = new SimSpecs(10, 100); Assert.AreEqual(10, _sim.Start); Assert.AreEqual <uint>(0, _sim.Step); Assert.AreEqual(100, _sim.Stop); }
public void RunTest5() { _sim = new SimSpecs(0, 0); while (_sim.Run()) { } Assert.AreEqual(0, _sim.Time); Assert.AreEqual <uint>(0, _sim.Step); }
public void Prepare(IVariable selfVariable, VariableCollection variables, SimSpecs sim) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } foreach (var variable in Variables.Where(variables.Exists)) { Expression.Parameters[variable] = variables[variable].Value; } }
public async Task Update(VariableCollection variables, SimSpecs simulation) { if (Updated) { return; } var eval = await Equation.Evaluate(this, variables, simulation); AdjustValue(eval); Updated = true; }
public void RunTest6() { _sim = new SimSpecs(0, 0) { DeltaTime = 0.25F }; while (_sim.Run()) { } Assert.AreEqual(0, _sim.Time); Assert.AreEqual <uint>(0, _sim.Step); }
public async Task <float> Evaluate(IVariable selfVariable, VariableCollection variables, SimSpecs sim) { try { Prepare(selfVariable, variables, sim); return(Convert.ToSingle(await Expression.EvaluateAsync(sim?.Time, sim?.Step, sim?.DeltaTime))); } catch (ArgumentException ex) { throw new ArgumentException(" the internal details for this exception are as follows: \r\n" + ex.Message); } //todo Trace.WriteLineIf(World.LoggingSwitch.TraceVerbose, equation + "was calculate"); }
public async Task <bool> TryOptimize(bool setInitialValue, SimSpecs sim) { return(true); }
public async Task Update(VariableCollection variables, SimSpecs simulation) { // }
public void ClearTest() { _sim = new SimSpecs(10, 100, 0.5F); _sim.Clear(); Assert.AreEqual <uint>(20, _sim.Step); }