2.2.10.2. dg/DG.hpp

2.2.10.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 the build() function. When the obtained builder is destructed the derivation graph becomes locked and can no longer be modified.

2.2.10.2.1.1. Synopsis

struct MOD_DECL DG {
    DG(const DG &) = delete;
    DG &operator=(const DG &) = delete;
public:
    class Vertex;
    class HyperEdge;
    class VertexIterator;
    class VertexRange;
    class EdgeIterator;
    class EdgeRange;
    class InEdgeIterator;
    class InEdgeRange;
    class OutEdgeIterator;
    class OutEdgeRange;
    class SourceIterator;
    class SourceRange;
    class TargetIterator;
    class TargetRange;
    class RuleIterator;
    class RuleRange;
private:
    DG(std::unique_ptr<lib::DG::NonHyper> dg);
public:
    ~DG();
    std::size_t getId() const;
    MOD_DECL 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;
public: // object state
    bool hasActiveBuilder() const;
    bool isLocked() const;
public: // hypergraph interface
    std::size_t numVertices() const;
    VertexRange vertices() const;
    std::size_t numEdges() const;
    EdgeRange edges() const;
public: // searching for vertices and hyperedges
    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;
public:
    Builder build();
    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 PrintData &data, const Printer &printer) const;
    std::string dump() const;
    void listStats() const;
private:
    struct Pimpl;
    std::unique_ptr<Pimpl> p;
public:
    static std::shared_ptr<DG> make(LabelSettings labelSettings,
                                    const std::vector<std::shared_ptr<graph::Graph> > &graphDatabase,
                                    IsomorphismPolicy graphPolicy);
    //    rst:            but only the rule name. It is then crucial that the names of the given rules match with those used to
    //    rst:            create the dump in the first place.
    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);
    static std::shared_ptr<DG> abstracted(std::shared_ptr<DG> dg);
};

2.2.10.2.1.2. Details

std::size_t getId() const
Returns

the instance identifier for the object.

friend std::ostream &operator<<(std::ostream &s, const DG &dg)
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
Returns

whether build() has been called and the returned Builder is still active.

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 not hasActiveBuilder() or isLocked().

VertexRange vertices() const
Returns

a range of all vertices in the derivation graph.

Throws

LogicError if not hasActiveBuilder() or isLocked().

std::size_t numEdges() const
Returns

the number of edges in the derivation graph.

Throws

LogicError if not hasActiveBuilder() or isLocked().

EdgeRange edges() const
Returns

a range of all edges in the derivation graph.

Throws

LogicError if not hasActiveBuilder() or isLocked().

Vertex findVertex(std::shared_ptr<graph::Graph> g) const
Returns

a vertex descriptor for which the given graph is associated, or a null descriptor if no such vertex exists.

Throws

LogicError if not hasActiveBuilder() or isLocked().

Throws

LogicError if g is a nullptr.

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
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 not hasActiveBuilder() or isLocked().

Builder build()
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 PrintData &data, const Printer &printer) 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 dump() const

Exports the derivation graph to a text file, which can be imported.

Returns

the name of the file with the exported data.

Throws

LogicError if the DG has not been calculated.

void listStats() const

Output various stats of the derivation graph.

Throws

LogicError if the DG has not been calculated.

static std::shared_ptr<DG> make(LabelSettings labelSettings, const std::vector<std::shared_ptr<graph::Graph>> &graphDatabase, IsomorphismPolicy graphPolicy)

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 the LabelType, while the LabelRelation is used for 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 of graphDatabase are checked for isomorphism against each other initially. Only use IsomorphismPolicy::TrustMe if you are absolutely sure that the graphs are unique up to isomorphism.

Throws

LogicError if graphPolicy == IsomorphismPolicy::Check and two graph objects in graphDatabase are different objects but represents isomorphic graphs.

Throws

LogicError if there is a nullptr in graphDatabase.

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)

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

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.

static void diff(std::shared_ptr<DG> dg1, std::shared_ptr<DG> dg2)

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.