Ejemplo n.º 1
0
        /// <summary>
        /// Gives the specified link (which must be one of the outbound links from this node) the lowest
        /// priority of all links outbound from this node. Retuens false if the specified link is not a
        /// successor link to this node. NOTE: This API will renumber the outbound links' priorities.
        /// </summary>
        /// <param name="outbound">The link, already in existence and an outbound link from this node, that
        /// is to be set to the lowest priority of all links already outbound from this node.</param>
        /// <returns></returns>
        public bool SetLinkLowestPriority(IPfcLinkElement outbound)
        {
            if (!m_successors.Contains(outbound))
            {
                return(false);
            }

            m_successors.Sort(Parent.LinkComparer);
            m_successors.Remove(outbound);
            m_successors.Insert(0, outbound);

            List <IPfcLinkElement> links = new List <IPfcLinkElement>(m_successors);

            for (int i = 0; i < links.Count; i++)
            {
                links[i].Priority = (int)(m_successors.Count - i);
            }

            m_successors.Clear();
            m_successors.AddRange(links);

            m_successors.Sort(Parent.LinkComparer);

            return(true);
        }
Ejemplo n.º 2
0
            public static void Detach(IPfcLinkElement link)
            {
                LinkValidationData vd = link.UserData as LinkValidationData;

                if (vd != null)
                {
                    link.UserData = vd.m_userData;
                }
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Removes the successor link from this node's list of successors.
 /// </summary>
 /// <param name="currentSuccessor">The current successor.</param>
 /// <returns></returns>
 public bool RemoveSuccessor(IPfcLinkElement currentSuccessor)
 {
     if (!m_successors.Contains(currentSuccessor))
     {
         return(false);
     }
     m_successors.Remove(currentSuccessor);
     StructureDirty = true;
     return(true);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Determines whether the specified link is followed by a transition.
 /// </summary>
 /// <param name="link">The specified link.</param>
 /// <returns>
 ///     <c>true</c> if the specified link is followed by a transition.; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsPreTransitionLink(IPfcLinkElement link)
 {
     if (link.Successor == null)
     {
         return(false);
     }
     else
     {
         return(link.Successor.ElementType.Equals(PfcElementType.Transition));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the link that connects this node to a predecessor node. Returns null if there is no such link.
        /// </summary>
        /// <param name="predecessorNode">The predecessor.</param>
        /// <returns></returns>
        public IPfcLinkElement GetLinkForPredecessorNode(IPfcNode predecessorNode)
        {
            IPfcLinkElement retval = null;

            m_predecessors.ForEach(delegate(IPfcLinkElement le) { if (le.Predecessor == predecessorNode)
                                                                  {
                                                                      retval = le;
                                                                  }
                                   });
            return(retval);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the link that connects this node to a successor node. Returns null if there is no such link.
        /// </summary>
        /// <param name="successorNode">The successor.</param>
        /// <returns></returns>
        public IPfcLinkElement GetLinkForSuccessorNode(IPfcNode successorNode)
        {
            IPfcLinkElement retval = null;

            m_successors.ForEach(delegate(IPfcLinkElement le) { if (le.Successor == successorNode)
                                                                {
                                                                    retval = le;
                                                                }
                                 });
            return(retval);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds the new successor link to this node's list of successors.
        /// </summary>
        /// <param name="newSuccessor">The new successor link.</param>
        public void AddSuccessor(IPfcLinkElement newSuccessor)
        {
            _Debug.Assert(newSuccessor.Predecessor == this);
            m_successors.Add(newSuccessor);

            if (!newSuccessor.Priority.HasValue)
            {
                newSuccessor.Priority = 0;
            }

            ResortSuccessorLinks();
            StructureDirty = true;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Determines whether the specified element is a part of a path that has alternate paths. This algorithm
 /// goes up only one level - that is, if it's part of a parallel divergence that, itself, is in a path that
 /// is part of a series divergence, then the result will still be false.
 /// </summary>
 /// <param name="element">The specified element.</param>
 /// <returns>
 ///     <c>true</c> if the specified element is a part of a path that has parallel paths; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasAlternatePaths(IPfcElement element)
 {
     if (element == null)
     {
         return(false);
     }
     if (element.ElementType.Equals(PfcElementType.Link))
     {
         IPfcLinkElement linkElement = (IPfcLinkElement)element;
         if (linkElement.Predecessor != null && linkElement.Predecessor.ElementType.Equals(PfcElementType.Step) && linkElement.Predecessor.Successors.Count > 1)
         {
             return(true);
         }
         else
         {
             return(HasAlternatePaths(((IPfcLinkElement)element).Predecessor));
         }
     }
     else
     {
         IPfcNode prevDivergenceNode = GetPrevDivergenceNode((IPfcNode)element);
         return(prevDivergenceNode != null && prevDivergenceNode.ElementType.Equals(PfcElementType.Step));
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Determines whether the specified element is the sole successor of its immediate precedent node. If immediate predecessor is
 /// null, this method returns false.
 /// </summary>
 /// <param name="element">The specified element.</param>
 /// <returns>
 ///     <c>true</c> if the specified link is the sole successor of its one immediate precedent node; otherwise, (if there
 /// are any number of predecessors other than one, or if the one predecessor node has any number but one successor nodes)<c>false</c>.
 /// </returns>
 public static bool IsSoleSuccessor(IPfcElement element)
 {
     if (element == null)
     {
         return(false);
     }
     if (element.ElementType.Equals(PfcElementType.Link))
     {
         IPfcLinkElement link = (IPfcLinkElement)element;
         if (link.Predecessor == null)
         {
             return(false);
         }
         else
         {
             return(link.Predecessor.Successors.Count == 1);
         }
     }
     else
     {
         IPfcNode node = (IPfcNode)element;
         return(node.PredecessorNodes.Count == 1 && node.PredecessorNodes[0].SuccessorNodes.Count == 1);
     }
 }
Ejemplo n.º 10
0
 private void _Attach(IPfcLinkElement link)
 {
     m_link        = link;
     m_userData    = link.UserData;
     link.UserData = this;
 }
Ejemplo n.º 11
0
 public static void Attach(IPfcLinkElement link)
 {
     new LinkValidationData()._Attach(link);
 }
Ejemplo n.º 12
0
 private LinkValidationData GetValidationData(IPfcLinkElement link)
 {
     return(link.UserData as LinkValidationData);
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Adds the new predecessor link to this node's list of predecessors.
 /// </summary>
 /// <param name="newPredecessor">The new predecessor link.</param>
 public void AddPredecessor(IPfcLinkElement newPredecessor)
 {
     _Debug.Assert(newPredecessor.Successor != null);
     m_predecessors.Add(newPredecessor);
     StructureDirty = true;
 }