Example #1
0
 def modules (self, modules=None) :
     if modules is None :
         return self.label("modules")
     mod = set(iterate(modules))
     self.label(modules=mod)
     for node in self.node() :
         node.modules(mod | node.modules())
Example #2
0
 def modules (self, modules=None) :
     if modules is None :
         return self.label("modules")
     mod = set(iterate(modules))
     self.label(modules=mod)
     for node in self.node() :
         node.modules(mod | node.modules())
Example #3
0
 def merge_transitions (self, target, sources, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.merge_transitions(self, target, sources, **options)
     new = self.transition(target)
     new.modules(reduce(set.__or__,
                        (self.place(p).modules()
                         for p in sources),
                        mod))
Example #4
0
 def merge_transitions (self, target, sources, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.merge_transitions(self, target, sources, **options)
     new = self.transition(target)
     new.modules(reduce(set.__or__,
                        (self.place(p).modules()
                         for p in sources),
                        mod))
Example #5
0
        def copy_transition (self, source, targets, **args) :
            """Extended with `status` keyword argument.

            @keyword status: a status that is given to the new node
            @type status: `Status`
            """
            status = args.pop("status", self.transition(source).status)
            module.PetriNet.copy_transition(self, source, targets, **args)
            for new in iterate(targets) :
                self.set_status(new, status)
Example #6
0
        def copy_transition(self, source, targets, **args):
            """Extended with `status` keyword argument.

            @keyword status: a status that is given to the new node
            @type status: `Status`
            """
            status = args.pop("status", self.transition(source).status)
            module.PetriNet.copy_transition(self, source, targets, **args)
            for new in iterate(targets):
                self.set_status(new, status)
Example #7
0
        def remove(self, tokens):
            """Remove tokens from the place.

            @param tokens: a collection of tokens to be removed from the
                place, note that `str` are not considered as iterable and
                used a a single value instead of as a collection
            @type tokens: `collection`
            """
            if len(self.tokens) - len(list(iterate(tokens))) < self._bound_min:
                raise ConstraintError(
                    "lower bound of place %r reached" % self.name)
            module.Place.remove(self, tokens)
Example #8
0
        def add(self, tokens):
            """Add tokens to the place.

            @param tokens: a collection of tokens to be added to the
                place, note that `str` are not considered as iterable and
                used a a single value instead of as a collection
            @type tokens: `collection`
            """
            if (self._bound_max is not None
                    and len(self.tokens) + len(list(iterate(tokens))) >
                    self._bound_max):
                raise ConstraintError(
                    "upper bound of place %r reached" % self.name)
            module.Place.add(self, tokens)
Example #9
0
        def reset(self, tokens):
            """Replace the marking with `tokens`.

            @param tokens: a collection of tokens to be removed from the
                place, note that `str` are not considered as iterable and
                used a a single value instead of as a collection
            @type tokens: `collection`
            """
            count = len(list(iterate(tokens)))
            bmax = count if self._bound_max is None else self._bound_max
            if not (self._bound_min <= count <= bmax):
                raise ConstraintError(
                    "not within bounds of place %r" % self.name)
            module.Place.reset(self, tokens)
Example #10
0
        def copy_transition(self, source, targets, **args):
            """Accepts a keyword parameter `actions` to change the
            multiaction of the resulting transition. If `actions` is
            not given, the multiaction of the new transition is the
            the same multiaction as the copied transition.

            @keyword actions: the multiaction of the transition
                resulting from the copy
            @type actions: `MultiAction`
            """
            actions = args.pop("actions", None)
            module.PetriNet.copy_transition(self, source, targets, **args)
            if actions is None:
                actions = self.transition(source).actions
            else:
                actions = MultiAction(actions)
            old = self.transition(source)
            for trans in iterate(targets):
                self.transition(trans).actions = actions.copy()
Example #11
0
        def copy_transition (self, source, targets, **args) :
            """Accepts a keyword parameter `actions` to change the
            multiaction of the resulting transition. If `actions` is
            not given, the multiaction of the new transition is the
            the same multiaction as the copied transition.

            @keyword actions: the multiaction of the transition
                resulting from the copy
            @type actions: `MultiAction`
            """
            actions = args.pop("actions", None)
            module.PetriNet.copy_transition(self, source, targets, **args)
            if actions is None :
                actions = self.transition(source).actions
            else :
                actions = MultiAction(actions)
            old = self.transition(source)
            for trans in iterate(targets) :
                self.transition(trans).actions = actions.copy()
Example #12
0
 def modules (self, modules=None) :
     if modules is None :
         return self.label("modules")
     else :
         self.label(modules=set(iterate(modules)))
Example #13
0
 def add_transition (self, trans, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.add_transition(self, trans, **options)
     trans.modules(trans.modules() | mod)
Example #14
0
def Any(items):
    return SetOfSets([m] for m in iterate(items))
Example #15
0
 def __init__(self, sets):
     self.sets = frozenset(frozenset(iterate(s)) for s in iterate(sets))
Example #16
0
 def __init__ (self, name, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.PetriNet.__init__(self, name, **options)
     self.modules(mod)
Example #17
0
 def modules (self, modules=None) :
     if modules is None :
         return self.label("modules")
     else :
         self.label(modules=set(iterate(modules)))
Example #18
0
 def __init__ (self, name, tokens=[], check=None, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.Place.__init__(self, name, tokens, check, **options)
     self.modules(mod)
Example #19
0
 def __init__ (self, name, guard=None, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.Transition.__init__(self, name, guard, **options)
     self.modules(mod)
Example #20
0
 def __init__ (self, name, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.PetriNet.__init__(self, name, **options)
     self.modules(mod)
Example #21
0
 def __init__ (self, name, tokens=[], check=None, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.Place.__init__(self, name, tokens, check, **options)
     self.modules(mod)
Example #22
0
 def add_place (self, place, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.add_place(self, place, **options)
     place.modules(place.modules() | mod)
Example #23
0
def All(items):
    return SetOfSets([iterate(items)])
Example #24
0
 def add_transition (self, trans, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.add_transition(self, trans, **options)
     trans.modules(trans.modules() | mod)
Example #25
0
 def __init__ (self, name, guard=None, **options) :
     mod = set(iterate(options.pop("modules", [])))
     module.Transition.__init__(self, name, guard, **options)
     self.modules(mod)
Example #26
0
 def add_place (self, place, **options) :
     mod = set(iterate(options.pop("modules", self.modules())))
     module.PetriNet.add_place(self, place, **options)
     place.modules(place.modules() | mod)