private IReadOnlyList <VariableValue> EvaluateParameters(IReadOnlyList <string> parameterExpressions) { if (parameterExpressions is not null && parameterExpressions.Count > 0) { List <VariableValue> values = new List <VariableValue>(parameterExpressions.Count); for (int i = 0; i < parameterExpressions.Count; i++) { values.Add(ScriptingHost.Evaluate(parameterExpressions[i])); } return(values); } return(null); }
private void InternalStep() { // Get next event ScheduledEvent nextEvent = Schedule.GetNext(); OnVertexFiring(nextEvent.Target); // Update internal variables Clock = nextEvent.Time; EventCount[Graph.Verticies.IndexOf(nextEvent.Target)]++; // Assign parameters AssignParameters(nextEvent.Target, nextEvent.ParameterValues); // Execute event ScriptingHost.Execute(nextEvent.Target.Code); // Evaluate trace variables EvaluateTraces(); OnVertexFired(nextEvent.Target); // Evaluate edges for (int i = 0; i < Graph.Edges.Count; i++) { if (Graph.Edges[i].Source == nextEvent.Target) { Edge edge = Graph.Edges[i]; // Check condition if (ScriptingHost.Evaluate(edge.Condition, VariableValue.True).AsBoolean()) { OnEdgeFiring(edge); // Evaluate parameters IReadOnlyList <VariableValue> parameterValues = EvaluateParameters(edge.ParameterExpressions); switch (edge.Action) { case EdgeAction.Schedule: double time = Clock + ScriptingHost.Evaluate(edge.Delay, new VariableValue(Schedule.DefaultDelay)).AsNumber(); double priority = ScriptingHost.Evaluate(edge.Priority, new VariableValue(Schedule.DefaultPriority)).AsNumber(); Schedule.Insert(edge.Target, time, priority, parameterValues); break; case EdgeAction.CancelNext: Schedule.CancelNext(edge.Target, parameterValues); break; case EdgeAction.CancelAll: Schedule.CancelAll(edge.Target, parameterValues); break; } OnEdgeFired(edge); } } } if (!KeepGoing()) { State = SimulationState.Complete; } }