3.2.13.6. rule/Rule.hpp

3.2.13.6.1. Class rule::Rule

class rule::Rule

This class models a graph transformation rule in the Double Pushout formalism, as the span \(L \leftarrow K \rightarrow R\). The three graphs are referred to as respectively the “left”, “context”, and “right” graphs of the rule. See Graph, Rule, and Molecule Model for more details.

See rule/GraphInterface.hpp for the documentation for the graph interface for this class.

3.2.13.6.1.1. Synopsis

class rule::Rule::LeftGraph
class rule::Rule::ContextGraph
class rule::Rule::RightGraph
class rule::Rule::Vertex
class rule::Rule::Edge
class rule::Rule::VertexIterator
class rule::Rule::VertexRange
class rule::Rule::EdgeIterator
class rule::Rule::EdgeRange
class rule::Rule::IncidentEdgeIterator
class rule::Rule::IncidentEdgeRange
unsigned int getId() const
std::size_t numVertices() const
VertexRange vertices() const
std::size_t numEdges() const
EdgeRange edges() const
LeftGraph getLeft() const
ContextGraph getContext() const
RightGraph getRight() const
std::shared_ptr<Rule> makeInverse() const
std::pair<std::string, std::string> print() const
std::pair<std::string, std::string> print(bool printCombined) const
std::pair<std::string, std::string> print(const graph::Printer &first, const graph::Printer &second) const
std::pair<std::string, std::string> print(const graph::Printer &first, const graph::Printer &second, bool printCombined) const
void printTermState() const
std::string getGMLString(bool withCoords = false) const
std::string printGML(bool withCoords = false) const
const std::string &getName() const
void setName(std::string name)
std::optional<LabelType> getLabelType() const
std::size_t getNumLeftComponents() const
std::size_t getNumRightComponents() const
std::size_t isomorphism(std::shared_ptr<Rule> r, std::size_t maxNumMatches, LabelSettings labelSettings) const
std::size_t monomorphism(std::shared_ptr<Rule> r, std::size_t maxNumMatches, LabelSettings labelSettings) const
bool isomorphicLeftRight(std::shared_ptr<Rule> r, LabelSettings labelSettings) const
Vertex getVertexFromExternalId(int id) const
int getMinExternalId() const
int getMaxExternalId() const
static std::shared_ptr<Rule> fromGMLString(const std::string &data, bool invert, bool printStereoWarnings)
static std::shared_ptr<Rule> fromGMLFile(const std::string &file, bool invert, bool printStereoWarnings)
static std::shared_ptr<Rule> fromDFS(const std::string &data, bool invert)
static std::shared_ptr<Rule> makeRule(std::unique_ptr<lib::Rules::Real> r)
static std::shared_ptr<Rule> makeRule(std::unique_ptr<lib::Rules::Real> r, std::map<int, std::size_t> externalToInternalIds)

3.2.13.6.1.2. Details

unsigned int getId() const
Returns:

the unique instance id among all Rule instances.

std::size_t numVertices() const
Returns:

the number of vertices in the rule.

VertexRange vertices() const
Returns:

a range of all vertices in the rule.

std::size_t numEdges() const
Returns:

the number of edges in the rule.

EdgeRange edges() const
Returns:

a range of all edges in the rule.

LeftGraph getLeft() const
Returns:

a proxy object representing the left graph of the rule.

ContextGraph getContext() const
Returns:

a proxy object representing the context graph of the rule.

RightGraph getRight() const
Returns:

a proxy object representing the rule graph of the rule.

std::shared_ptr<Rule> makeInverse() const
Returns:

a rule representing the inversion of this rule.

Raises:

LogicError if inversion is not possible (due to matching constraints).

std::pair<std::string, std::string> print() const
std::pair<std::string, std::string> print(bool printCombined) const
std::pair<std::string, std::string> print(const graph::Printer &first, const graph::Printer &second) const
std::pair<std::string, std::string> print(const graph::Printer &first, const graph::Printer &second, bool printCombined) const

