2.2.7. DGStrat.h

2.2.7.1. Class DGStrat

class DGStrat

Derivation graph strategies are used in DG::ruleComp().

2.2.7.1.1. Synopsis

struct DGStrat {
    DGStrat(const DGStrat&) = delete;
    DGStrat &operator=(const DGStrat&) = delete;
public:
    // rst-nested-begin:
    struct GraphState {
        GraphState(std::function<void(std::vector<std::shared_ptr<Graph> >&) > fSubset,
                std::function<void(std::vector<std::shared_ptr<Graph> >&) > fUniverse,
                std::function<void(std::vector<DerivationRef>&) > fDerivationRefs);
        const std::vector<std::shared_ptr<Graph> > &getSubset() const;
        const std::vector<std::shared_ptr<Graph> > &getUniverse() const;
        const std::vector<DerivationRef> &getDerivationRefs() const;
    private:
        mutable bool subsetInit, universeInit, derivationRefsInit;
        mutable std::vector<std::shared_ptr<Graph> > subset, universe;
        mutable std::vector<DerivationRef> derivationRefs;
        std::function<void(std::vector<std::shared_ptr<Graph> >&) > fSubset, fUniverse;
        std::function<void(std::vector<DerivationRef>&) > fDerivationRefs;
    };
private:
    DGStrat(std::unique_ptr<lib::DG::Strategies::Strategy> strategy);
public:
    ~DGStrat();
    std::unique_ptr<DGStrat> clone() const;
    friend std::ostream &operator<<(std::ostream &s, const DGStrat &strat);
    lib::DG::Strategies::Strategy &getStrategy();
private:
    struct Pimpl;
    std::unique_ptr<Pimpl> p;
public:
    static std::shared_ptr<DGStrat> makeAdd(bool onlyUniverse, const std::vector<std::shared_ptr<Graph> > &graphs);
    static std::shared_ptr<DGStrat> makeAdd(bool onlyUniverse, const std::shared_ptr<Function<std::vector<std::shared_ptr<Graph> >() > > generator);
    static std::shared_ptr<DGStrat> makeExecute(std::shared_ptr<Function<void(const DGStrat::GraphState&)> > func);
    static std::shared_ptr<DGStrat> makeFilter(bool alsoUniverse,
            std::shared_ptr<Function<bool(std::shared_ptr<Graph>, const DGStrat::GraphState&, bool)> > filterFunc);
    static std::shared_ptr<DGStrat> makeLeftPredicate(std::shared_ptr<Function<bool(const Derivation&) > > predicate,
            std::shared_ptr<DGStrat> strat);
    static std::shared_ptr<DGStrat> makeParallel(const std::vector<std::shared_ptr<DGStrat> > &strategies);
    static std::shared_ptr<DGStrat> makeRepeat(std::size_t limit, std::shared_ptr<DGStrat> strategy);
    static std::shared_ptr<DGStrat> makeRevive(std::shared_ptr<DGStrat> strategy);
    static std::shared_ptr<DGStrat> makeRightPredicate(std::shared_ptr<Function<bool(const Derivation&) > > predicate,
            std::shared_ptr<DGStrat> strat);
    static std::shared_ptr<DGStrat> makeRule(std::shared_ptr<Rule> rule);
    static std::shared_ptr<DGStrat> makeSequence(const std::vector<std::shared_ptr<DGStrat> > &strategies);
    // TODO: remove
    static std::shared_ptr<DGStrat> makeSort(bool doUniverse,
            std::shared_ptr<Function<bool(std::shared_ptr<Graph>, std::shared_ptr<Graph>, const DGStrat::GraphState&)> > less);
    // TODO: remove
    static std::shared_ptr<DGStrat> makeTake(bool doUniverse, unsigned int limit);
};

2.2.7.1.2. Details

static std::shared_ptr<DGStrat> makeAdd(bool onlyUniverse, const std::vector<std::shared_ptr<Graph>> &graphs)
Returns:an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy.
static std::shared_ptr<DGStrat> makeAdd(bool onlyUniverse, const std::shared_ptr<Function<std::vector<std::shared_ptr<Graph>>()>> generator)
Returns:an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy.
static std::shared_ptr<DGStrat> makeExecute(std::shared_ptr<Function<void(const DGStrat::GraphState&)>> func)
Returns:an Execute strategy.
static std::shared_ptr<DGStrat> makeFilter(bool alsoUniverse, std::shared_ptr<Function<bool(std::shared_ptr<Graph>, const DGStrat::GraphState&, bool)>> filterFunc)

The filtering predicate will be 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.

Returns:a Filter Universe strategy if onlyUniverse is True, otherwise a Filter Subset strategy.
static std::shared_ptr<DGStrat> makeLeftPredicate(std::shared_ptr<Function<bool(const Derivation&)>> predicate, std::shared_ptr<DGStrat> strat, )

Even though the predicate is called with a Derivation object, only the left side and the rule of the object is valid.

Returns:a Derivation Predicates strategy.
static std::shared_ptr<DGStrat> makeParallel(const std::vector<std::shared_ptr<DGStrat>> &strategies)
Returns:a Parallel strategy.
Throws:LogicError if strategies is empty.
static std::shared_ptr<DGStrat> makeRepeat(unsigned int limit, std::shared_ptr<DGStrat> strategy)
Returns:a Repeat strategy.
static std::shared_ptr<DGStrat> makeRevive(std::shared_ptr<DGStrat> strategy)
Returns:a Revive strategy.
static std::shared_ptr<DGStrat> makeRightPredicate(std::shared_ptr<Function<bool(const Derivation&)>> predicate, std::shared_ptr<DGStrat> strat, )
Returns:a Derivation Predicates strategy.
static std::shared_ptr<DGStrat> makeRule(std::shared_ptr<Rule> rule)
Returns:a Rule strategy.
static std::shared_ptr<DGStrat> makeSequence(const std::vector<std::shared_ptr<DGStrat>> &strategies)
Retunrs:a Sequence strategy.

2.2.7.2. Class DGStrat::GraphState

class DGStrat::GraphState

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

const std::vector<std::shared_ptr<Graph>> &getSubset() const
Returns:the subset \(\mathcal{S}\).
const std::vector<std::shared_ptr<Graph>> &getUniverse() const
Returns:the universe \(\mathcal{U}\)
const std::vector<DerivationRef> &getDerivationRefs() const
Returns:the references to all derivations in the underlying derivation graph. I.e., some derivations might involve graphs not in the universe.