Esempio n. 1
0
 private void addToken(Token item)
 {
     if (item != null)
     {
         this.tokens.Add(item);
         this.nameOfTokensAtFire.Add(item.Name);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 private void deleteToken(Token token)
 {
     if (this.tokens.Contains(token))
     {
         this.tokens.Remove(token);
     }
 }
Esempio n. 4
0
 private static List<Token> openTokensFromXml(XmlNodeList list, List<Token> alltokens)
 {
     List<Token> ret = new List<Token>();
     foreach (XmlNode childNode in list)
     {
         string namespaceUri = childNode.NamespaceURI;
         string localName = childNode.LocalName;
         if ((PetriXmlHelper.XML_STATE_NAMESPACE.Equals(namespaceUri)) && ("Token".Equals(localName)))
         {
             long tokUnid = PetriXmlHelper.openLongAttributeFromNode(childNode, "unid", PetriXmlHelper.XML_STATE_NAMESPACE);
             Token token = Token.findTokenByUnid(alltokens, tokUnid);
             if (token == null)
             {
                 token = new Token("", tokUnid, true, Color.Black);
             }
             ret.Add(token);
         }
     }
     return ret;
 }
Esempio n. 5
0
 internal void addToken(Token item)
 {
     if (!this.tokens.Contains(item))
     {
         this.tokens.Add(item);
     }
 }