3.1.8.3. causality/Petri¶
-
class
mod.
PetriNet
¶ Adaptation of a derivation graph into a Petri net. Importantly, if the underlying derivation graph is enlarged then
syncSize()
must be called before calling certain other methods on the object.-
__init__
(self, dg)¶ Calls
syncSize()
.- Parameters
dg (DG) – the derivation graph to adapt.
- Returns
a new Petri net, adapting the given derivation graph.
- Raises
LogicError
ifdg
isNone
.- Raises
LogicError
if neitherdg.hasActiveBuilder
nordg.locked
.
-
syncSize
()¶ Enlarges the internal data structures to the current size of the underlying derivation graph.
-
getPostPlaces
(e)¶ - Parameters
e (DGHyperEdge) – the hyperedge to find unique targets for.
- Returns
a list of unique targets for the given hyperedge.
- Return type
Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.
-
-
class
mod.
PetriNetMarking
¶ Representation of a marking on a Petri net. Importantly, if the underlying derivation graph is enlarged then
syncSize()
must be called before calling certain other methods on the object.-
__init__
(net)¶ - Parameters
net (PetriNet) – the Petri net to construct a marking for.
- Raises
LogicError
ifnet
isNone
.
-
syncSize
()¶ Enlarges the internal data structures to the current size of the underlying derivation graph.
Calls
net.syncSize()
.
-
__str__
(self)¶ Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.
-
add
(v, c)¶ Add c tokens on the place v.
- Parameters
- Returns
the new total token count on v.
- Return type
- Raises
LogicError
ifnot v
.- Raises
LogicError
ifv.dg != self.net.dg
.- Throws
LogicError
ifc < 0
.
Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.
-
remove
(v, c)¶ Remove c tokens from the place v.
- Parameters
- Returns
the new total token count on v.
- Return type
- Raises
LogicError
ifnot v
.- Raises
LogicError
ifv.dg != self.net.dg
.- Throws
LogicError
ifc < 0
.- Throws
LogicError
if not enough tokens are left to remove allc
.
Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.
-
__getitem__
(v)¶ - Parameters
v (DGVertex) – the place to remove tokens from.
- Returns
the token count for v.
- Return type
- Raises
LogicError
ifnot v
.- Raises
LogicError
ifv.dg != self.net.dg
.
Requires
syncSize()
to have been called since the last time the underlying derivation graph has changed size.
-
getAllEnabled
()¶ - Returns
a list of all hyperedges currently enabled for firing.
- Return type
-
getEmptyPostPlaces
(e)¶ - Parameters
e (DGHyperEdge) – the edge to query for empty post places.
- Returns
a list of all target vertices of the given hyperedge that do not have any tokens. The list represents a set, so if vertex is a target multiple times it will only be included once.
- Return type
- Raises
LogicError
ifnot e
.- Raises
LogicError
ife.dg != self.net.dg
.
-
isEnabled
(e)¶ - Parameters
e (DGHyperEdge) – the edge to query for being enabled.
- Returns
whether the given hyperedge is enabled for firing.
- Return type
- Raises
LogicError
ifnot e
.- Raises
LogicError
ife.dg != self.net.dg
.
-
fire
(e)¶ - Parameters
e (DGHyperEdge) – the edge to fire.
- Raises
LogicError
ifnot e
.- Raises
LogicError
ife.dg != self.net.dg
.- Raises
LogicError
ifnot self.isEnabled(e)
.
-