3.1.4. DG

3.1.4.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
vertices

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

Type:DGVertexRange
numEdges

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

Type:int
edges

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

Type:DGEdgeRange
findVertex(g)
Parameters:g (Graph) – the graph to find a vertex which has it associated.
Returns:a vertex descriptor for which the given graph is associated, or a null descriptor if no such vertex exists.
Return type:DGVertex
findEdge(sources, targets)
findEdge(sourceGraphs, targetGraphs)
Parameters:
  • sources (list of Vertex) – the list of source vertices the resulting hyperedge must have.
  • targets (list of Vertex) – 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.
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.

Raises:

LogicError if a vertex descriptor is null, or does not belong to the derivation graph.

calc()

Create the actual derivation graph.

graphDatabase

All graphs known to the derivation graph.

Type:list of Graph
products

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

Type:list of Graph
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.
dump()

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

Returns:the filename of the exported derivation graph.
Return type:string
list()

List information about the calculation.

listStats()

Lists various statistics for the derivation graph.

mod.dgDerivations(ders)
Parameters:ders (list of Derivation) – the list of derivations to include in the derivation graph.
Returns:a derivation graph from a list of Derivation.
Return type:DG
mod.dgAbstract(s)
Parameters:s (string) – the abstract specification of a derivation graph.
Returns:Construct a derivation graph from an abstract set of derivations. See DG::abstract() for the specification format.
Return type:DG
mod.dgRuleComp(graphs, strat)

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.
Returns:

the derivation graph object. The calculation method must be called to create the actual derivation graph.

Return type:

DG

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.
Returns:

the loaded derivation graph.

Return type:

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.

3.1.4.2. Class DerivationRef

class mod.DerivationRef

A reference to a derivation in a specific derivation graph, or an invalid reference.

id

(Read-only) If the reference is valid, this is the id of the pointed to derivation.

Type:unsigned int
dg

(Read-only) If the reference is valid, this is the derivation graph the reference points into.

Type:DG
isValid()
Returns:whether or not the reference is valid.
Return type:bool
derivation

(Read-only) If the reference is valid, this is the pointed to derivation.

Type:Derivation
print(printer=GraphPrinter(), matchColour="ForestGreen")

Print the derivation pointed to by the derivation reference. All possible Double-Pushout diagrams for the derivation are printed.

Parameters:
  • printer (GraphPrinter) – the printer to use for the figures.
  • matchColour (string) – the TikZ colour to use for the rule and its image in the bottom span.