Showing
1 changed file
with
21 additions
and
7 deletions
... | @@ -7,6 +7,12 @@ Moreover, when nodes are attached to a net, they inherit the modules | ... | @@ -7,6 +7,12 @@ Moreover, when nodes are attached to a net, they inherit the modules |
7 | from this net. When nodes are merged, their sets of modules is added | 7 | from this net. When nodes are merged, their sets of modules is added |
8 | to build the set of modules of the new node. | 8 | to build the set of modules of the new node. |
9 | 9 | ||
10 | +The plugin implements a very basic notion of modules, un particular, | ||
11 | +it does not support hierarchy and when a module is attached to a node, | ||
12 | +it is not possible to remove it. So modules are only a way to remember | ||
13 | +where a node comes from and to tag nodes as we aggregate nets, e.g., | ||
14 | +through compositions (see plugin `ops`). | ||
15 | + | ||
10 | Internally, modules are stored in a label called `"modules"` (see | 16 | Internally, modules are stored in a label called `"modules"` (see |
11 | plugin `snakes.plugins.labels`). | 17 | plugin `snakes.plugins.labels`). |
12 | 18 | ||
... | @@ -23,11 +29,17 @@ set(['hello']) | ... | @@ -23,11 +29,17 @@ set(['hello']) |
23 | >>> n2.add_place(Place("r")) | 29 | >>> n2.add_place(Place("r")) |
24 | >>> n2.add_place(Place("s", modules="spam")) | 30 | >>> n2.add_place(Place("s", modules="spam")) |
25 | >>> n = n1|n2 | 31 | >>> n = n1|n2 |
26 | ->>> list(sorted((p.name, p.modules()) for p in n.place())) | 32 | +>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place())) |
27 | -[('[p|]', set(['hello'])), | 33 | +[('[p|]', ['hello']), |
28 | - ('[q|]', set(['hello'])), | 34 | + ('[q|]', ['hello']), |
29 | - ('[|r]', set(['world'])), | 35 | + ('[|r]', ['world']), |
30 | - ('[|s]', set(['world', 'spam']))] | 36 | + ('[|s]', ['spam', 'world'])] |
37 | +>>> n.modules("egg") | ||
38 | +>>> list(sorted((p.name, list(sorted(p.modules()))) for p in n.place())) | ||
39 | +[('[p|]', ['egg', 'hello']), | ||
40 | + ('[q|]', ['egg', 'hello']), | ||
41 | + ('[|r]', ['egg', 'world']), | ||
42 | + ('[|s]', ['egg', 'spam', 'world'])] | ||
31 | """ | 43 | """ |
32 | 44 | ||
33 | from snakes.plugins import plugin, new_instance | 45 | from snakes.plugins import plugin, new_instance |
... | @@ -65,8 +77,10 @@ def extend (module) : | ... | @@ -65,8 +77,10 @@ def extend (module) : |
65 | def modules (self, modules=None) : | 77 | def modules (self, modules=None) : |
66 | if modules is None : | 78 | if modules is None : |
67 | return self.label("modules") | 79 | return self.label("modules") |
68 | - else : | 80 | + mod = set(iterate(modules)) |
69 | - self.label(modules=set(iterate(modules))) | 81 | + self.label(modules=mod) |
82 | + for node in self.node() : | ||
83 | + node.modules(mod | node.modules()) | ||
70 | def add_place (self, place, **options) : | 84 | def add_place (self, place, **options) : |
71 | mod = set(iterate(options.pop("modules", self.modules()))) | 85 | mod = set(iterate(options.pop("modules", self.modules()))) |
72 | module.PetriNet.add_place(self, place, **options) | 86 | module.PetriNet.add_place(self, place, **options) | ... | ... |
-
Please register or login to post a comment