コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateLoopTestPfc()
        {
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "SFC 1");

            #region Create Nodes

            A = pfc.CreateStep("Step_A", "", Guid.NewGuid());
            B = pfc.CreateStep("Step_B", "", Guid.NewGuid());
            C = pfc.CreateStep("Step_C", "", Guid.NewGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;

            #endregion Create Nodes

            #region Create Structure

            pfc.Bind(nA, nB);
            pfc.Bind(nB, nC);
            pfc.Bind(nB, nB);

            #endregion Create Structure

            return(pfc);
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        public static Dictionary <IPfcNode, int> GetNodeDepths(ProcedureFunctionChart pfc)
        {
            Dictionary <IPfcNode, int> depths = new Dictionary <IPfcNode, int>();
            //List<IPfcStepNode> nodes =
            //Debug.Assert( nodes.Count == 1, "A PFC was passed into PFCAnalyst.GetNodeDepths(...) that had " + nodes.Count + " finish steps. This is illegal." );
            IPfcNode node = pfc.GetFinishTransition( );

            GetDepth(node, ref depths);
            return(depths);
        }
コード例 #5
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateTestPfc5()
        {
            // Flip-flop pattern.

            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "SFC 1");

            #region Create Nodes

            char name = 'A';
            A = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            B = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            C = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            D = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            E = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            F = pfc.CreateStep("Step_" + (name++), "", NextGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;
            nD = (IPfcNode)D;
            nE = (IPfcNode)E;
            nF = (IPfcNode)F;

            #endregion Create Nodes

            #region Create Structure

            pfc.BindParallelDivergent(nA, new IPfcNode[] { nB, nC });
            pfc.BindSeriesDivergent(nB, new IPfcNode[] { nD, nE });
            pfc.BindSeriesDivergent(nC, new IPfcNode[] { nD, nE });
            pfc.BindParallelConvergent(new IPfcNode[] { nD, nE }, nF);

            PfcLinkElementList links = new PfcLinkElementList(pfc.Links);
            links.Sort(new Comparison <IPfcLinkElement>(delegate(IPfcLinkElement a, IPfcLinkElement b) {
                return(Comparer.Default.Compare(a.Name, b.Name));
            }));


            System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
            foreach (IPfcLinkElement link in links)
            {
                typeof(PfcElement).GetFields(bf);
                typeof(PfcElement).GetField("m_guid", bf).SetValue((PfcElement)link, NextGuid()); // Totally cheating.
            }

            //pfc.Bind(nD, pfc.Nodes["T_005"]);

            #endregion Create Structure

            return(pfc);
        }
コード例 #6
0
        public static int AssignWeightsForBroadestNonLoopingPath(ProcedureFunctionChart pfc)
        {
            pfc.Nodes.ForEach(n => n.NodeColor = NodeColor.White);
            pfc.Links.ForEach(n => n.Priority  = null);

            PfcStep start  = (PfcStep)pfc.GetStartSteps()[0];
            int     retval = WeightAssignmentPropagationForBroadestNonLoopingPath(start);

            pfc.Links.ForEach(n => { if (n.Priority < 0)
                                     {
                                         n.Priority = int.MinValue - n.Priority;
                                     }
                              });
            return(retval);
        }
コード例 #7
0
        private void _TestSerialization(ProcedureFunctionChart pfc, string shouldBe, string testName)
        {
            #region Store the Pfc to a file.

            #region Create an XmlWriter
            System.Text.StringBuilder sb     = new System.Text.StringBuilder();
            System.IO.StringWriter    sw     = new System.IO.StringWriter(sb);
            XmlTextWriter             writer = new XmlTextWriter(sw);

            writer.Formatting = Formatting.Indented;

            #endregion Create an XmlWriter

            #region Write the PFC to the writer
            writer.WriteStartDocument();
            pfc.WriteXml(writer);
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();

            #endregion Write the PFC to the writer

            XmlDocument doc = new XmlDocument();
            doc.InnerXml = sb.ToString();

            doc.Save(m_pfcTestFileName);

            #endregion Store the Pfc to a file.

            #region Load the Pfc from a file.

            ProcedureFunctionChart pfc2 = new ProcedureFunctionChart();
            FileStream             fs   = new FileStream(m_pfcTestFileName, FileMode.Open);
            XmlReader tr = System.Xml.XmlReader.Create(fs);
            pfc2.ReadXml(tr);
            tr.Close();
            fs.Close();
            File.Delete(m_pfcTestFileName);

            Console.WriteLine(PfcDiagnostics.GetStructure(pfc2));

            #endregion Load the Pfc from a file.

            string structureString = PfcDiagnostics.GetStructure(pfc2);
            Console.WriteLine("After storing and reloading a " + testName + ", the reloaded structure is \r\n" + structureString);
            Assert.AreEqual(StripCRLF(structureString), StripCRLF(shouldBe), "Structure should have been\r\n" + shouldBe + "\r\nbut it was\r\n" + structureString + "\r\ninstead.");
        }
コード例 #8
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateTestPfc4()
        {
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "SFC 1");

            #region Create Nodes

            char name = 'A';
            A = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            B = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            C = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            D = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            E = pfc.CreateStep("Step_" + (name++), "", NextGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;
            nD = (IPfcNode)D;
            nE = (IPfcNode)E;

            #endregion Create Nodes

            #region Create Structure

            pfc.Bind(nA, nB);
            pfc.Bind(nB, nE);
            pfc.Bind(nA.SuccessorNodes[0], nC);
            pfc.Bind(nC, nD);
            pfc.Bind(nD, nE.PredecessorNodes[0]);

            PfcLinkElementList links = new PfcLinkElementList(pfc.Links);
            links.Sort(new Comparison <IPfcLinkElement>(delegate(IPfcLinkElement a, IPfcLinkElement b) {
                return(Comparer.Default.Compare(a.Name, b.Name));
            }));


            System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
            foreach (IPfcLinkElement link in links)
            {
                typeof(PfcElement).GetFields(bf);
                typeof(PfcElement).GetField("m_guid", bf).SetValue((PfcElement)link, NextGuid()); // Totally cheating.
            }

            #endregion Create Structure

            return(pfc);
        }
コード例 #9
0
        private void _TestStepToStepBinding()
        {
            string testName = "Step-to-Step binding, maintaining SFC Compliance";

            Model model = new Model("SFC Test 1");
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid());

            PfcStep s1 = (PfcStep)pfc.CreateStep("Alice", "", Guid.Empty);
            PfcStep s2 = (PfcStep)pfc.CreateStep("Bob", "", Guid.Empty);

            //SfcStep s3 = (SfcStep)pfc.CreateStep("Charlie", "", Guid.Empty);

            pfc.Bind(s1, s2);

            string structureString = PfcDiagnostics.GetStructure(pfc);

            Console.WriteLine("After a " + testName + ", structure is \r\n" + structureString);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void Test_SynchronizerConstruct_Steps()
        {
            Model model = new Model("SFC Test 1");
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid());

            IPfcStepNode t0 = pfc.CreateStep("S_Alice", "", Guid.Empty);
            IPfcStepNode t1 = pfc.CreateStep("S_Bob", "", Guid.Empty);
            IPfcStepNode t2 = pfc.CreateStep("S_Charley", "", Guid.Empty);
            IPfcStepNode t3 = pfc.CreateStep("S_David", "", Guid.Empty);
            IPfcStepNode t4 = pfc.CreateStep("S_Edna", "", Guid.Empty);
            IPfcStepNode t5 = pfc.CreateStep("S_Frank", "", Guid.Empty);
            IPfcStepNode t6 = pfc.CreateStep("S_Gary", "", Guid.Empty);
            IPfcStepNode t7 = pfc.CreateStep("S_Hailey", "", Guid.Empty);

            pfc.Synchronize(new IPfcStepNode[] { t0, t1, t2, t3 }, new IPfcStepNode[] { t4, t5, t6, t7 });

            string structureString = PfcDiagnostics.GetStructure(pfc);

            structureString = structureString.Replace("SFC 1.Root", "SFC 1.Root");
            string shouldBe = "{S_Alice-->[L_000(SFC 1.Root)]-->T_000}\r\n{S_Bob-->[L_001(SFC 1.Root)]-->T_000}\r\n{S_Charley-->[L_002(SFC 1.Root)]-->T_000}\r\n{S_David-->[L_003(SFC 1.Root)]-->T_000}\r\n{T_000-->[L_004(SFC 1.Root)]-->S_Edna}\r\n{T_000-->[L_005(SFC 1.Root)]-->S_Frank}\r\n{T_000-->[L_006(SFC 1.Root)]-->S_Gary}\r\n{T_000-->[L_007(SFC 1.Root)]-->S_Hailey}\r\n";

            Console.WriteLine("After a synchronization of steps, 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 IPfcStepNode[] { t0, t1, t2, t3, t4, t5, t6, t7 });
                pfc.Synchronize(new IPfcStepNode[] { t0, t1, t2, t3 }, new IPfcStepNode[] { t4, t5, t6, t7 });

                testEvaluator.NextExpectedActivations = new IPfcStepNode[] { t0, t1, t2, t3, t4, t5, t6, t7 };

                foreach (IPfcNode ilinkable in new IPfcStepNode[] { 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.
            }
        }
コード例 #13
0
        public static List <IPfcNode> GetNodesOnBroadestNonLoopingPath(ProcedureFunctionChart pfc, bool restoreOldLinkPriorities = true)
        {
            Dictionary <PfcLink, int?> oldVal = null;

            if (restoreOldLinkPriorities)
            {
                oldVal = new Dictionary <PfcLink, int?>();
                pfc.Links.ForEach(n => oldVal.Add((PfcLink)n, ((PfcLink)n).Priority));
            }
            AssignWeightsForBroadestNonLoopingPath(pfc);
            List <IPfcNode> retval = GetNodesOnPriorityPath(pfc);

            if (restoreOldLinkPriorities)
            {
                foreach (PfcLink link in oldVal.Keys)
                {
                    link.Priority = oldVal[link];
                }
            }
            return(retval);
        }
コード例 #14
0
ファイル: StateMachines.cs プロジェクト: sjvannTMU/Sage
        /// <summary>
        /// Creates pfc execution contexts, one per action under the step that is currently running. Each
        /// is given an instance count of zero, as a step can run its action only once, currently.
        /// </summary>
        /// <param name="parentContext">The parent context, that of the step that is currently running.</param>
        /// <param name="kids">The procedure function charts that live in the actions under the step that is currently running.</param>
        /// <param name="kidContexts">The pfc execution contexts that will correspond to the running of each of the child PFCs.</param>
        protected virtual void CreateChildContexts(PfcExecutionContext parentContext, out IProcedureFunctionChart[] kids, out PfcExecutionContext[] kidContexts)
        {
            int kidCount = MyStep.Actions.Count;

            kids        = new ProcedureFunctionChart[kidCount];
            kidContexts = new PfcExecutionContext[kidCount];
            int i = 0;

            foreach (KeyValuePair <string, IProcedureFunctionChart> kvp in MyStep.Actions)
            {
                IProcedureFunctionChart kid = kvp.Value;
                kids[i] = kid;
                Guid kidGuid = GuidOps.XOR(parentContext.Guid, kid.Guid);
                while (parentContext.Contains(kidGuid))
                {
                    kidGuid = GuidOps.Increment(kidGuid);
                }
                kidContexts[i] = new PfcExecutionContext(kid, kvp.Key, null, kidGuid, parentContext);
                kidContexts[i].InstanceCount = 0;
                i++;
            }
        }
コード例 #15
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateOffsetParallelPFC()
        {
            ProcedureFunctionChart pfc    = new ProcedureFunctionChart(null, "OffsetParallelPfc");
            IPfcStepNode           start  = pfc.CreateStep("Start", "", Guid.Empty);
            IPfcStepNode           finish = pfc.CreateStep("Finish", "", Guid.Empty);

            char name = 'A';

            A = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            B = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            C = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            D = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            E = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            F = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            G = pfc.CreateStep("Step_" + (name++), "", NextGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;
            nD = (IPfcNode)D;
            nE = (IPfcNode)E;
            nF = (IPfcNode)F;
            nG = (IPfcNode)G;

            pfc.Bind(start, nA);
            pfc.Bind(nA, nB);
            pfc.Bind(nB, nE);
            pfc.Bind(nE, nF);
            pfc.Bind(nF, nG);
            pfc.Bind(nG, finish);
            pfc.Bind(((PfcTransition)((PfcStep)nA).SuccessorNodes[0]), nC);
            pfc.Bind(nC, ((PfcTransition)((PfcStep)nE).SuccessorNodes[0]));
            pfc.Bind(((PfcTransition)((PfcStep)nB).SuccessorNodes[0]), nD);
            pfc.Bind(nD, ((PfcTransition)((PfcStep)nF).SuccessorNodes[0]));

            pfc.UpdateStructure();

            return(pfc);
        }
コード例 #16
0
        private void _TestSimpleLink(PfcElementType inType, PfcElementType outType, string shouldBe)
        {
            string testName = "Simple link from " + inType.ToString() + " to " + outType.ToString();
            Model  model    = new Model(testName);

            ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid());

            IPfcNode n0, n1;

            n0 = CreateNode(pfc, "Alice", inType);
            n1 = CreateNode(pfc, "Bob", outType);
            pfc.Bind(n0, n1);

            string structureString = PfcDiagnostics.GetStructure(pfc);

            Console.WriteLine("After a " + testName + ", structure is \r\n" + structureString);
            Assert.AreEqual(StripCRLF(structureString), StripCRLF(shouldBe), "Structure should have been\r\n" + shouldBe + "\r\nbut it was\r\n" + structureString + "\r\ninstead.");

            if (m_testSerializationToo)
            {
                _TestSerialization(pfc, shouldBe, testName);
            }
        }
コード例 #17
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateTestPfc()
        {
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "SFC 1");

            ((PfcElementFactory)pfc.ElementFactory).SetRepeatable(Guid.Empty); // Ensures Guids are repeatable.

            #region Create Nodes

            char name = 'A';
            A = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            B = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            C = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            D = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            E = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            F = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            G = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            H = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            I = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            J = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            K = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            L = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            M = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            N = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            O = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            P = pfc.CreateStep("Step_" + (name), "", NextGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;
            nD = (IPfcNode)D;
            nE = (IPfcNode)E;
            nF = (IPfcNode)F;
            nG = (IPfcNode)G;
            nH = (IPfcNode)H;
            nI = (IPfcNode)I;
            nJ = (IPfcNode)J;
            nK = (IPfcNode)K;
            nL = (IPfcNode)L;
            nM = (IPfcNode)M;
            nN = (IPfcNode)N;
            nO = (IPfcNode)O;
            nP = (IPfcNode)P;

            #endregion Create Nodes

            #region Create Structure

            pfc.Bind(nA, nB);
            pfc.BindSeriesDivergent(nB, new IPfcNode[] { nC, nF });
            pfc.Bind(nC, nD);
            pfc.Bind(nD, nE);
            pfc.Bind(nF, nG);
            pfc.BindParallelDivergent(nG, new IPfcNode[] { nH, nI, nP });
            pfc.Bind(nH, nJ);
            pfc.Bind(nI, nK);
            pfc.BindParallelConvergent(new IPfcNode[] { nJ, nK, nP }, nL);
            pfc.Bind(nL, nM);
            pfc.BindSeriesConvergent(new IPfcNode[] { nE, nM }, nN);
            pfc.Bind(nN, nO);
            pfc.Bind(nB, nN);

            #endregion Create Structure

            pfc.UpdateStructure();

            return(pfc);
        }
コード例 #18
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateTestPfc3()
        {
            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "SFC 1");

            #region Create Nodes

            char name = 'A';
            A = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            B = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            C = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            D = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            E = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            F = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            G = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            H = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            I = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            J = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            K = pfc.CreateStep("Step_" + (name++), "", NextGuid());
            L = pfc.CreateStep("Step_" + (name++), "", NextGuid());

            nA = (IPfcNode)A;
            nB = (IPfcNode)B;
            nC = (IPfcNode)C;
            nD = (IPfcNode)D;
            nE = (IPfcNode)E;
            nF = (IPfcNode)F;
            nG = (IPfcNode)G;
            nH = (IPfcNode)H;
            nI = (IPfcNode)I;
            nJ = (IPfcNode)J;
            nK = (IPfcNode)K;
            nL = (IPfcNode)L;

            #endregion Create Nodes

            #region Create Structure

            pfc.BindParallelDivergent(nA, new IPfcNode[] { nB, nC, nD, nE });
            pfc.BindParallelDivergent(nB, new IPfcNode[] { nF, nG });
            pfc.BindParallelDivergent(nE, new IPfcNode[] { nJ, nK });

            pfc.BindParallelConvergent(new IPfcNode[] { nF, nG }, nH);
            pfc.BindParallelConvergent(new IPfcNode[] { nC, nD }, nI);
            pfc.BindParallelConvergent(new IPfcNode[] { nH, nI, nJ, nK }, nL);

            PfcLinkElementList links = new PfcLinkElementList(pfc.Links);
            links.Sort(new Comparison <IPfcLinkElement>(delegate(IPfcLinkElement a, IPfcLinkElement b) {
                return(Comparer.Default.Compare(a.Name, b.Name));
            }));


            System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
            foreach (IPfcLinkElement link in links)
            {
                typeof(PfcElement).GetFields(bf);
                typeof(PfcElement).GetField("m_guid", bf).SetValue((PfcElement)link, NextGuid()); // Totally cheating.
            }

            #endregion Create Structure

            return(pfc);
        }
コード例 #19
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateRandomPFC(int nSteps, int seed)
        {
            Guid mask     = GuidOps.FromString(string.Format("{0}, {1}", nSteps, seed));
            Guid seedGuid = GuidOps.FromString(string.Format("{0}, {1}", seed, nSteps));
            int  rotate   = 3;

            GuidGenerator     guidGen = new GuidGenerator(seedGuid, mask, rotate);
            PfcElementFactory pfcef   = new PfcElementFactory(guidGen);

            ProcedureFunctionChart pfc = new ProcedureFunctionChart(new Highpoint.Sage.SimCore.Model("Test model", Guid.NewGuid()), "Name", "", guidGen.Next(), pfcef);

            IPfcStepNode start  = pfc.CreateStep("Start", "", Guid.Empty);
            IPfcStepNode step1  = pfc.CreateStep("Step1", "", Guid.Empty);
            IPfcStepNode finish = pfc.CreateStep("Finish", "", Guid.Empty);

            pfc.Bind(start, step1);
            pfc.Bind(step1, finish);

            Console.WriteLine("Seed = {0}.", seed);

            Random r = new Random(seed);

            while (pfc.Steps.Count < nSteps)
            {
                double steeringValue = r.NextDouble();

                if (steeringValue < .5)
                {
                    // Insert a step in series.
                    IPfcLinkElement link     = pfc.Links[r.Next(0, pfc.Links.Count - 1)];
                    IPfcStepNode    stepNode = pfc.CreateStep();
                    pfc.Bind(link.Predecessor, stepNode);
                    pfc.Bind(stepNode, link.Successor);
                    //Console.WriteLine("Inserted {0} between {1} and {2}.", stepNode.Name, link.Predecessor.Name, link.Successor.Name);
                    link.Detach();
                }
                else if (steeringValue < .666)
                {
                    // Insert a step in parallel.
                    for (int i = 0; i < 50; i++)   // Try, but give up if don't find suitable step.
                    {
                        IPfcStepNode target = pfc.Steps[r.Next(0, pfc.Steps.Count - 1)];
                        if (target.PredecessorNodes.Count == 1 && target.SuccessorNodes.Count == 1)
                        {
                            IPfcStepNode stepNode = pfc.CreateStep();
                            pfc.Bind(target.PredecessorNodes[0], stepNode);
                            pfc.Bind(stepNode, target.SuccessorNodes[0]);
                            //Console.WriteLine("Inserted {0} parallel to {1}.", stepNode.Name, target.Name);
                            break;
                        }
                    }
                }
                else if (steeringValue < .833)
                {
                    // Insert a branch
                    for (int i = 0; i < 50; i++)   // Try, but give up if don't find suitable step.
                    {
                        IPfcStepNode step = pfc.Steps[r.Next(0, pfc.Steps.Count - 1)];
                        if (step.PredecessorNodes.Count == 1 && step.SuccessorNodes.Count == 1)
                        {
                            IPfcStepNode entryStep = pfc.CreateStep(step.Name + "_IN", null, Guid.Empty);
                            IPfcStepNode exitStep  = pfc.CreateStep(step.Name + "_OUT", null, Guid.Empty);
                            IPfcStepNode leftStep  = pfc.CreateStep(step.Name + "_LFT", null, Guid.Empty);
                            IPfcStepNode rightStep = pfc.CreateStep(step.Name + "_RGT", null, Guid.Empty);
                            pfc.Bind(step.PredecessorNodes[0], entryStep);
                            pfc.Bind(entryStep, leftStep);
                            pfc.Bind(entryStep, rightStep);
                            pfc.Bind(leftStep, exitStep);
                            pfc.Bind(rightStep, exitStep);
                            pfc.Bind(exitStep, step.SuccessorNodes[0]);
                            pfc.Unbind(step.PredecessorNodes[0], step);
                            pfc.Unbind(step, step.SuccessorNodes[0]);
                            //Console.WriteLine("Inserted a branch in place of {0}.", step.Name);
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 50; i++)   // Try, but give up if don't find suitable step.
                    {
                        IPfcTransitionNode trans = pfc.Transitions[r.Next(0, pfc.Transitions.Count - 1)];
                        if (trans.PredecessorNodes.Count == 1 && trans.SuccessorNodes.Count == 1)
                        {
                            IPfcStepNode successor = (IPfcStepNode)trans.SuccessorNodes[0];
                            IPfcStepNode subject   = pfc.CreateStep();
                            pfc.Bind(trans, subject);
                            pfc.Bind(subject, successor);
                            pfc.Unbind(trans, successor);
                            IPfcStepNode loopback = pfc.CreateStep();
                            pfc.Bind(subject, loopback);
                            pfc.Bind(loopback, subject);
                            //Console.WriteLine("Inserted {0} between {1} and {2}, and created a branchback around it using {3}.",
                            //    subject.Name, trans.PredecessorNodes[0].Name, successor.Name, loopback.Name);
                            break;
                        }
                    }
                    //// insert a loopback
                    //IPfcStepNode step;
                    //do { step = pfc.Steps[r.Next(0, pfc.Steps.Count - 1)]; } while (step == start || step == finish);
                    //IPfcStepNode newNode = pfc.CreateStep();
                    //pfc.Bind(step, newNode);
                    //pfc.Bind(newNode, step);
                    //Console.WriteLine("Inserted a loopback around {0} using new step, {1}.", step.Name, newNode.Name);
                }

                //IPfcStepNode origin = pfc.Steps[r.Next(0, pfc.Steps.Count - 1)];
                //if (origin.Equals(finish)) continue;

                //if (r.NextDouble() < .2) {
                //    IPfcStepNode stepNode = pfc.CreateStep();
                //    IPfcNode target = origin.SuccessorNodes[r.Next(0, origin.SuccessorNodes.Count - 1)];
                //    // Insert a step in series.
                //    pfc.Bind(origin, stepNode);
                //    pfc.Bind(stepNode, target);
                //    pfc.Unbind(origin, target);
                //    Console.WriteLine("Inserting {0} between {1} and {2}.",
                //        stepNode.Name, origin.Name, target.Name);


                //} else if (r.NextDouble() < .55) {
                //    // Insert a step in parallel
                //    if (origin.PredecessorNodes.Count == 1 && origin.SuccessorNodes.Count == 1) {
                //        origin = origin.PredecessorNodes[0];
                //        target = origin.SuccessorNodes[0];
                //        pfc.Bind(origin, stepNode);
                //        pfc.Bind(stepNode, target);
                //        Console.WriteLine("Inserting {0} parallel to {1} - between {2} and {3}.",
                //            stepNode.Name, parallelTo.Name, origin.Name, target.Name);

                //    }

                //} else {
                //    // Insert a loopback or branchforward.
                //    IPfcNode target = null;
                //    string parallelType = null;
                //    if (!origin.PredecessorNodes.Contains(start) && r.NextDouble() < .5) {
                //        target = origin;
                //        parallelType = "loopback";
                //    } else if (origin.SuccessorNodes.Count==1 && origin.PredecessorNodes==1) {
                //        target = origin.SuccessorNodes[r.Next(0, origin.SuccessorNodes.Count - 1)];
                //        parallelType = "branch forward";
                //    }

                //    if (target != null) {
                //        IPfcStepNode stepNode = pfc.CreateStep();
                //        pfc.Bind(origin, stepNode);
                //        pfc.Bind(stepNode, target);
                //        Console.WriteLine("Inserting {0} around {1} to {2}, with {3} on the new alternate path.",
                //            parallelType, origin.Name, target.Name, stepNode.Name);
                //    }
                //}
            }

            return(pfc);
        }
コード例 #20
0
        private void _TestComplexLink(LinkSuperType superType, PfcElementType inType, PfcElementType outType, string shouldBe)
        {
            string testName = superType.ToString() + " from " + inType.ToString() + " to " + outType.ToString();
            Model  model    = new Model(testName);

            ProcedureFunctionChart pfc = new ProcedureFunctionChart(model, "SFC 1", "", Guid.NewGuid());

            IPfcNode n0, n1, n2, n3, n4;

            switch (superType)
            {
            case LinkSuperType.ParallelConvergent:
                n0 = CreateNode(pfc, "Alice", inType);
                n1 = CreateNode(pfc, "Bob", inType);
                n2 = CreateNode(pfc, "Charley", inType);
                n3 = CreateNode(pfc, "David", inType);
                n4 = CreateNode(pfc, "Edna", outType);
                pfc.BindParallelConvergent(new IPfcNode[] { n0, n1, n2, n3 }, n4);
                break;

            case LinkSuperType.SeriesConvergent:
                n0 = CreateNode(pfc, "Alice", inType);
                n1 = CreateNode(pfc, "Bob", inType);
                n2 = CreateNode(pfc, "Charley", inType);
                n3 = CreateNode(pfc, "David", inType);
                n4 = CreateNode(pfc, "Edna", outType);
                pfc.BindSeriesConvergent(new IPfcNode[] { n0, n1, n2, n3 }, n4);
                break;

            case LinkSuperType.ParallelDivergent:
                n0 = CreateNode(pfc, "Alice", inType);
                n1 = CreateNode(pfc, "Bob", outType);
                n2 = CreateNode(pfc, "Charley", outType);
                n3 = CreateNode(pfc, "David", outType);
                n4 = CreateNode(pfc, "Edna", outType);
                pfc.BindParallelDivergent(n0, new IPfcNode[] { n1, n2, n3, n4 });
                break;

            case LinkSuperType.SeriesDivergent:
                n0 = CreateNode(pfc, "Alice", inType);
                n1 = CreateNode(pfc, "Bob", outType);
                n2 = CreateNode(pfc, "Charley", outType);
                n3 = CreateNode(pfc, "David", outType);
                n4 = CreateNode(pfc, "Edna", outType);
                pfc.BindSeriesDivergent(n0, new IPfcNode[] { n1, n2, n3, n4 });
                break;

            default:
                break;
            }


            string structureString = PfcDiagnostics.GetStructure(pfc);

            Console.WriteLine("After a " + testName + ", structure is \r\n" + structureString);
            Assert.AreEqual(StripCRLF(structureString), StripCRLF(shouldBe), "Structure should have been\r\n" + shouldBe + "\r\nbut it was\r\n" + structureString + "\r\ninstead.");

            if (m_testSerializationToo)
            {
                _TestSerialization(pfc, shouldBe, testName);
            }
        }
コード例 #21
0
        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"));
        }
コード例 #22
0
        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");
        }
