simple pass to pick up paths redundant with those from cyclic's succs

This commit is contained in:
Alex Coyte
2016-10-06 15:54:48 +11:00
committed by Matthew Barr
parent 8cadba0bdd
commit 47f53f63a7
13 changed files with 234 additions and 68 deletions

View File

@@ -70,6 +70,13 @@ void succ(const NGHolder &g, NFAVertex v, U *s) {
s->insert(ai, ae);
}
template<class ContTemp = flat_set<NFAVertex>>
ContTemp succs(NFAVertex u, const NGHolder &g) {
ContTemp rv;
succ(g, u, &rv);
return rv;
}
/** adds predecessors of v to s */
template<class U>
static really_inline
@@ -79,6 +86,13 @@ void pred(const NGHolder &g, NFAVertex v, U *p) {
p->insert(it, ite);
}
template<class ContTemp = flat_set<NFAVertex>>
ContTemp preds(NFAVertex u, const NGHolder &g) {
ContTemp rv;
pred(g, u, &rv);
return rv;
}
/** returns a vertex with an out edge from v and is not v.
* v must have exactly one out-edge excluding self-loops.
* will return NGHolder::null_vertex() if the preconditions don't hold.
@@ -88,6 +102,30 @@ NFAVertex getSoleDestVertex(const NGHolder &g, NFAVertex v);
/** Like getSoleDestVertex but for in-edges */
NFAVertex getSoleSourceVertex(const NGHolder &g, NFAVertex v);
/** \brief edge filtered graph.
*
* This will give you a view over the graph that has none of the edges from
* the provided set included.
*
* If this is provided with the back edges of the graph, this will result in an
* acyclic subgraph view. This is useful for topological_sort and other
* algorithms that require a DAG.
*/
template<typename EdgeSet>
struct bad_edge_filter {
bad_edge_filter() {}
explicit bad_edge_filter(const EdgeSet *bad_e) : bad_edges(bad_e) {}
bool operator()(const typename EdgeSet::value_type &e) const {
return !contains(*bad_edges, e); /* keep edges not in the bad set */
}
const EdgeSet *bad_edges = nullptr;
};
template<typename EdgeSet>
bad_edge_filter<EdgeSet> make_bad_edge_filter(const EdgeSet *e) {
return bad_edge_filter<EdgeSet>(e);
}
/** Visitor that records back edges */
template <typename BackEdgeSet>
class BackEdges : public boost::default_dfs_visitor {
@@ -100,23 +138,6 @@ public:
BackEdgeSet &backEdges;
};
/** \brief Acyclic filtered graph.
*
* This will give you a view over the graph that is directed and acyclic:
* useful for topological_sort and other algorithms that require a DAG.
*/
template <typename BackEdgeSet>
struct AcyclicFilter {
AcyclicFilter() {}
explicit AcyclicFilter(const BackEdgeSet *edges) : backEdges(edges) {}
template <typename EdgeT>
bool operator()(const EdgeT &e) const {
// Only keep edges that aren't in the back edge set.
return (backEdges->find(e) == backEdges->end());
}
const BackEdgeSet *backEdges = nullptr;
};
/**
* Generic code to renumber all the vertices in a graph. Assumes that we're
* using a vertex_index property of type u32, and that we always have