A plugin to implement boundedness on places.

When this plugin is loaded, Place constructor accepts a parameter bound that allows to specify the minimal and maximal number of tokens that the place is allowed to carry. (Repeated tokens count as many times as they are repeated.) Exception ConstraintError is raised whenever an operation (like a transition firing) leads to violate any of a place bound. (But note that direct modifications of a Place.tokens are not checked.)

>>> import snakes.plugins
>>> snakes.plugins.load('bound', 'snakes.nets', 'nets')
<module ...>
>>> from nets import *

If parameter bound is given as a non-negative integer, this is the upper bound of the place (and its lower bound is zero).

>>> n = PetriNet('N')
>>> p = Place('p', [dot], bound=3)
>>> n.add_place(p)
>>> put = Transition('put')
>>> n.add_transition(put)
>>> n.add_output('p', 'put', Value(dot))
>>> p.tokens
MultiSet([dot])
>>> put.fire(Substitution())
>>> p.tokens
MultiSet([dot, dot])
>>> put.fire(Substitution())
>>> p.tokens
MultiSet([dot, dot, dot])
>>> put.fire(Substitution())
Traceback (most recent call last):
  ...
ConstraintError: upper bound of place 'p' reached

If bound is given as a pair (n, None) where n is a non-negative integer, then n is the lower bound of the place (and it has no upper bound).

>>> n = PetriNet('N')
>>> p = Place('p', [dot, dot], bound=(1, None))
>>> n.add_place(p)
>>> put = Transition('put')
>>> n.add_transition(put)
>>> n.add_output('p', 'put', Value(dot))
>>> get =  Transition('get')
>>> n.add_transition(get)
>>> n.add_input('p', 'get', Value(dot))
>>> p.tokens
MultiSet([dot, dot])
>>> get.fire(Substitution())
>>> p.tokens
MultiSet([dot])
>>> get.fire(Substitution())
Traceback (most recent call last):
  ...
ConstraintError: lower bound of place 'p' reached
>>> for i in range(100) : # no upper bound
...     put.fire(Substitution())

If bound is given as a pair of non-negative integers (n,m) such that n <= m then n is the lower bound of the place and m its upper bound.

>>> n = PetriNet('N')
>>> p = Place('p', [dot, dot], bound=(1, 3))
>>> n.add_place(p)
>>> put = Transition('put')
>>> n.add_transition(put)
>>> n.add_output('p', 'put', Value(dot))
>>> get =  Transition('get')
>>> n.add_transition(get)
>>> n.add_input('p', 'get', Value(dot))
>>> p.tokens
MultiSet([dot, dot])
>>> put.fire(Substitution())
>>> p.tokens
MultiSet([dot, dot, dot])
>>> put.fire(Substitution())
Traceback (most recent call last):
  ...
ConstraintError: upper bound of place 'p' reached
>>> get.fire(Substitution())
>>> p.tokens
MultiSet([dot, dot])
>>> get.fire(Substitution())
>>> p.tokens
MultiSet([dot])
>>> get.fire(Substitution())
Traceback (most recent call last):
  ...
ConstraintError: lower bound of place 'p' reached

Any other value for bound is refused raising a ValueError.

Extensions

Extends module

Class Place

class Place (module.Place) :

Extend places with boundedness

Method Place.__init__

def __init__ (self, name, tokens, check=None, **args) :

Add new keyword argument bound

Call API

Method Place.add

def add (self, tokens) :

Add tokens to the place.

Call API

Method Place.remove

def remove (self, tokens) :

Remove tokens from the place.

Call API

Method Place.reset

def reset (self, tokens) :

Replace the marking with tokens.

Call API