# 3.1.7.1. dg/DG¶

## 3.1.7.1.1. Class DG¶

class mod.DG

The main derivation graph class. A derivation graph is a directed hypergraph $$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.

id

The unique instance id among all DG objects.

Type: int
numVertices

(Read-only) The number of vertices in the derivation graph.

Type: int LogicError if the DG has not been calculated.
vertices

(Read-only) An iterable of all vertices in the derivation graph.

Type: DGVertexRange LogicError if the DG has not been calculated.
numEdges

(Read-only) The number of hyperedges in the derivation graph.

Type: int LogicError if the DG has not been calculated.
edges

(Read-only) An iterable of all hyperedges in the derivation graph.

Type: DGEdgeRange LogicError if the DG has not been calculated.
findVertex(g)
Parameters: g (Graph) – the graph to find a vertex which has it associated. a vertex descriptor for which the given graph is associated, or a null descriptor if no such vertex exists. DGVertex
findEdge(sources, targets)
findEdge(sourceGraphs, targetGraphs)
Parameters: sources (list of DGVertex) – the list of source vertices the resulting hyperedge must have. targets (list of DGVertex) – the list of targets vertices the resulting hyperedge must have. sourceGraphs (list of Graph) – the list of graphs that must be associated with the source vertices the resulting hyperedge must have. targetGraphs (list of Graph) – the list of graphs that must be associated with the targets vertices the resulting hyperedge must have. 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. LogicError if a vertex descriptor is null, or does not belong to the derivation graph.
calc()

Create the actual derivation graph.

Raises: LogicError if created from dgRuleComp and a dynamic add strategy adds a graph isomorphic to an already known graph, but represented by a different object.
graphDatabase

All graphs known to the derivation graph.

Type: list of
products

The subset of the vertex graphs which were discovered by the calculation.

Type: list of
print(printer=DGPrinter(), data=None)

Print the derivation graph in style of a hypergraph. The appearance and structure of the visualisation can optionally be configured by giving a DG printer and/or data object.

Parameters: printer (DGPrinter) – the printer to use governing the appearance. data (DGPrintData) – the extra data to use encoding the structure of the graph. the name of the PDF-file that will be compiled in post-processing. string
dump()

Export the derivation graph to an external file. The vertex graphs are exported as well.

Returns: the filename of the exported derivation graph. string LogicError if the DG has not been calculated.
list()

List information about the calculation.

listStats()

Lists various statistics for the derivation graph.

Raises: LogicError if the DG has not been calculated.
mod.dgDerivations(ders)
Parameters: ders (list of Derivation) – the list of derivations to include in the derivation graph. a derivation graph from a list of Derivation. DG
mod.dgAbstract(s)
Parameters: s (string) – the abstract specification of a derivation graph. Construct a derivation graph from an abstract set of derivations. See dg::DG::abstract() for the specification format. DG
mod.dgRuleComp(graphs, strat, labelSettings=LabelSettings(LabelType.String, LabelRelation.Isomorphism), ignoreRuleLabelTypes=False)

Initialize a derivation graph defined by a strategy.

Parameters: graphs (list of Graph) – an initial graph database. Any derived graph isomorphic to one of these graphs will be replaced by the given graph. strat (DGStrat) – the strategy which will be used for calculating the actual derivation graph. labelSettings (LabelSettings) – the settings to use for monomorphism enumeration and isomorphism checked. ignoreRuleLabelTypes (bool) – whether the rules in the given strategy should be checked to be in line with the given label type. the derivation graph object. The calculation method must be called to create the actual derivation graph. DG LogicError if two graphs in graphs are different by isomorphic objects, or similarly if a static add strategy adds an isomorphic graph. LogicError if ignoreRuleLabelTypes is False and a rule in the given strategy has an intended label type different from the given type in labelSettings.
mod.dgDump(graphs, rules, file)

Load a derivation graph dump.

Parameters: graphs (list of Graph) – Any graph in the dump which is isomorphic one of these graphs is replaced by the given graph. rules (list of Rule) – As for the graphs the same procedure is done for the rules, however only using the name of the rule for comparison. the loaded derivation graph. DG
mod.diffDGs(dg1, 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.

Parameters: dg1 (DG) – the first derivation graph. dg2 (DG) – the second derivation graph.