4.1.8.4. causality/Petri

class causality.Net

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__(dg)

Calls syncSize().

Parameters:

dg (DG) – the derivation graph to adapt.

Returns:

a new Petri net, adapting the given derivation graph.

Raises:

LogicError if dg is None.

Raises:

LogicError if neither dg.hasActiveBuilder nor dg.locked.

dg

(Read-only) The underlying derivation graph.

Type:

DG

syncSize()

Enlarges the internal data structures to the current size of the underlying derivation graph.

getPostPlaces(e)
Parameters:

e (DG.HyperEdge) – the hyperedge to find unique targets for.

Returns:

a list of unique targets for the given hyperedge.

Return type:

list[DG.Vertex]

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.

class causality.Marking

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 (Net) – the Petri net to construct a marking for.

Raises:

LogicError if net is None.

net

(Read-only) The underlying Petri net.

Type:

Net

syncSize()

Enlarges the internal data structures to the current size of the underlying derivation graph.

Calls net.syncSize().

__eq__()
add(v, c)
add(g, c)

Add c tokens on the place v. The second version is equivalent to self.add(self.net.dg.findVertex(g), c).

Parameters:
  • v (DG.Vertex) – the place to add tokens to.

  • g (Graph) – the graph associated to the place to add tokens to.

  • c (int) – the amount of tokens to add.

Returns:

the new total token count on v.

Return type:

int

Raises:

LogicError if not v.

Raises:

LogicError if v.dg != self.net.dg.

Raises:

LogicError if c < 0.

Raises:

LogicError if g is None.

Raises:

LogicError if !self.net.dg.findVertex(g).

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.

remove(v, c)
remove(g, c)

Remove c tokens from the place v. The second version is equivalent to self.remove(self.net.dg.findVertex(g), c).

Parameters:
  • v (DG.Vertex) – the place to remove tokens from.

  • g (Graph) – the graph associated to the place to remove tokens from.

  • c (int) – the amount of tokens to remove.

Returns:

the new total token count on v.

Return type:

int

Raises:

LogicError if not v.

Raises:

LogicError if v.dg != self.net.dg.

Raises:

LogicError if c < 0.

Raises:

LogicError if not enough tokens are left to remove all c.

Raises:

LogicError if g is None.

Raises:

LogicError if !self.net.dg.findVertex(g).

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.

__getitem__(v)
__getitem__(g)
Parameters:
  • v (DG.Vertex) – the place to query the number of tokens for.

  • g (Graph) – the graph associated to the place to query the number of tokens for.

Returns:

the token count for v. The second version is equivalent to self[self.net.dg.findVertex(g)].

Return type:

int

Raises:

LogicError if not v.

Raises:

LogicError if v.dg != self.net.dg.

Raises:

LogicError if g is None.

Raises:

LogicError if !self.net.dg.findVertex(g).

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.

numTokens

(Read-only) The total number of tokens in the marking.

Type:

int

getAllEnabled()
Returns:

a list of all hyperedges currently enabled for firing.

Return type:

list[DG.HyperEdge]

getNonZeroPlaces()
Returns:

a list of all vertices with tokens.

Return type:

list[DG.Vertex]

getEmptyPostPlaces(e)
Parameters:

e (DG.HyperEdge) – 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:

list[DG.Vertex]

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != self.net.dg.

isEnabled(e)
Parameters:

e (DG.HyperEdge) – the edge to query for being enabled.

Returns:

whether the given hyperedge is enabled for firing.

Return type:

bool

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != self.net.dg.

fire(e)
Parameters:

e (DG.HyperEdge) – the edge to fire.

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != self.net.dg.

Raises:

LogicError if not self.isEnabled(e).