A plugin to add labels to nodes and nets. Labels are names (valid Python identifiers) associated to arbitrary objects.

>>> import snakes.plugins
>>> snakes.plugins.load('labels', 'snakes.nets', 'nets')
<module ...>
>>> from nets import *
>>> t = Transition('t')
>>> t.label(foo='bar', spam=42)
>>> t.label('foo')
'bar'
>>> t.label('spam')
42

Note that when nodes in a Petri net are merged, their labels are merged too, but in an arbitrary order. So, for example:

>>> n = PetriNet('N')
>>> n.add_place(Place('p1'))
>>> n.place('p1').label(foo='bar', spam='ham')
>>> n.add_place(Place('p2'))
>>> n.place('p2').label(hello='world', spam='egg')
>>> n.merge_places('p', ['p1', 'p2'])
>>> n.place('p').label('hello')
'world'
>>> n.place('p').label('foo')
'bar'
>>> n.place('p').label('spam') in ['ham', 'egg']
True

In the latter statement, we cannot know whether the label will be one or the other value because merging has been done in an arbitrary order.

Extensions

Class Transition

class Transition (module.Transition) :

Method Transition.label

def label (self, *get, **set) :

Get and set labels for the transition. The labels given in get will be returned as a tuple and the labels assigned in set will be changed accordingly. If a label is given both in getand set, the returned value is that it had at the beginning of the call, ie, before it is set by the call.

Call API
Exceptions

Method Transition.has_label

def has_label (self, name, *names) :

Check is a label has been assigned to the transition.

Call API

Class Place

class Place (module.Place) :

Method Place.label

def label (self, *get, **set) :

See documentation for Transition.label above

Method Place.has_label

def has_label (self, name, *names) :

See documentation for Transition.has_label above

Class PetriNet

class PetriNet (module.PetriNet) :

Method PetriNet.label

def label (self, *get, **set) :

See documentation for Transition.label above

Method PetriNet.has_label

def has_label (self, name, *names) :

See documentation for Transition.has_label above