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 void Test_InsertStepAndTransition() { Model model = new Model("SFC Test 1"); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid()); IPfcStepNode t0 = pfc.CreateStep("START", "", Guid.Empty); IPfcStepNode t1 = pfc.CreateStep("FINISH", "", Guid.Empty); pfc.Bind(t0, t1); string structureString = PfcDiagnostics.GetStructure(pfc); Console.WriteLine("Structure is \r\n" + structureString); // Get reference to old successor IPfcNode pfcNode = pfc.Nodes["T_000"]; IPfcNode oldSuccessorNode = pfcNode.SuccessorNodes[0]; // Add the step IPfcStepNode newStep = pfc.CreateStep("STEP_1", "", Guid.Empty); IPfcTransitionNode newTrans = pfc.CreateTransition(); // We are adding a step following a transition - binding is from selectedTrans-newStep-newTrans-oldSuccessorStep pfc.Bind(pfcNode, newStep); pfc.Bind(newStep, newTrans); pfc.Bind(newTrans, oldSuccessorNode); // Disconnect old successor pfc.Unbind(pfcNode, oldSuccessorNode); structureString = PfcDiagnostics.GetStructure(pfc); Console.WriteLine("Structure is \r\n" + structureString); Assert.IsTrue(structureString.Equals("{START-->[L_000(SFC 1.Root)]-->T_000}\r\n{T_000-->[L_002(SFC 1.Root)]-->STEP_1}\r\n{STEP_1-->[L_003(SFC 1.Root)]-->T_001}\r\n{T_001-->[L_004(SFC 1.Root)]-->FINISH}\r\n")); }
private void _TestTransitionToTransitionBinding() { string testName = "Transition-to-Transition binding, maintaining SFC Compliance"; Model model = new Model("SFC Test 1"); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid()); IPfcTransitionNode s1 = pfc.CreateTransition("Alice", "", Guid.Empty); IPfcTransitionNode s2 = pfc.CreateTransition("Bob", "", Guid.Empty); //IPfcTransitionNode s3 = pfc.CreateTransition("Charlie", "", Guid.Empty); pfc.Bind(s1, s2); string structureString = PfcDiagnostics.GetStructure(pfc); Console.WriteLine("After a " + testName + ", structure is \r\n" + structureString); }
private IPfcNode CreateNode(ProcedureFunctionChart pfc, string name, PfcElementType inType) { switch (inType) { case PfcElementType.Link: break; case PfcElementType.Transition: return(pfc.CreateTransition("T_" + name, "", Guid.NewGuid())); //break; case PfcElementType.Step: return(pfc.CreateStep("S_" + name, "", Guid.NewGuid())); //break; default: break; } return(null); }
public void Test_SynchronizerConstruct_Transitions() { Model model = new Model("SFC Test 1"); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid()); IPfcTransitionNode t0 = pfc.CreateTransition("T_Alice", "", Guid.Empty); IPfcTransitionNode t1 = pfc.CreateTransition("T_Bob", "", Guid.Empty); IPfcTransitionNode t2 = pfc.CreateTransition("T_Charley", "", Guid.Empty); IPfcTransitionNode t3 = pfc.CreateTransition("T_David", "", Guid.Empty); IPfcTransitionNode t4 = pfc.CreateTransition("T_Edna", "", Guid.Empty); IPfcTransitionNode t5 = pfc.CreateTransition("T_Frank", "", Guid.Empty); IPfcTransitionNode t6 = pfc.CreateTransition("T_Gary", "", Guid.Empty); IPfcTransitionNode t7 = pfc.CreateTransition("T_Hailey", "", Guid.Empty); pfc.Synchronize(new IPfcTransitionNode[] { t0, t1, t2, t3 }, new IPfcTransitionNode[] { t4, t5, t6, t7 }); string structureString = PfcDiagnostics.GetStructure(pfc); string shouldBe = "{T_Alice-->[L_000(SFC 1.Root)]-->S_000}\r\n{S_000-->[L_001(SFC 1.Root)]-->T_000}\r\n{T_Bob-->[L_002(SFC 1.Root)]-->S_001}\r\n{S_001-->[L_003(SFC 1.Root)]-->T_000}\r\n{T_Charley-->[L_004(SFC 1.Root)]-->S_002}\r\n{S_002-->[L_005(SFC 1.Root)]-->T_000}\r\n{T_David-->[L_006(SFC 1.Root)]-->S_003}\r\n{S_003-->[L_007(SFC 1.Root)]-->T_000}\r\n{T_000-->[L_008(SFC 1.Root)]-->S_004}\r\n{S_004-->[L_009(SFC 1.Root)]-->T_Edna}\r\n{T_000-->[L_010(SFC 1.Root)]-->S_005}\r\n{S_005-->[L_011(SFC 1.Root)]-->T_Frank}\r\n{T_000-->[L_012(SFC 1.Root)]-->S_006}\r\n{S_006-->[L_013(SFC 1.Root)]-->T_Gary}\r\n{T_000-->[L_014(SFC 1.Root)]-->S_007}\r\n{S_007-->[L_015(SFC 1.Root)]-->T_Hailey}\r\n"; Console.WriteLine("After a synchronization of transitions, structure is \r\n" + structureString); Assert.AreEqual(structureString, shouldBe, "Structure should have been\r\n" + shouldBe + "\r\nbut it was\r\n" + structureString + "\r\ninstead."); if (m_runSFCs) { TestEvaluator testEvaluator = new TestEvaluator(new IPfcTransitionNode[] { t0, t1, t2, t3, t4, t5, t6, t7 }); testEvaluator.NextExpectedActivations = new IPfcTransitionNode[] { t0, t1, t2, t3, t4, t5, t6, t7 }; foreach (IPfcNode ilinkable in new IPfcTransitionNode[] { t0, t1, t2, t3 }) { Console.WriteLine("Incrementing " + ilinkable.Name + "."); //ilinkable.Increment(); throw new ApplicationException("PFCs are not currently executable."); } testEvaluator.NextExpectedActivations = new IPfcTransitionNode[] { }; // Ensure it's empty and all have fired. } }
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); }
public void Test_InsertStepIntoLoop() { string testName = "PFC with loop gets the loop extended"; /* * START * | * |---- +T1 * | | | * | STEP1 * | | | * | T2+ +T3 * ----| | * FINISH * * TO * * START * | * |---- +T1 * | | | * | STEP1 * | | | * | T4+ +T3 * | | | * | STEP2 FINISH * | | * | T2+ * ----- * */ IModel model = new Model(testName); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, testName); IPfcNode startStep = pfc.CreateStep("START", string.Empty, Guid.NewGuid()); IPfcNode step1 = pfc.CreateStep("STEP1", string.Empty, Guid.NewGuid()); IPfcNode step2 = pfc.CreateStep("STEP2", string.Empty, Guid.NewGuid()); IPfcNode finishStep = pfc.CreateStep("FINISH", string.Empty, Guid.NewGuid()); IPfcNode t1 = pfc.CreateTransition("T1", string.Empty, Guid.NewGuid()); IPfcNode t2 = pfc.CreateTransition("T2", string.Empty, Guid.NewGuid()); IPfcNode t3 = pfc.CreateTransition("T3", string.Empty, Guid.NewGuid()); IPfcNode t4 = pfc.CreateTransition("T4", string.Empty, Guid.NewGuid()); pfc.Bind(startStep, t1); pfc.Bind(t1, step1); pfc.Bind(step1, t2); pfc.Bind(step1, t3); pfc.Bind(t2, step1); pfc.Bind(t3, finishStep); Console.WriteLine(PfcDiagnostics.GetStructure(pfc)); Console.WriteLine(); /* Connect new step (step2) to existing transition (t2) */ pfc.Bind(step2, t2); /* Connect existing step (step1) to new transition (t3)*/ pfc.Bind(step1, t4); /* Connect new transition (t3) to new step (step2)*/ pfc.Bind(t4, step2); /* Unbind existing step (step1) and existing transition (t2) */ pfc.Unbind(step1, t2); string result = PfcDiagnostics.GetStructure(pfc); Console.WriteLine(result); Assert.IsTrue(result.Equals("{START-->[L_000(SFC 1.Root)]-->T1}\r\n{T1-->[L_001(SFC 1.Root)]-->STEP1}\r\n{STEP1-->[L_003(SFC 1.Root)]-->T3}\r\n{T2-->[L_004(SFC 1.Root)]-->STEP1}\r\n{T3-->[L_005(SFC 1.Root)]-->FINISH}\r\n{STEP2-->[L_006(SFC 1.Root)]-->T2}\r\n{STEP1-->[L_007(SFC 1.Root)]-->T4}\r\n{T4-->[L_008(SFC 1.Root)]-->STEP2}\r\n")); }
public void Test_RemoveStep() { string testName = "PFC With Simultaneous Branch"; IModel model = new Model(testName); /* * START * + {T1} * STEP1 * + (T2) * STEP2 STEP3 * | + (T3) * | STEP4 * + (T4) * STEP5 * + (T5) * FINISH */ ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, testName); IPfcNode startStep = pfc.CreateStep("START", string.Empty, Guid.NewGuid()); IPfcNode step1 = pfc.CreateStep("STEP1", string.Empty, Guid.NewGuid()); IPfcNode step2 = pfc.CreateStep("STEP2", string.Empty, Guid.NewGuid()); IPfcNode step3 = pfc.CreateStep("STEP3", string.Empty, Guid.NewGuid()); IPfcNode step4 = pfc.CreateStep("STEP4", string.Empty, Guid.NewGuid()); IPfcNode step5 = pfc.CreateStep("STEP5", string.Empty, Guid.NewGuid()); IPfcNode finishStep = pfc.CreateStep("FINISH", string.Empty, Guid.NewGuid()); IPfcNode t1 = pfc.CreateTransition("T1", string.Empty, Guid.NewGuid()); IPfcNode t2 = pfc.CreateTransition("T2", string.Empty, Guid.NewGuid()); IPfcNode t3 = pfc.CreateTransition("T3", string.Empty, Guid.NewGuid()); IPfcNode t4 = pfc.CreateTransition("T4", string.Empty, Guid.NewGuid()); IPfcNode t5 = pfc.CreateTransition("T4", string.Empty, Guid.NewGuid()); pfc.Bind(startStep, t1); pfc.Bind(t1, step1); pfc.Bind(step1, t2); pfc.Bind(t2, step2); pfc.Bind(t2, step3); pfc.Bind(step2, t4); pfc.Bind(step3, t3); pfc.Bind(t3, step4); pfc.Bind(step4, t4); pfc.Bind(t4, step5); pfc.Bind(step5, t5); pfc.Bind(t5, finishStep); /* Delete Step4 and T3*/ // Need to delete the predecessor transition IPfcTransitionNode predecessorTrans = (IPfcTransitionNode)step4.PredecessorNodes[0]; Assert.IsTrue(predecessorTrans.Name == t3.Name, "The predecessor trans should be T3"); IPfcStepNode predecessorStep = (IPfcStepNode)predecessorTrans.PredecessorNodes[0]; Assert.IsTrue(predecessorStep.Name == step3.Name, "The predecessor step should be STEP3"); IPfcTransitionNode successorTrans = (IPfcTransitionNode)step4.SuccessorNodes[0]; Assert.IsTrue(successorTrans.Name == t4.Name, "The successor trans should be T4"); // Connect the predecessor step to the successor transition pfc.Bind(predecessorStep, successorTrans); // Unbind the existing path from the predecessor step to the successor transition pfc.Unbind(predecessorStep, predecessorTrans); pfc.Unbind(predecessorTrans, step4); pfc.Unbind(step4, successorTrans); // Delete the predecessor transition pfc.Delete(predecessorTrans); // Delete step pfc.Delete(step4); Assert.IsTrue(pfc.Transitions[t3.Name] == null, "T3 Should be Deleted"); Assert.IsTrue(pfc.Steps[step4.Name] == null, "Step4 Should be Deleted"); }
public void TestSequencers() { Model model = new Model("MyTestModel"); ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "RootPfc"); pfc.ExecutionEngineConfiguration = new ExecutionEngineConfiguration(); // Start // | // + T_Start // | // ===================================== // | | | | | // Step0 Step1 Step2 Step3 Step4 // | | | | | // ===================================== // | // + Finis // // (We want to run these in order "Step3", "Step1", "Step4", "Step2", "Step0") #region Create PFC IPfcStepNode start = pfc.CreateStep("Start", null, Guid.NewGuid()); IPfcTransitionNode startTrans = pfc.CreateTransition("T_Start", null, Guid.NewGuid()); pfc.Bind(start, startTrans); IPfcTransitionNode finis = pfc.CreateTransition("Finish", null, Guid.NewGuid()); for (int i = 0; i < 5; i++) { IPfcStepNode step = pfc.CreateStep("Step" + i, null, Guid.NewGuid()); pfc.Bind(startTrans, step); pfc.Bind(step, finis); } #endregion Create PFC Guid sequencerKey = Guid.NewGuid(); string[] stepSeq = new string[] { "Step4", "Step3", "Step2", "Step1", "Step0" }; for (int n = 0; n < 10; n++) { Console.WriteLine("\r\n\r\n========================================================\r\nStarting test iteration # " + n + ":\r\n"); stepSeq = Shuffle(stepSeq); Console.WriteLine("Expecting sequence " + StringOperations.ToCommasAndAndedList(new List <string>(stepSeq))); int j = 0; StringBuilder sb = new StringBuilder(); foreach (string stepNodeName in stepSeq) { IPfcStepNode step = pfc.Steps[stepNodeName]; step.Precondition = new Sequencer(sequencerKey, j++).Precondition; step.LeafLevelAction = new PfcAction(delegate(PfcExecutionContext pfcec, StepStateMachine ssm) { sb.Append("Running " + ssm.MyStep.Name + " "); }); } model.Executive.RequestEvent( new ExecEventReceiver(pfc.Run), DateTime.MinValue, 0.0, new PfcExecutionContext(pfc, "PFCEC", null, Guid.NewGuid(), null), ExecEventType.Detachable); pfc.Model.Start(); Console.Out.Flush(); string tgtString = string.Format(@"Running {0} Running {1} Running {2} Running {3} Running {4} ", stepSeq[0], stepSeq[1], stepSeq[2], stepSeq[3], stepSeq[4]); System.Diagnostics.Debug.Assert(sb.ToString().Equals(tgtString)); pfc.Model.Executive.Reset(); Console.WriteLine("========================================================"); } }