コード例 #23
0
ファイル: TestPfcRepository.cs プロジェクト: sjvannTMU/Sage
        public static ProcedureFunctionChart CreateStandardPFC(int number)
        {
            ProcedureFunctionChart pfc = null;

            switch (number)
            {
            case 2:
                pfc = CreateTestPfc();
                break;

            case 3:
                pfc = CreateTestPfc2();
                break;

            case 4:
                pfc = CreateTestPfc3();
                break;

            case 5:
                pfc = CreateTestPfc4();
                break;

            case 6:     // A Flip-flop PFC.
                pfc = CreateTestPfc5();
                break;

            case 82:
                pfc = CreateRandomPFC(8, 1076501454);
                break;

            case 83:
                pfc = CreateRandomPFC(15, 1443487589);
                break;

            case 84:
                pfc = CreateRandomPFC(15, 919145039);
                break;

            case 85:
                pfc = CreateRandomPFC(15, 1915039786);
                break;

            case 86:
                pfc = CreateRandomPFC(14, 1576245265);
                break;

            case 87:
                pfc = CreateRandomPFC(14, 1359939537);
                break;

            case 88:
                pfc = CreateRandomPFC(12, 3666920);
                break;

            case 89:
                pfc = CreateRandomPFC(12, 1688960816);
                break;

            case 90:
                pfc = CreateRandomPFC(12, 1444166439);
                break;

            case 91:
                pfc = CreateRandomPFC(12, 84258233);
                break;

            case 92:
                pfc = CreateRandomPFC(7, 1174395592);
                break;

            case 93:
                pfc = CreateRandomPFC(7, 1479576831);
                break;

            case 94:
                pfc = CreateRandomPFC(7, 1514213606);
                break;

            case 95:
                pfc = CreateRandomPFC(7, 953319173);
                break;

            case 96:
                pfc = CreateRandomPFC(7, 376952253);
                break;

            case 97:
                pfc = CreateRandomPFC(7, 1020353150);
                break;

            case 98:
                pfc = CreateRandomPFC(7, 585340845);
                break;

            default:
                break;
            }
            return(pfc);
        }
