3.2.11.5. causality/Petri.hpp

3.2.11.5.1. Class causality::Net

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.

3.2.11.5.1.1. Synopsis

std::shared_ptr<dg::DG> getDG() const
friend std::ostream &operator<<(std::ostream &s, const Net &net)
void syncSize()
std::vector<dg::DG::Vertex> getPostPlaces(dg::DG::HyperEdge e) const
static std::shared_ptr<Net> make(std::shared_ptr<dg::DG> dg_)

3.2.11.5.1.2. Details

std::shared_ptr<dg::DG> getDG() const
Returns:

the underlying derivation graph.

friend std::ostream &operator<<(std::ostream &s, const Net &net)
void syncSize()

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

std::vector<dg::DG::Vertex> getPostPlaces(dg::DG::HyperEdge e) const
Returns:

a list of unique targets for the given hyperedge.

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

static std::shared_ptr<Net> make(std::shared_ptr<dg::DG> dg_)

Calls syncSize().

Returns:

a new Petri net, adapting the given derivation graph.

Throws:

LogicError if dg_ is null.

Throws:

LogicError if neither dg_->hasActiveBuilder() nor dg_->isLocked().

3.2.11.5.2. Class causality::Marking

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.

3.2.11.5.2.1. Synopsis

explicit Marking(std::shared_ptr<Net> net)
std::shared_ptr<Net> getNet() const
void syncSize() const
friend std::ostream &operator<<(std::ostream &s, const Marking &m)
friend bool operator==(const Marking &a, const Marking &b)
friend bool operator!=(const Marking &a, const Marking &b)
int add(dg::DG::Vertex v, int c)
int add(std::shared_ptr<graph::Graph> g, int c)
int remove(dg::DG::Vertex v, int c)
int remove(std::shared_ptr<graph::Graph> g, int c)
int operator[](dg::DG::Vertex v)
int operator[](std::shared_ptr<graph::Graph> g) const
int getNumTokens() const
std::vector<dg::DG::HyperEdge> getAllEnabled() const
std::vector<dg::DG::Vertex> getNonZeroPlaces() const
std::vector<dg::DG::Vertex> getEmptyPostPlaces(dg::DG::HyperEdge e) const
bool isEnabled(dg::DG::HyperEdge e) const
void fire(dg::DG::HyperEdge e)

3.2.11.5.2.2. Details

explicit Marking(std::shared_ptr<Net> net)
Throws:

LogicError if net is null.

std::shared_ptr<Net> getNet() const
Returns:

the underlying Petri net.

void syncSize() const

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

Calls getNet().syncSize().

friend std::ostream &operator<<(std::ostream &s, const Marking &m)

Calls syncSize().

friend bool operator==(const Marking &a, const Marking &b)
friend bool operator!=(const Marking &a, const Marking &b)

May call a.syncSize() and b.syncSize().

int add(dg::DG::Vertex v, int c)
int add(std::shared_ptr<graph::Graph> g, int c)

Add c tokens on the place v. The graph version is equivalent to add(getNet()->getDG()->findVertex(g), c).

Returns:

the new total token count on v.

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getNet()->getDG().

Throws:

LogicError if c < 0.

Throws:

LogicError if !g.

Throws:

LogicError if !getNet()->getDG()->findVertex(g).

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

int remove(dg::DG::Vertex v, int c)
int remove(std::shared_ptr<graph::Graph> g, int c)

Remove c tokens from the place v. The graph version is equivalent to remove(getNet()->getDG()->findVertex(g), c).

Returns:

the new total token count on v.

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getNet()->getDG().

Throws:

LogicError if c < 0.

Throws:

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

Throws:

LogicError if !g.

Throws:

LogicError if !getNet()->getDG()->findVertex(g).

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

int operator[](dg::DG::Vertex v)
int operator[](std::shared_ptr<graph::Graph> g) const
Returns:

the token count for v. The graph version is equivalent to first calling getNet()->getDG()->findVertex(g) before using it as index to the marking.

Throws:

LogicError if !v.

Throws:

LogicError if v.getDG() != getNet()->getDG().

Throws:

LogicError if !g.

Throws:

LogicError if !getNet()->getDG()->findVertex(g).

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

int getNumTokens() const
Returns:

the total number of tokens in the marking.

std::vector<dg::DG::HyperEdge> getAllEnabled() const
Returns:

a list of all hyperedges currently enabled for firing.

std::vector<dg::DG::Vertex> getNonZeroPlaces() const
Returns:

a list of all vertices with tokens.

std::vector<dg::DG::Vertex> getEmptyPostPlaces(dg::DG::HyperEdge e) const
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.

Throws:

LogicError if !e.

Throws:

LogicError if e.getDG() != getNet()->getDG().

bool isEnabled(dg::DG::HyperEdge e) const
Returns:

whether the given hyperedge is enabled for firing.

Throws:

LogicError if !e.

Throws:

LogicError if e.getDG() != getNet()->getDG().

void fire(dg::DG::HyperEdge e)

Fire the given edge.

Throws:

LogicError if !e.

Throws:

LogicError if e.getDG() != getNet()->getDG().

Throws:

LogicError if !isEnabled(e).