2.2.8.1. dg/DG.h

2.2.8.1.1. Class dg::DG

class dg::DG

The main derivation graph class. A derivation graph is a directed hypergraph \(\mathcal{H} = (V, E)\). Each vertex is annotated with a graph, and each hyperedge is annotated with a transformation rule. A derivation graph can either be calculated from a strategy or loaded from external data.

2.2.8.1.1.1. Synopsis

struct 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;
    friend std::ostream &operator<<(std::ostream &s, const DG &dg);
    const lib::DG::NonHyper &getNonHyper() const;
    const lib::DG::Hyper &getHyper() 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:
    void calc();
    const std::set<std::shared_ptr<graph::Graph>, graph::GraphLess> &getGraphDatabase() const;
    const std::vector<std::shared_ptr<graph::Graph> > &getProducts() const;
    std::string print(const PrintData &data, const Printer &printer) const;
    std::string dump() const;
    void list() const;
    void listStats() const;
    // :throws: :class:`LogicError` if the DG has not been calculated or if the DG is not created from strategies.
    std::vector<std::shared_ptr<graph::Graph> > getStratOutputSubset() const;
private:
    struct Pimpl;
    std::unique_ptr<Pimpl> p;
public:
    static std::shared_ptr<DG> derivations(const std::vector<Derivation> &derivations);
    static std::shared_ptr<DG> abstract(const std::string &specification);
    static std::shared_ptr<DG> ruleComp(const std::vector<std::shared_ptr<graph::Graph> > &graphs,
            std::shared_ptr<Strategy> strategy, LabelSettings labelSettings, bool ignoreRuleLabelTypes);
    static std::shared_ptr<DG> dumpImport(const std::vector<std::shared_ptr<graph::Graph> > &graphs, const std::vector<std::shared_ptr<rule::Rule> > &rules, const std::string &file);
    static void diff(std::shared_ptr<DG> dg1, std::shared_ptr<DG> dg2);
};

2.2.8.1.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.
std::size_t numVertices() const
Returns:the number of vertices in the derivation graph.
Throws:LogicError if the DG has not been calculated.
VertexRange vertices() const
Returns:a range of all vertices in the derivation graph.
Throws:LogicError if the DG has not been calculated.
std::size_t numEdges() const
Returns:the number of edges in the derivation graph.
Throws:LogicError if the DG has not been calculated.
EdgeRange edges() const
Returns:a range of all edges in the derivation graph.
Throws:LogicError if the DG has not been calculated.
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.
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.
void calc()

Compute the derivation graph.

Throws:LogicError if created from ruleComp() and a dynamic add strategy adds a graph isomorphic to an already known graph, but represented by a different object.
const std::set<std::shared_ptr<graph::Graph>, graph::GraphLess> &getGraphDatabase() const
Returns:the set 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::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.
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 importetet.

Returns:the name of the file with the exported data.
Throws:LogicError if the DG has not been calculated.
void list() const

Output information on the calculation of the derivation graph. For strategy-based calculations, this outputs the expression tree.

void listStats() const

Output various stats of the derivation graph.

Throws:LogicError if the DG has not been calculated.
static std::shared_ptr<DG> derivations(const std::vector<Derivation> &derivations)

Create a derivation graph from a list of Derivation.

static std::shared_ptr<DG> abstract(const std::string &specification)

Create a derivation graph from an abstract description according to the following grammar.

description ::=  derivation { derivation }
derivation  ::=  side ("->" | "<=>") side
side        ::=  term { "+" term }
term        ::=  [ unsignedInt ] identifier
Throws:InputError on bad input.
static std::shared_ptr<DG> ruleComp(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<Strategy> strategy, LabelSettings labelSettings, bool ignoreRuleLabelTypes)

Initialize a derivation graph with a Strategy and an initial graph database. Any derived graph isomorphic to a given graph is replaced by the given graph. The given LabelSettings is used for both monomorphism enumeration, and its LabelType is used in isomorphism checks.

Throws:LogicError if two graphs in graphs are different by isomorphic objects, or similarly if a static add strategy adds an isomorphic graph.
Throws:LogicError if ignoreRuleLabelTypes is false and a rule in the given strategy has an intended label type different from the given type in labelSettings.
static std::shared_ptr<DG> dumpImport(const std::vector<std::shared_ptr<graph::Graph>> &graphs, const std::vector<std::shared_ptr<rule::Rule>> &rules, const std::string &file)

Load a derivation graph 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, however only using the name of the rule for comparison.

Throws:InputError on bad input.
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.