2.2.8.5. dg/Strategies.h

2.2.8.5.1. Class dg::Strategy

class dg::Strategy

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

2.2.8.5.1.1. Synopsis

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

2.2.8.5.1.2. Details

static std::shared_ptr<Strategy> makeAdd(bool onlyUniverse, const std::vector<std::shared_ptr<graph::Graph>> &graphs)
Returns:an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy.
static std::shared_ptr<Strategy> makeAdd(bool onlyUniverse, const std::shared_ptr<Function<std::vector<std::shared_ptr<graph::Graph>>()>> generator)
Returns:an Add Universe strategy if onlyUniverse is True, otherwise an Add Subset strategy.
static std::shared_ptr<Strategy> makeExecute(std::shared_ptr<Function<void(const Strategy::GraphState&)>> func)
Returns:an Execute strategy.
static std::shared_ptr<Strategy> makeFilter(bool alsoUniverse, std::shared_ptr<Function<bool(std::shared_ptr<graph::Graph>, const Strategy::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<Strategy> makeLeftPredicate(std::shared_ptr<Function<bool(const Derivation&)>> predicate, std::shared_ptr<Strategy> 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<Strategy> makeParallel(const std::vector<std::shared_ptr<Strategy>> &strategies)
Returns:a Parallel strategy.
Throws:LogicError if strategies is empty.
static std::shared_ptr<Strategy> makeRepeat(unsigned int limit, std::shared_ptr<Strategy> strategy)
Returns:a Repeat strategy.
static std::shared_ptr<Strategy> makeRevive(std::shared_ptr<Strategy> strategy)
Returns:a Revive strategy.
static std::shared_ptr<Strategy> makeRightPredicate(std::shared_ptr<Function<bool(const Derivation&)>> predicate, std::shared_ptr<Strategy> strat, )
Returns:a Derivation Predicates strategy.
static std::shared_ptr<Strategy> makeRule(std::shared_ptr<rule::Rule> r)
Returns:a Rule strategy.
static std::shared_ptr<Strategy> makeSequence(const std::vector<std::shared_ptr<Strategy>> &strategies)
Retunrs:a Sequence strategy.

2.2.8.5.2. Class dg::Strategy::GraphState

class dg::Strategy::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::Graph>> &getSubset() const
Returns:the subset \(\mathcal{S}\).
const std::vector<std::shared_ptr<graph::Graph>> &getUniverse() const
Returns:the universe \(\mathcal{U}\)
const std::vector<DG::HyperEdge> &getHyperEdges() const
Returns:all edges in the underlying derivation graph. I.e., some derivations might involve graphs not in the universe.