public void TestCreationOfABazillionEECs() { Assert.Fail(); DateTime start = DateTime.Now; ExecutionEngineConfiguration eec = new ExecutionEngineConfiguration(); IProcedureFunctionChart pfc = CreatePfc(new Model(), "RootPfc", 15.0, eec); PfcExecutionContext pfcec = new PfcExecutionContext(pfc, "MyPfcExecutionContext_0", "", Guid.NewGuid(), null); while (nECs < nSteps) { Propagate(pfc, pfcec); } DateTime finish = DateTime.Now; Console.WriteLine("The test took " + ((TimeSpan)(finish - start)) + " to create " + nECs + " execution contexts."); }
public void TestSmallLoopbackHierarchical() { DateTime start = DateTime.Now; Model model = new Model("MyTestModel"); ExecutionEngineConfiguration eec = new ExecutionEngineConfiguration(); eec.ScanningPeriod = TimeSpan.FromSeconds(60.0); IProcedureFunctionChart pfc = CreatePfc(model, "RootPfc", 15.0, eec); IProcedureFunctionChart pfcChild1 = CreatePfc(model, "Step1Child", 15.0, eec); ((PfcStep)pfc.Nodes["RootPfc" + "Step1"]).AddAction("Alice", pfcChild1); IProcedureFunctionChart pfcGrandChild1 = CreatePfc(model, "Step1GrandChild", 15.0, eec); ((PfcStep)pfcChild1.Nodes["Step1Child" + "Step1"]).AddAction("Bob", pfcGrandChild1); PfcExecutionContext dictionary = new PfcExecutionContext(pfc, "MyPfcExecutionContext", "", Guid.NewGuid(), null); dictionary.Add("StringBuilder", new StringBuilder()); pfc.Model.Executive.RequestEvent(new ExecEventReceiver(pfc.Run), DateTime.MinValue, 0.0, dictionary, ExecEventType.Detachable); pfc.Model.Start(); int resultHashCode = dictionary["StringBuilder"].ToString().GetHashCode(); foreach (object obj in dictionary.Values) { if (obj is PfcExecutionContext) { Console.WriteLine(obj.ToString() + " contains " + ((PfcExecutionContext)obj).Values.Count + " members."); } } Console.WriteLine(dictionary["StringBuilder"]); DateTime finish = DateTime.Now; Console.WriteLine("The test took " + ((TimeSpan)(finish - start))); }
private IProcedureFunctionChart CreateRecipePfc(IModel model, string pfcName, double minutesPerTask, ExecutionEngineConfiguration eec) { // Start // | // +T1 ---- // | | | // ------- | // | | // Step1 | // | | // +T2 | // | | // Step2 | // | | // ------- | // T3+ +T4 | // | |--- // Finish // | // T5+ ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, pfcName); pfc.ExecutionEngineConfiguration = eec; pfc.CreateStep("Start", "", Guid.NewGuid()); pfc.CreateStep("Step1", "", Guid.NewGuid()); pfc.CreateStep("Step2", "", Guid.NewGuid()); pfc.CreateStep("Finish", "", Guid.NewGuid()); pfc.CreateTransition("T1", "", Guid.NewGuid()); pfc.CreateTransition("T2", "", Guid.NewGuid()); pfc.CreateTransition("T3", "", Guid.NewGuid()); pfc.CreateTransition("T4", "", Guid.NewGuid()); pfc.CreateTransition("T5", "", Guid.NewGuid()); pfc.Bind(pfc.Nodes["Start"], pfc.Nodes["T1"]); pfc.Bind(pfc.Nodes["T1"], pfc.Nodes["Step1"]); pfc.Bind(pfc.Nodes["Step1"], pfc.Nodes["T2"]); pfc.Bind(pfc.Nodes["T2"], pfc.Nodes["Step2"]); pfc.Bind(pfc.Nodes["Step2"], pfc.Nodes["T3"]); pfc.Bind(pfc.Nodes["Step2"], pfc.Nodes["T4"]); pfc.Bind(pfc.Nodes["T4"], pfc.Nodes["Step1"]); pfc.Bind(pfc.Nodes["T3"], pfc.Nodes["Finish"]); pfc.Bind(pfc.Nodes["Finish"], pfc.Nodes["T5"]); pfc.Steps.ForEach(delegate(IPfcStepNode psn) { psn.LeafLevelAction = new PfcAction(delegate(PfcExecutionContext pfcec, StepStateMachine ssm) { StringBuilder sb = (StringBuilder)pfcec["StringBuilder"]; string stepName = pfc.Name + "." + psn.Name; IExecutive exec = psn.Model.Executive; sb.AppendLine(string.Format("{0} : {1} is running its intrinsic action.", exec.Now, stepName)); exec.CurrentEventController.SuspendUntil(exec.Now + TimeSpan.FromMinutes(minutesPerTask)); }); }); pfc.Transitions["T1"].ExpressionExecutable = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition( delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) { IDictionary graphContext = userData as IDictionary; string countKey = pfc.Guid.ToString() + ".Count"; if (!((IDictionary)graphContext).Contains(countKey)) { ((IDictionary)graphContext).Add(countKey, 1); } else { graphContext[countKey] = 1; } return(DEFAULT_EXECUTABLE_EXPRESSION(graphContext, tsm)); }); pfc.Transitions["T3"].ExpressionExecutable = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition( delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) { IDictionary graphContext = userData as IDictionary; string countKey = pfc.Guid.ToString() + ".Count"; return(DEFAULT_EXECUTABLE_EXPRESSION(graphContext, tsm) && (((int)graphContext[countKey]) > 5)); }); pfc.Transitions["T4"].ExpressionExecutable = new Highpoint.Sage.Graphs.PFC.Execution.ExecutableCondition( delegate(object userData, Highpoint.Sage.Graphs.PFC.Execution.TransitionStateMachine tsm) { IDictionary graphContext = userData as IDictionary; string countKey = pfc.Guid.ToString() + ".Count"; if ((DEFAULT_EXECUTABLE_EXPRESSION(graphContext, tsm) && (((int)graphContext[countKey]) <= 5))) { graphContext[countKey] = ((int)graphContext[countKey]) + 1; return(true); } else { return(false); } }); pfc.UpdateStructure(); return(pfc); }
private IProcedureFunctionChart CreateSchedulePfc(IModel model, string pfcName, double minutesPerTask, ExecutionEngineConfiguration eec) { // Start // | // + T1 // | // Campaigns // | // + T2 // ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, pfcName); pfc.ExecutionEngineConfiguration = eec; pfc.CreateStep("Start", "", Guid.NewGuid()); pfc.CreateStep("Campaigns", "", Guid.NewGuid()); pfc.CreateTransition("T1", "", Guid.NewGuid()); pfc.CreateTransition("T2", "", Guid.NewGuid()); pfc.Bind(pfc.Nodes["Start"], pfc.Nodes["T1"]); pfc.Bind(pfc.Nodes["T1"], pfc.Nodes["Campaigns"]); pfc.Bind(pfc.Nodes["Campaigns"], pfc.Nodes["T2"]); pfc.UpdateStructure(); return(pfc); }
public ExecutionEngine(IProcedureFunctionChart pfc, ExecutionEngineConfiguration eec) { m_executionEngineConfiguration = eec; m_model = pfc.Model; m_stepStateMachines = new Dictionary <IPfcStepNode, StepStateMachine>(); m_transitionStateMachines = new Dictionary <IPfcTransitionNode, TransitionStateMachine>(); foreach (IPfcStepNode pfcStepNode in pfc.Steps) { StepStateMachine ssm = new StepStateMachine(pfcStepNode); ssm.StructureLocked = m_executionEngineConfiguration.StructureLockedDuringRun; m_stepStateMachines.Add(pfcStepNode, ssm); ssm.MyStep = pfcStepNode; ((PfcStep)pfcStepNode).MyStepStateMachine = ssm; } foreach (IPfcTransitionNode pfcTransNode in pfc.Transitions) { TransitionStateMachine tsm = new TransitionStateMachine(pfcTransNode); tsm.ScanningPeriod = m_executionEngineConfiguration.ScanningPeriod; m_transitionStateMachines.Add(pfcTransNode, tsm); tsm.MyTransition = pfcTransNode; ((PfcTransition)pfcTransNode).MyTransitionStateMachine = tsm; } StepStateMachineEvent ssme = new StepStateMachineEvent(anSSM_StepStateChanged); foreach (IPfcStepNode step in pfc.Steps) { step.MyStepStateMachine.StepStateChanged += ssme; foreach (IPfcTransitionNode transNode in step.SuccessorNodes) { step.MyStepStateMachine.SuccessorStateMachines.Add(transNode.MyTransitionStateMachine); } if (step.MyStepStateMachine.SuccessorStateMachines.Count == 0) { string message = $"Step {step.Name} in PFC {step.Parent.Name} has no successor transition. A PFC must end with a termination transition. (Did you acquire an Execution Engine while the Pfc was still under construction?)"; throw new ApplicationException(message); } } TransitionStateMachineEvent tsme = new TransitionStateMachineEvent(aTSM_TransitionStateChanged); foreach (IPfcTransitionNode trans in pfc.Transitions) { TransitionStateMachine thisTsm = m_transitionStateMachines[trans]; thisTsm.TransitionStateChanged += tsme; foreach (IPfcStepNode stepNode in trans.SuccessorNodes) { thisTsm.SuccessorStateMachines.Add(m_stepStateMachines[stepNode]); } foreach (IPfcStepNode stepNode in trans.PredecessorNodes) { thisTsm.PredecessorStateMachines.Add(m_stepStateMachines[stepNode]); } } List <IPfcStepNode> startSteps = pfc.GetStartSteps(); _Debug.Assert(startSteps.Count == 1); m_startStep = m_stepStateMachines[startSteps[0]]; }