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);
        }
Exemple #2
0
 protected void addItemToTransitionHistory(TransitionHistoryItem item)
 {
     this.transitionHistory.Add(item);
 }