Print the rule, using either the default options or the options in first and second. If first and second are the same, only one depiction will be made.

Parameters:

printCombined – whether a depiction of the rule as a single combined graph is printed. Defaults to false.

Returns:

a pair of filename prefixes for the PDF-files that will be compiled in post-processing. The actual names can be obtained by appending _L.pdf, _K.pdf, and _R.pdf for respectively the left side, context, and right side graphs. If first and second are the same, the two file prefixes are equal.

void printTermState() const

Print the term state for the rule.

std::string getGMLString(bool withCoords = false) const
Returns:

the GML representation of the rule, optionally with generated 2D coordinates.

Throws:

LogicError when coordinates are requested, but none can be generated.

std::string printGML(bool withCoords = false) const

Print the rule in GML format, optionally with generated 2D coordinates.

Returns:

the filename of the printed GML file.

Throws:

LogicError when coordinates are requested, but none can be generated.

const std::string &getName() const
void setName(std::string name)

Access the name of the rule.

std::optional<LabelType> getLabelType() const
Returns:

the intended label type for this rule, or nothing if no specific label type is intended.

std::size_t getNumLeftComponents() const
Returns:

the number of connected components in the left graph.

std::size_t getNumRightComponents() const
Returns:

the number of connected components in the right graph.

std::size_t isomorphism(std::shared_ptr<Rule> r, std::size_t maxNumMatches, LabelSettings labelSettings) const
Returns:

the number of isomorphisms found between r and this graph, but at most maxNumMatches.

std::size_t monomorphism(std::shared_ptr<Rule> r, std::size_t maxNumMatches, LabelSettings labelSettings) const
Returns:

the number of monomorphism from this rule to subgraphs of r, though at most maxNumMatches.

bool isomorphicLeftRight(std::shared_ptr<Rule> r, LabelSettings labelSettings) const
Returns:

whether the left-hand sides are isomorphic and the right-hand sides are isomorphic.

Vertex getVertexFromExternalId(int id) const

If the rule was not loaded from an external data format, then this function always return a null descriptor.

Note

In general there is no correlation between external and internal ids.

Returns:

the vertex descriptor for the given external id. The descriptor is null if the external id was not used.

int getMinExternalId() const
int getMaxExternalId() const

If the rule was not loaded from an external data format, then these functions always return 0. Otherwise, return the minimum/maximum external id from which non-null vertices can be obtained from getVertexFromExternalId(). If no such minimum and maximum exists, then 0 will be returned.

static std::shared_ptr<Rule> fromGMLString(const std::string &data, bool invert, bool printStereoWarnings)
static std::shared_ptr<Rule> fromGMLFile(const std::string &file, bool invert, bool printStereoWarnings)

Load a rule from a GML string or file, and store either that rule or its inverse. The name of the rule is the one specified in the GML string, though when invert=True the string “, inverse” is appended to the name.

Note

If the GML string specifies matching constraints it is not possible to invert the rule. There is however a configuration option to ignore matching constraints when inverting rules.

Parameters:

printStereoWarnings – whether to print warnings due to unhandled stereo information.

Returns:

the loaded (possibly inverted) rule.

Throws:

InputError on bad data and when inversion fails due to constraints.

static std::shared_ptr<Rule> fromDFS(const std::string &data, bool invert)

Load a rule from a RuleDFS string, and store either that rule or its inverse. The name of the rule is the one specified, though when invert=True the string “, inverse” is appended to the name.

Returns:

the loaded (possibly inverted) rule.

Throws:

InputError on bad data and when inversion fails due to constraints.

static std::shared_ptr<Rule> makeRule(std::unique_ptr<lib::Rules::Real> r)
static std::shared_ptr<Rule> makeRule(std::unique_ptr<lib::Rules::Real> r, std::map<int, std::size_t> externalToInternalIds)
Returns:

a rule wrapping the given internal rule object. If an id mapping is given, it will be used for the getVertexFromExternalId() function.