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())
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))
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)
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)
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)
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)
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)
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()
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()
def modules (self, modules=None) : if modules is None : return self.label("modules") else : self.label(modules=set(iterate(modules)))
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)
def Any(items): return SetOfSets([m] for m in iterate(items))
def __init__(self, sets): self.sets = frozenset(frozenset(iterate(s)) for s in iterate(sets))
def __init__ (self, name, **options) : mod = set(iterate(options.pop("modules", []))) module.PetriNet.__init__(self, name, **options) self.modules(mod)
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)
def __init__ (self, name, guard=None, **options) : mod = set(iterate(options.pop("modules", []))) module.Transition.__init__(self, name, guard, **options) self.modules(mod)
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)
def All(items): return SetOfSets([iterate(items)])