/** * Fires a transition in this marking. Changes this marking. * * @param transition transition to be fired in the marking * @return false if the specified transition was not enabled, otherwise true */ public boolean fire(Transition transition) { boolean success; lock.writeLock().lock(); try { if (isEnabled(transition)) { for (Arc arc : transition.getConnectedArcs()) { if (arc.isPlaceToTransition()) { int tokens = getTokens(arc.getPlaceNode()); if (!arc.getInhibitory()) { // inhibitory arc doesnt consume tokens if (arc.getReset()) { // reset arc consumes them all setTokens(arc.getPlaceNode(), 0); } else { setTokens(arc.getPlaceNode(), tokens - arc.getMultiplicity()); } } } else { int tokens = getTokens(arc.getPlaceNode()); setTokens(arc.getPlaceNode(), tokens + arc.getMultiplicity()); } } success = true; } else { success = false; } } finally { lock.writeLock().unlock(); } return success; }
/** * Determines if a transition is enabled in this marking * * @param transition - transition to be checked * @return true if transition is enabled in the marking, otherwise false */ public boolean isEnabled(Transition transition) { boolean isEnabled = true; lock.readLock().lock(); try { for (Arc arc : transition.getConnectedArcs()) { if (arc.isPlaceToTransition()) { if (arc.getReset()) { // reset arc is always fireable continue; // but can be blocked by other arcs } else { if (!arc.getInhibitory()) { if (getTokens(arc.getPlaceNode()) < arc.getMultiplicity()) { // normal arc isEnabled = false; break; } } else { if (getTokens(arc.getPlaceNode()) >= arc.getMultiplicity()) { // inhibitory arc isEnabled = false; break; } } } } } } finally { lock.readLock().unlock(); } return isEnabled; }