コード例 #24
0
ファイル: PfcStep.cs プロジェクト: sjvannTMU/Sage
 /// <summary>
 /// Returns the actions under this Step as a procedure function chart.
 /// </summary>
 /// <returns>A procedure function chart containing the actions under this Step.</returns>
 public ProcedureFunctionChart ToProcedureFunctionChart()
 {
     return(ProcedureFunctionChart.CreateFromStep(this, false));
 }
コード例 #25
0
        /// <summary>
        /// Gets the nodes on the already-established priority path. At a branch, the link with the highest priority
        /// is followed.
        /// </summary>
        /// <param name="pfc">The PFC.</param>
        /// <returns></returns>
        public static List <IPfcNode> GetNodesOnPriorityPath(ProcedureFunctionChart pfc)
        {
            // Do a breadth-first traversal, determining the sequence of operation steps executed in each unit.
            List <IPfcNode>  sequence = new List <IPfcNode>();
            Queue <IPfcNode> working  = new Queue <IPfcNode>();

            pfc.Nodes.ForEach(n => n.NodeColor = NodeColor.White);
            IPfcNode starter = pfc.GetStartSteps()[0];

            starter.NodeColor = NodeColor.Gray;
            working.Enqueue(starter);

            IPfcNode current;

            while (working.Count() > 0)
            {
                current = working.Dequeue();
                if (s_diagnostics)
                {
                    Console.WriteLine("Dequeueing {0}, leaving {1} elements in queue.", current.Name, working.Count());
                }
                Debug.Assert(current.NodeColor == NodeColor.Gray);
                if (current.Successors.Count() == 0)
                {
                    current.NodeColor = NodeColor.Black; // It's the last one.
                    sequence.Add(current);
                    if (s_diagnostics)
                    {
                        Console.WriteLine("\tIt's the last one in the queue.");
                    }
                }
                else
                {
                    // If it's a step node, then it's a pass-in, or it's a serial convergence.
                    // Either way, we only need one predecessor to be black. And it will be.
                    if (current is IPfcStepNode || current.PredecessorNodes.TrueForAll(n => n.NodeColor == NodeColor.Black))
                    {
                        if (s_diagnostics)
                        {
                            Console.WriteLine("\tAdvancing.");
                        }
                        current.NodeColor = NodeColor.Black;
                        // We can advance.
                        if (current.SuccessorNodes.Count() == 1 || current is IPfcTransitionNode)
                        {
                            // Single follower, or parallel divergence, all successors are enqueued.
                            foreach (IPfcNode next in current.SuccessorNodes)
                            {
                                if (next.NodeColor == NodeColor.White)
                                {
                                    next.NodeColor = NodeColor.Gray;
                                    if (s_diagnostics)
                                    {
                                        Console.WriteLine("\t\tEnqueueing {0}.", next.Name);
                                    }
                                    working.Enqueue(next);
                                }
                            }
                        }
                        else     // Serial divergence - enqueue only the highest priority node.
                        {
                            IPfcNode next = current.Successors.OrderByDescending(n => n.Priority).First().Successor;
                            if (next.NodeColor == NodeColor.White)
                            {
                                next.NodeColor = NodeColor.Gray;
                                if (s_diagnostics)
                                {
                                    Console.WriteLine("\t\tEnqueueing {0}.", next.Name);
                                }
                                working.Enqueue(next);
                            }
                            //System.Diagnostics.Debug.Assert(next.SuccessorNodes.Count() < 2); // Duality violation, if not.
                        }
                        current.NodeColor = NodeColor.Black;
                        if (s_diagnostics)
                        {
                            Console.WriteLine("\t->Logging execution of {0}.", current.Name);
                        }
                        sequence.Add(current);
                    }
                    else
                    {
                        working.Enqueue(current); // All preds are not black. Must try again later.
                    }
                }
            }

            return(sequence);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
ファイル: Expressions.cs プロジェクト: sjvannTMU/Sage
        /// <summary>
        /// Refreshes the Participant Directory to contain only the ExpressionElements in the specified PFC.
        /// Performed via a Mark-and-Sweep algorithm.
        /// </summary>
        /// <param name="pfc">The PFC.</param>
        internal void Refresh(ProcedureFunctionChart pfc)
        {
            foreach (ExpressionElement ee in m_nameMap.Values)
            {
                ee.Marked = false;
                _Debug.Assert(m_guidMap.ContainsValue(ee));
            }

            foreach (ExpressionElement ee in m_guidMap.Values)
            {
                _Debug.Assert(ee.Marked == false);
                _Debug.Assert(m_nameMap.ContainsValue(ee));
            }

            foreach (IPfcNode node in pfc.Steps)
            {
                if (m_nameMap.ContainsKey(node.Name))
                {
                    m_nameMap[node.Name].Marked = true;
                }
            }

            // PCB20080725: Was this. Changed to the following, to key on name.
            //foreach (IPfcTransitionNode trans in pfc.Transitions) {
            //    foreach (ExpressionElement ee in trans.Expression.Elements) {
            //        ee.Marked = true;
            //    }
            //}

            foreach (IPfcTransitionNode trans in pfc.Transitions)
            {
                foreach (ExpressionElement ee in trans.Expression.Elements)
                {
                    if (ee is Macro)
                    {
                        m_nameMap[ee.Name.Trim('\'')].Marked = true;
                    }
                    else if (ee.Name != string.Empty)
                    {
                        m_nameMap[ee.Name].Marked = true;
                    }
                }
            }

            List <ExpressionElement> rejects = new List <ExpressionElement>();

            foreach (ExpressionElement ee in m_nameMap.Values)
            {
                if (!ee.Marked)
                {
                    rejects.Add(ee);
                }
                ee.Marked = false;
            }

            foreach (ExpressionElement ee in rejects)
            {
                m_nameMap.Remove(ee.Name);
                m_guidMap.Remove(ee.Guid);
            }
        }
コード例 #28
0
ファイル: PfcStep.cs プロジェクト: sjvannTMU/Sage
 /// <summary>
 /// Returns the actions under this Step as a procedure function chart.
 /// </summary>
 /// <param name="autoFlatten">if set to <c>true</c>, flattens each PFC under this step and its actions and their steps' actions.</param>
 /// <returns>A procedure function chart containing the actions under this Step.</returns>
 public ProcedureFunctionChart ToProcedureFunctionChart(bool autoFlatten)
 {
     return(ProcedureFunctionChart.CreateFromStep(this, autoFlatten));
 }
コード例 #29
0
        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("========================================================");
            }
        }