/// <summary> /// This function is called by a PNPlace if it received enough tokens to satisfy the fire condition belongs to it, /// or when this fire condition cannot be satisfied anymore. /// </summary> /// <param name="caller">The place that called this function.</param> /// <param name="satisfied">True if the fire condition can be satisfied or false otherwise.</param> public void FireConditionChange(PNPlace caller, bool satisfied) { if (!this.fireConditions.ContainsKey(caller)) { throw new PetriNetException("The given place is not registered to the transition as an input place!"); } if (satisfied) { /// A fire condition satisfied. if (!this.fireable && !this.fireConditions[caller]) { this.fireConditions[caller] = true; foreach (KeyValuePair <PNPlace, bool> condition in this.fireConditions) { if (!condition.Value) { /// There are other unsatisfied fire conditions, so we can return. return; } } /// This was the last unsatisfied fire condition. this.fireable = true; this.group.TransitionBecameFireable(this, true); } } else { /// The fire condition cannot be satisfied, so the transition becomes unfireable. this.fireConditions[caller] = false; this.fireable = false; this.group.TransitionBecameFireable(this, false); } }
/// <summary> /// Creates an edge from this transition to the given place with the given weight. /// </summary> /// <param name="target">The target place of the edge.</param> /// <param name="weight">The weight of the edge.</param> public void CreateOutputEdge(PNPlace target, int weight) { if (!this.outputEdges.ContainsKey(target)) { this.outputEdges.Add(target, weight); } else { throw new ArgumentException("Output edge to the given target already exists!"); } }
/// <summary> /// Registers an edge from the given place to this transition. /// </summary> /// <param name="source">The source place of the registered edge.</param> public void RegisterInputEdge(PNPlace source) { if (!this.fireConditions.ContainsKey(source)) { this.fireConditions.Add(source, false); this.inputEdges.Add(source); this.fireable = false; this.group.TransitionBecameFireable(this, false); } else { throw new ArgumentException("Input edge from the given source already exists!"); } }