3.2.11.1. dg/Builder.hpp

3.2.11.1.1. Class dg::Builder

class dg::Builder

An RAII-style object obtained from DG::build(). On destruction of an active builder object the owning DG will be locked for further modifications. Builder objects are move-only types, and a moved from object becomes an inactive builder, not associated with any DG.

3.2.11.1.1.1. Synopsis

std::shared_ptr<DG> getDG() const
bool isActive() const
DG::HyperEdge addDerivation(const Derivations &d)
DG::HyperEdge addDerivation(const Derivations &d, IsomorphismPolicy graphPolicy)
DG::HyperEdge addHyperEdge(const DG::HyperEdge &e)
DG::HyperEdge addHyperEdge(const DG::HyperEdge &e, IsomorphismPolicy graphPolicy)
ExecuteResult execute(std::shared_ptr<Strategy> strategy)
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity)
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity, bool ignoreRuleLabelTypes)
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r)
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r, bool onlyProper, int verbosity)
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r, bool onlyProper, int verbosity, IsomorphismPolicy graphPolicy)
void addAbstract(const std::string &description)
void load(const std::vector<std::shared_ptr<rule::Rule>> &ruleDatabase, const std::string &file, int verbosity)

3.2.11.1.1.2. Details

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

the derivation graph this builder can modify.

bool isActive() const
Returns:

whether this object is associated with a DG.

DG::HyperEdge addDerivation(const Derivations &d)
DG::HyperEdge addDerivation(const Derivations &d, IsomorphismPolicy graphPolicy)

Adds a hyperedge corresponding to the given derivation to the associated DG. If it already exists, only add the given rules to the edge. The given graphPolicy refers to adding the graphs in d, and it defaults to IsomorphismPolicy::Check.

Returns:

the hyperedge corresponding to the given derivation.

Throws:

LogicError if !isActive().

Throws:

LogicError if d.left.empty().

Throws:

LogicError if d.right.empty().

Throws:

LogicError if a nullptr is in d.left, d.right, or d.rules.

Throws:

LogicError if graphPolicy == IsomorphismPolicy::Check and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph.

DG::HyperEdge addHyperEdge(const DG::HyperEdge &e)
DG::HyperEdge addHyperEdge(const DG::HyperEdge &e, IsomorphismPolicy graphPolicy)

Adds a hyperedge to the associated DG from a copy of the given hyperedge (from a different DG). If it already exists, only add the rules to the edge. The given graphPolicy refers to adding the graphs associated with e, and it defaults to IsomorphismPolicy::Check.

Returns:

the hyperedge corresponding to the given derivation.

Throws:

LogicError if !isActive().

Throws:

LogicError if !e.

Throws:

LogicError if graphPolicy == IsomorphismPolicy::Check and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph.

ExecuteResult execute(std::shared_ptr<Strategy> strategy)
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity)
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity, bool ignoreRuleLabelTypes)

Execute the given strategy (Derivation Graph Strategies) and as a side effect add vertices and hyperedges to the underlying derivation graph.

The verbosity defaults to level 2. The levels have the following meaning:

  • 0 (or less): no information is printed.

  • 2: Repetition strategies print information for each round.

  • 4: All strategies print minimal information.

  • 6: Derivation predicate strategies and filtering strategies also print their predicates.

  • 8: Rule strategies print minimal information about graph binding.

  • 10: Rule strategies print more information about graph binding, including failure due to derivation predicates.

  • 50: Print information about morphism generation for rule composition.

  • 60: Print rule composition information.

Throws:

LogicError if a static “add” strategy has IsomorphismPolicy::Check as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database. This is checked before execution, so there is strong exception guarantee.

Throws:

LogicError if a dynamic “add” strategy has IsomorphismPolicy::Check as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database.

Warning

This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph.

Throws:

LogicError if a dynamic “add” strategy is executed where a returned graph is a nullptr.

Warning

This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph.

Throws:

LogicError: if ignoreRuleLabelTypes is false, which is the default, and a rule in the given strategy has an associated LabelType which is different from the one in the derivation graph.

std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r)
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r, bool onlyProper, int verbosity)
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph>> &graphs, std::shared_ptr<rule::Rule> r, bool onlyProper, int verbosity, IsomorphismPolicy graphPolicy)

Compute direct derivations using graphs for the left-hand side and r as the rule.

When onlyProper is true, then all of graphs must be used in each direct derivation. The default is true.

The given graphPolicy refers to adding the graphs in graphs, and it defaults to IsomorphismPolicy::Check.

The verbosity defaults to level 0. The levels have the following meaning:

  • 0 (or less): no information is printed.

  • 2: Print minimal information about graph binding.

  • 10: Print information about morphism generation for rule composition.

  • 20: Print rule composition information.

Returns:

a list of hyper edges representing the found direct derivations. The list may contain duplicates if there are multiple ways of constructing the same direct derivation when ignoring the specific match morphism.

Throws:

LogicError if there is a nullptr in graphs.

Throws:

LogicError if r == nullptr.

Throws:

LogicError if graphPolicy == IsomorphismPolicy::Check and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph.

void addAbstract(const std::string &description)

Add vertices and hyperedges based on the given abstract description. The description must adhere to the grammar described at Abstract Derivation Graphs.

For each vertex named in the description a graph object with a single vertex will be created. The label of that vertex and the name of the graph is set to the given identifier.

Throws:

InputError if the description could not be parsed.

void load(const std::vector<std::shared_ptr<rule::Rule>> &ruleDatabase, const std::string &file, int verbosity)

Load and add a derivation graph dump. Use DG::load() to load a dump as a locked derivation graph.

The label settings of this DG and the ones retrieved from the dump file must match. Vertices with graphs and hyperedges with rules are then added from the dump. Any graph in the dump which is isomorphic to a graph in the internal graph database of the DG is replaced by the given graph. The same procedure is done for the rules, but compared against the given rules. If a graph/rule is not found in the given lists, a new object is instantiated and used.

See DG::load() for an explanation of the verbosity levels.

Throws:

LogicError if there is a nullptr in ruleDatabase.

Throws:

LogicError if the label settings of the dump does not match those of this DG. :throws: InputError if the file can not be opened or its content is bad.

3.2.11.1.2. Class dg::ExecuteResult

class dg::ExecuteResult

The result from calling Builder::execute().

3.2.11.1.2.1. Synopsis

const std::vector<std::shared_ptr<graph::Graph>> &getSubset() const
const std::vector<std::shared_ptr<graph::Graph>> &getUniverse() const
void list(bool withUniverse) const

3.2.11.1.2.2. Details

const std::vector<std::shared_ptr<graph::Graph>> &getSubset() const
const std::vector<std::shared_ptr<graph::Graph>> &getUniverse() const
Returns:

respectively the subset and the universe computed by the strategy execution (see also Derivation Graph Strategies).

void list(bool withUniverse) const

Output information from the execution of the strategy. The universe lists can be rather long so with withUniverse == false they are omitted.