# 3.1.7.4. dg/Strategies¶

This section describes two interfaces for the derivation graph strategies; the basic API and an embedded language which is built on the basic API. Usually the embedded strategy language is easiest and sufficient for constructing strategies.

The semantics of the individual strategies are described in Derivation Graph Strategies. Note that a DGStrat is a representation of a strategy and must be given to a derivation graph to be evaluated.

## 3.1.7.4.1. The Embedded Strategy Language¶

The strategy language is really a collection of proxy classes with a lot of operator overloading, thus the normal syntax and semantics of Python applies.

The following is the grammar for the strategies.

strat ::=  strats
strat ">>" strat
rule
"addSubset(" graphs ")"
"addUniverse(" graphs ")"
"execute(" executeFunc ")"
"filterSubset(" filterPred ")"
"filterUniverse(" filterPred ")"
"leftPredicate[" derivationPred "](" strat ")"
"rightPredicate[" derivationPred "](" strat ")"
"repeat" [ "[" int "]" ] "(" strat ")"
"revive(" strat ")"


A strats must be an iterable of strat. A graphs can either be a single Graph, an iterable of graphs, or a function taking no arguments and returning a list of graphs.

## 3.1.7.4.2. The Basic API¶

### 3.1.7.4.2.1. Class DGStratGraphState¶

class mod.DGStratGraphState

This class represents a graph state with a subset $$S$$ and a universe $$U$$ fulfilling $$S\subseteq U$$.

subset

The subset $$\mathcal{S}$$.

Type: list of
universe

The universe $$\mathcal{U}$$.

Type: list of
hyperEdges

The references to all derivations in the underlying derivation graph. I.e., some derivations might involve graphs not in the universe.

Type: list of

### 3.1.7.4.2.2. Class DGStrat¶

class mod.DGStrat
static makeAddStatic(onlyUniverse, graphs)
Parameters: onlyUniverse (bool) – if the strategy is Add Universe or Add Subset. graphs (list of Graph) – the graphs to be added by the strategy. an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy. DGStrat
static makeAddDynamic(onlyUniverse, graphsFunc)
Parameters: onlyUniverse (bool) – if the strategy is Add Universe or Add Subset. graphsFunc (list of Graph ()) – a function returning the graphs to be added by the strategy. an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy. DGStrat
static makeExecute(func)
Parameters: func (void(DGStratGraphState)) – A function being executed when the strategy is evaluated. an Execute strategy. DGStrat
static makeFilter(alsoUniverse, p)
Parameters: alsoUniverse (bool) – if the strategy is Filter Universe or Filter Subset. p (bool(Graph, DGStratGraphState, bool)) – the filtering predicate being called for each graph in either the subset or the universe. The predicate is called with the graph and the graph state as arguments, and a bool stating whether or not the call is the first in the filtering process. a Filter Universe strategy if onlyUniverse is True, otherwise a Filter Subset strategy. DGStrat
static makeLeftPredicate(p, strat)
Parameters: p (bool(Derivation)) – the predicate to be called on each candidate derivation. Even though the predicate is called with a Derivation object, only the left side and the rule of the object is valid. strat (DGStrat) – the sub-strategy to be evaluated under the constraints of the left predicate. a Derivation Predicates strategy. DGStrat
static makeParallel(strats)
Parameters: strats (list of DGStrat) – the sub-strategies to evaluate. a Parallel strategy. DGStrat LogicError if strats is empty.
static makeRepeat(limit, strat)
Parameters: limit (unsigned int) – the maximum number of iterations. strat (DGStrat) – the strategy to be repeated. a Repeat strategy. DGStrat
static makeRevive(strat)
Parameters: strat (DGStrat) – the strategy to encapsulate. a Revive strategy. DGStrat
static makeRightPredicate(p, strat)
Parameters: p (bool(Derivation)) – the predicate to be called on each candidate derivation. strat (DGStrat) – the sub-strategy to be evaluated under the constraints of the right predicate. a Derivation Predicates strategy. DGStrat
static makeRule(r)
Parameters: r (Rule) – the rule to make into a strategy. a Rule strategy. DGStrat
static makeSequence(strats)
Parameters: strats (list of DGStrat) – the strategies to evaluate in sequence. a Sequence strategy. DGStrat