3.2.11.2. dg/DG.hpp¶
3.2.11.2.1. Class dg::DG
¶
-
class dg::DG¶
The derivation graph class. A derivation graph is a directed multi-hypergraph \(\mathcal{H} = (V, E)\). Each hyperedge \(e\in E\) is thus an ordered pair \((e^+, e^-)\) of multisets of vertices, the sources and the targets. Each vertex is annotated with a graph, and each hyperedge is annotated with list of transformation rules. A derivation graph is constructed incrementally using a
Builder
obtained from thebuild()
function. When the obtained builder is destructed the derivation graph becomes locked and can no longer be modified.
3.2.11.2.1.1. Synopsis¶
-
std::size_t getId() const
-
friend std::ostream &operator<<(std::ostream &s, const DG &dg)
-
const lib::DG::NonHyper &getNonHyper() const
-
const lib::DG::Hyper &getHyper() const
-
LabelSettings getLabelSettings() const
-
bool hasActiveBuilder() const
-
bool isLocked() const
-
std::size_t numVertices() const
-
VertexRange vertices() const
-
std::size_t numEdges() const
-
EdgeRange edges() const
-
Vertex findVertex(std::shared_ptr<graph::Graph> g) const
-
HyperEdge findEdge(const std::vector<Vertex> &sources, const std::vector<Vertex> &targets) const
-
HyperEdge findEdge(const std::vector<std::shared_ptr<graph::Graph>> &sources, const std::vector<std::shared_ptr<graph::Graph>> &targets) const
-
Builder build()
-
Builder build(std::shared_ptr<Function<void(dg::DG::Vertex)>> onNewVertex, std::shared_ptr<Function<void(dg::DG::HyperEdge)>> onNewHyperEdge)
-
const std::vector<std::shared_ptr<graph::Graph>> &getGraphDatabase() const
-
const std::vector<std::shared_ptr<graph::Graph>> &getProducts() const
-
std::pair<std::string, std::string> print(const Printer &printer, const PrintData &data) const
-
std::string printNonHyper() const
-
std::string dump() const
-
std::string dump(const std::string &filename) const
-
void listStats() const
-
static std::shared_ptr<DG> make(LabelSettings labelSettings, const std::vector<std::shared_ptr<graph::Graph>> &graphDatabase, IsomorphismPolicy graphPolicy)
-
static std::shared_ptr<DG> load(const std::vector<std::shared_ptr<graph::Graph>> &graphDatabase, const std::vector<std::shared_ptr<rule::Rule>> &ruleDatabase, const std::string &file, IsomorphismPolicy graphPolicy)
-
static std::shared_ptr<DG> load(const std::vector<std::shared_ptr<graph::Graph>> &graphDatabase, const std::vector<std::shared_ptr<rule::Rule>> &ruleDatabase, const std::string &file, IsomorphismPolicy graphPolicy, int verbosity)
-
static void diff(std::shared_ptr<DG> dg1, std::shared_ptr<DG> dg2)
-
class dg::DG::Vertex
-
class dg::DG::HyperEdge
-
class dg::DG::VertexIterator
-
class dg::DG::VertexRange
-
class dg::DG::EdgeIterator
-
class dg::DG::EdgeRange
-
class dg::DG::InEdgeIterator
-
class dg::DG::InEdgeRange
-
class dg::DG::OutEdgeIterator
-
class dg::DG::OutEdgeRange
-
class dg::DG::SourceIterator
-
class dg::DG::SourceRange
-
class dg::DG::TargetIterator
-
class dg::DG::TargetRange
-
class dg::DG::RuleIterator
-
class dg::DG::RuleRange
3.2.11.2.1.2. Details¶
-
std::size_t getId() const¶
- Returns:
the instance identifier for the object.
-
const lib::DG::NonHyper &getNonHyper() const¶
-
const lib::DG::Hyper &getHyper() const¶
- Returns:
the internal data structures of the derivation graph.
-
LabelSettings getLabelSettings() const¶
- Returns:
the label settings for the derivation graph.
-
bool hasActiveBuilder() const¶
-
bool isLocked() const¶
- Returns:
whether the derivation graph is locked or not.
-
std::size_t numVertices() const¶
- Returns:
the number of vertices in the derivation graph.
- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().
-
VertexRange vertices() const¶
- Returns:
a range of all vertices in the derivation graph.
- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().
-
std::size_t numEdges() const¶
- Returns:
the number of edges in the derivation graph.
- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().
-
EdgeRange edges() const¶
- Returns:
a range of all edges in the derivation graph.
- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().
- Returns:
a vertex descriptor for which the given graph is associated, or a null descriptor if no such vertex exists.
- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().- Throws:
LogicError
if g is a nullptr.
-
HyperEdge findEdge(const std::vector<Vertex> &sources, const std::vector<Vertex> &targets) const¶
- Returns:
a hyperedge with the given sources and targets. If no such hyperedge exists in the derivation graph then a null edge is returned. In the second version, the graphs are put through
findVertex()
first.- Throws:
LogicError
if a vertex descriptor is null, or does not belong to the derivation graph.- Throws:
LogicError
if neither hasActiveBuilder() nor isLocked().
-
Builder build()¶
- Parameters:
onNewVertex – a callback invoked when a new vertex is added to the underlying derivation graph. Defaults to nullptr.
onNewHyperEdge – a callback invoked when a new hyperedge is added to the underlying derivation graph. Defaults to nullptr.
- Returns:
an RAII-style move-only object which can be used to construct the derivation graph. Only one of these objects can be active at the same time, and on destruction an active builder object will lock the associated DG object for further modification.
- Throws:
LogicError
if hasActiveBuilder().- Throws:
LogicError
if isLocked().
-
const std::vector<std::shared_ptr<graph::Graph>> &getGraphDatabase() const¶
- Returns:
a list of all graphs created by the derivation graph, and all graphs given when constructed.
-
const std::vector<std::shared_ptr<graph::Graph>> &getProducts() const¶
- Returns:
the list of new graphs discovered by the derivation graph.
-
std::pair<std::string, std::string> print(const Printer &printer, const PrintData &data) const¶
Print the derivation graph in style of a hypergraph.
- Returns:
the name of the PDF-file that will be compiled in post-processing and the name of the coordinate tex-file used.
- Throws:
LogicError
if the print data is not for this DG.
-
std::string printNonHyper() const¶
Print the derivation graph in style of a digraph, where each edge represents a hyperedge. Each vertex in the depiction then represents a multiset of vertices in the hypergraph.
- Returns:
the name of the PDF-file that will be compiled in post-processing.
-
std::string dump() const¶
-
std::string dump(const std::string &filename) const¶
Exports the derivation graph to a file, including associated graphs and rules. Use
load()
orBuilder::load()
to import the derivation graph again.- Parameters:
filename – the name of the file to save the dump to. If non is given an auto-generated name in the
out/
folder is used. If an empty string is given, it is treated as if non is given.- Returns:
the name of the file with the exported data.
- Throws:
LogicError
if !isLocked().- Throws:
LogicError
if the target file can not be opened.
-
void listStats() const¶
Output various stats of the derivation graph.
- Throws:
LogicError
if the DG has not been calculated.
Create an empty unlocked derivation graph object.
The given
LabelSettings
defines which category the derivation graph object works in. All morphism calculations (monomorphism and isomorphism) are thus defined by theLabelType
, while theLabelRelation
is used for monomorphism enumeration.The graphs is the given
graphDatabase
are used as the initial graph database. Any subsequently added or constructed graph for this object will be checked for isomorphism against the graph database.The given
graphPolicy
refers to how the graphs ofgraphDatabase
are checked for isomorphism against each other initially. Only useIsomorphismPolicy::TrustMe
if you are absolutely sure that the graphs are unique up to isomorphism.- Throws:
LogicError
if graphPolicy == IsomorphismPolicy::Check and two graph objects ingraphDatabase
are different objects but represents isomorphic graphs.- Throws:
LogicError
if there is a nullptr in graphDatabase.
Load a derivation graph dump as a locked object. Use
Builder::load()
to load a dump into a derivation graph under construction.This is done roughly by calling
make()
with the given graphDatabase and graphPolicy. The label settings are retrieved from the dump file. Vertices with graphs and hyperedges with rules are then added from the dump. Any graph in the dump which is isomorphic to a given graph is replaced by the given graph. The same procedure is done for the rules. If a graph/rule is not found in the given lists, a new object is instantiated and used. In the end the derivation graph is locked.Note
If the dump to be loaded was made by version 0.10 or earlier, it does not contain the full rules but only the rule name. It is then crucial that the names of the given rules match with those used to create the dump in the first place.
The
verbosity
defaults to level 2. The levels have the following meaning:0: print nothing.
2: print a message whenever a loaded graph or rule is isomorphic to an existing graph or rule.
- Throws:
the same exceptions
make()
throws related to graphDatabase and graphPolicy.- Throws:
LogicError
if there is a nullptr in ruleDatabase. :throws:InputError
if the file can not be opened or its content is bad.
Compare two derivation graphs and lists the difference. This is not a general isomorphism check; two vertices are equal if they have the same graph attached. Edges are equal if the head and tail sets are equal and if the attached rule is the same.