public TransitionHistoryItem(Transition transition)
 {
     this.transition = transition;
     this.transitionNameAtFire = this.transition.Name;
     this.tokens = new List<Token>();
     this.nameOfTokensAtFire = new List<string>();
 }
Exemple #2
0
 public AbstractEdge(string name, long unid, bool showAnnotation, int weight, Position position, Transition transition, EdgeType edgeType)
     : base(name, unid, showAnnotation)
 {
     this.weight = weight;
     this.position = position;
     this.transition = transition;
     this.edgeType = edgeType;
 }
 public EdgeTransitionPosition(string name, long unid, bool showAnnotation, int weight, Transition transition, Position position, EdgeType edgeType)
     : base(name, unid, showAnnotation, weight, position, transition, edgeType)
 {
 }
 public EdgeTransitionPosition(AbstractItemData itemData, int weight, Transition transition, Position position, EdgeType edgeType)
     : this(itemData.name, itemData.unid, itemData.showAnnotation, weight, transition, position, edgeType)
 {
 }
Exemple #5
0
 internal static AbstractEventDrivenItem openFromXml(XmlNode node)
 {
     XmlNodeList list = node.ChildNodes;
     List<PetriEvent> events = null;
     foreach (XmlNode childNode in list)
     {
         string namespaceUri = childNode.NamespaceURI;
         string localName = childNode.LocalName;
         switch (namespaceUri)
         {
             case PetriXmlHelper.XML_ITEM_NAMESPACE:
                 switch (localName)
                 {
                     case "Events":
                         events = PetriEvent.openEvents(childNode.ChildNodes, "ItemEvent");
                         break;
                 }
                 break;
         }
     }
     int priority = Transition.openPriorityAttrFromNode(node);
     TransitionType transitionType = Transition.openTransitionTypeAttrFromNode(node);
     int delay = Transition.openDelayAttrFromNode(node);
     Transition ret = new Transition(AbstractItem.readItem(node), priority, transitionType, delay);
     ret.EventTrunk.addEvents(events);
     return ret;
 }
        private StateVector simulateTransitionFire(Transition fireTransition, bool changeStatistics)
        {
            this.checkHandler(fireTransition, EventType.PREACTIVATE);

            TransitionHistoryItem historyItem = null;
            if (changeStatistics)
            {
                fireTransition.Statistics.add(1);
                historyItem = new TransitionHistoryItem(fireTransition);
            }
            List<Token> tokens = new List<Token>();
            List<AbstractEdge> inputs = this.getAllInputEdge(fireTransition);
            foreach (AbstractEdge edge in inputs)
            {
                if (edge.Start is Position)
                {
                    Position position = (Position)edge.Start;
                    if (EdgeType.NORMAL.Equals(edge.EdgeType))
                    {
                        this.checkHandler(position, EventType.PREACTIVATE);
                        tokens.AddRange(position.takeAwayTokens(edge.Weight, changeStatistics));
                        this.checkHandler(position, EventType.POSTACTIVATE);
                    }
                    else if (EdgeType.RESET.Equals(edge.EdgeType))
                    {
                        this.checkHandler(position, EventType.PREACTIVATE);
                        tokens.AddRange(position.takeAwayTokens(changeStatistics));
                        this.checkHandler(position, EventType.POSTACTIVATE);
                    }
                    else if (EdgeType.INHIBITOR.Equals(edge.EdgeType))
                    {
                        // nothing to do
                    }
                }
            }

            this.checkHandler(fireTransition, EventType.POSTACTIVATE);

            this.mixTokens(tokens);
            if (changeStatistics && historyItem != null)
            {
                historyItem.addToken(tokens);
            }

            List<AbstractEdge> outputs = this.getAllOutputEdge(fireTransition);
            int ti = 0;
            foreach (AbstractEdge edge in outputs)
            {
                if (edge.End is Position)
                {
                    Position position = (Position)edge.End;
                    this.checkHandler(position, EventType.PREACTIVATE);
                    for (int ei = 0; ei < edge.Weight; ei++)
                    {
                        Token token = null;
                        if (ti < tokens.Count)
                        {
                            token = tokens[ti++];
                        }
                        else
                        {
                            token = new Token("", this.unidGenNumber++, false, Color.Black);
                        }
                        position.addToken(token);
                    }
                    if (changeStatistics)
                    {
                        position.addStatistics();
                    }
                    this.checkHandler(position, EventType.POSTACTIVATE);
                }
            }
            if (changeStatistics && historyItem != null)
            {
                this.addItemToTransitionHistory(historyItem);
            }

            return this.getNewStateVector(null);
        }
 private List<AbstractEdge> getAllOutputEdge(Transition transition)
 {
     List<AbstractEdge> outputs = new List<AbstractEdge>();
     foreach (AbstractEdge edge in this.Edges)
     {
         if (transition.Equals(edge.Start))
         {
             outputs.Add(edge);
         }
     }
     return outputs;
 }
 private List<AbstractEdge> getAllInputEdge(Transition transition)
 {
     List<AbstractEdge> inputs = new List<AbstractEdge>();
     foreach (AbstractEdge edge in this.Edges)
     {
         if (transition.Equals(edge.End))
         {
             inputs.Add(edge);
         }
     }
     return inputs;
 }
 private bool checkCapacityLimit(Transition transition, Dictionary<Position, Int32> touchedPositions)
 {
     bool cFire = true;
     List<AbstractEdge> outputs = this.getAllOutputEdge(transition);
     if (outputs.Count > 0)
     {
         foreach (AbstractEdge edge in outputs)
         {
             if (edge.End is Position)
             {
                 int needCapacity = edge.Weight;
                 Position tmpPos = (Position)edge.End;
                 if (touchedPositions.ContainsKey(tmpPos))
                 {
                     needCapacity -= touchedPositions[tmpPos];
                 }
                 if (tmpPos.isCapcityLimitInjured(needCapacity))
                 {
                     cFire = false;
                 }
             }
         }
     }
     return cFire;
 }
Exemple #10
0
 public FireReturn(FireEvent fireEvent, Transition fireTransition)
 {
     this.fireEvent = fireEvent;
     this.fireTransition = fireTransition;
 }