A plugin to record for each not to which modules it belongs.

Modules are arbitrary values, each PetriNet, Place or transition is attached a set of modules. These modules can be given at construction time, as a single value or a collection of values. Moreover, when nodes are attached to a net, they inherit the modules from this net. When nodes are merged, their sets of modules is added to build the set of modules of the new node.

The plugin implements a very basic notion of modules, un particular, it does not support hierarchy and when a module is attached to a node, it is not possible to remove it. So modules are only a way to remember where a node comes from and to tag nodes as we aggregate nets, e.g., through compositions (see plugin ops).

Internally, modules are stored in a label called "modules" (see plugin snakes.plugins.labels).

>>> import snakes.plugins
>>> snakes.plugins.load(["ops", "modules"], "snakes.nets", "snk")
<module 'snk' ...>
>>> from snk import *
>>> n1 = PetriNet("n1", modules="hello")
>>> n1.add_place(Place("p"))
>>> n1.place("p").modules()
set(['hello'])
>>> n1.add_place(Place("q"))
>>> n2 = PetriNet("n2", modules="world")
>>> n2.add_place(Place("r"))
>>> n2.add_place(Place("s", modules="spam"))
>>> n = n1|n2
>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place()))
[('[p|]', ['hello']),
 ('[q|]', ['hello']),
 ('[|r]', ['world']),
 ('[|s]', ['spam', 'world'])]
>>> n.modules("egg")
>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place()))
[('[p|]', ['egg', 'hello']),
 ('[q|]', ['egg', 'hello']),
 ('[|r]', ['egg', 'world']),
 ('[|s]', ['egg', 'spam', 'world'])]

Extensions

Class Transition

class Transition (module.Transition) :

Method Transition.__init__

def __init__ (self, name, guard=None, **options) :

Method Transition.modules

def modules (self, modules=None) :

Class Place

class Place (module.Place) :

Method Place.__init__

def __init__ (self, name, tokens=[], check=None, **options) :

Method Place.modules

def modules (self, modules=None) :

Class PetriNet

class PetriNet (module.PetriNet) :

Method PetriNet.__init__

def __init__ (self, name, **options) :

Method PetriNet.modules

def modules (self, modules=None) :

Method PetriNet.add_place

def add_place (self, place, **options) :

Method PetriNet.add_transition

def add_transition (self, trans, **options) :

Method PetriNet.merge_places

def merge_places (self, target, sources, **options) :

Method PetriNet.merge_transitions

def merge_transitions (self, target, sources, **options) :