Example #1
0
        /// <summary>
        /// Adds this Arc to the petrinet and sends notification if a state change is caused. 
        /// </summary>
        /// <param name="callback">The method to be called in case a state change is caused.</param>
        public void Add(CallbackDelegates.TransitionStateChanged callback)
        {
            Source.AddSuccessor(Target);
            Source.AddArc(this);
            Target.AddPredecessor(Source);
            Target.AddArc(this);

            if (Source is IPlace)
            {
                // call the provided method if the status of a transition is changed
                ITransition targetTransition = (ITransition)Target;
                if (((IPlace)Source).TokenCount == 0)
                {
                    bool deactivated = true;
                    foreach (INode sourcePlace in targetTransition.Predecessors)
                    {
                        if (((IPlace)sourcePlace).TokenCount == 0 && !sourcePlace.Equals(Source))
                            deactivated = false;
                    }
                    if (deactivated)
                    {
                        targetTransition.Enabled = false;
                        callback(Target.Id, false);
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Inverses a transition of tokens through this Transition and sends notification about new 
 /// token values.
 /// </summary>
 /// <param name="callbackTrans">
 /// The method to be called by a connected Place if the state of one of its connected
 /// transitions has changed. </param>
 /// <param name="callbackTokens">
 /// The method to be called if the token count of a connected Place has changed. </param>
 public void InverseTransitionTokens(CallbackDelegates.TransitionStateChanged callbackTrans,
                                     CallbackDelegates.TokensChanged callbackTokens)
 {
     // reduce the token count of all successors by one
     foreach (INode successor in Successors)
     {
         IPlace toChange = (IPlace)successor;
         int newTokenCount = toChange.TokenCount - 1;
         if (newTokenCount < 0)
             throw new InvalidOperationException("TokenCount reduced below zero!");
         toChange.ChangeTokenCount(newTokenCount, callbackTrans);
         callbackTokens(toChange.Id, newTokenCount);
     }
     // increase the token count of all predecessors by one
     foreach (INode predecessor in Predecessors)
     {
         IPlace toChange = (IPlace)predecessor;
         int newTokenCount = toChange.TokenCount + 1;
         toChange.ChangeTokenCount(newTokenCount, callbackTrans);
         callbackTokens(toChange.Id, newTokenCount);
     }
 }
Example #3
0
        /// <summary>
        /// Changes the amount of tokens to the amount provided and activates or deactivates transitions
        /// respectively. Sends notification if a transition has been activated or deactivated.
        /// </summary>
        /// <param name="tokenCount">The new amount of tokens.</param>
        /// <param name="callback">The method to be called in case a state change is caused.</param>
        public void ChangeTokenCount(int tokenCount, CallbackDelegates.TransitionStateChanged callback)
        {
            _tokenCount = tokenCount;

            bool checkActivated = tokenCount != 0;
            bool transitionEnabled = checkActivated;
            foreach (INode successor in Successors)
            {
                if (!(checkActivated ^ ((ITransition)successor).Enabled))  // if transition already activated,
                    continue;                                             // continue with next one
                foreach (INode predecessor in successor.Predecessors)
                {
                    if (((IPlace)predecessor).TokenCount == 0)
                        transitionEnabled = !checkActivated;
                }
                if (transitionEnabled)      // if transition needs to be activated
                {
                    ((ITransition)successor).Enabled = checkActivated;   // activate transition
                    callback(successor.Id, checkActivated);
                }
                transitionEnabled = checkActivated;   // reinitialize for next round
            }
        }
Example #4
0
 public void ChangeTokenCount(int tokenCount, CallbackDelegates.TransitionStateChanged callback)
 {
     TokenCount = tokenCount;
 }
Example #5
0
        /// <summary>
        /// Removes this Arc from the petrinet and sends notification if a state change is caused.
        /// </summary>
        /// <param name="callback">The method to be called in case a state change is caused.</param>
        public void Remove(CallbackDelegates.TransitionStateChanged callback)
        {
            // remove the arc from the petrinet
            Source.RemoveSuccessor(Target);
            Source.RemoveArc(this);
            Target.RemovePredecessor(Source);
            Target.RemoveArc(this);

            if (Target is ITransition)
            {
                // call the provided method if the status of a transition is changed
                ITransition targetTransition = (ITransition)Target;
                if (((IPlace)Source).TokenCount == 0)
                {
                    bool activated = true;
                    foreach (INode sourcePlace in targetTransition.Predecessors)
                    {
                        if (((IPlace)sourcePlace).TokenCount == 0)
                            activated = false;
                    }
                    if (activated)
                    {
                        targetTransition.Enabled = true;
                        callback(Target.Id, true);
                    }
                }
            }
        }
Example #6
0
 public void TransitionTokens(CallbackDelegates.TransitionStateChanged callbackTrans, 
                              CallbackDelegates.TokensChanged callbackTokens)
 {
 }
Example #7
0
 public void Remove(CallbackDelegates.TransitionStateChanged callback)
 {
 }