A simple header-only library to create and manipulate directed graphs. Just add the DirectedGraph folder to your project.
The digraph
class represents a directed graph with nodes of type N
and connections between these nodes.
add(N n)
: Adds a noden
to the graph.add(const N& n1, const N& n2, const TWeights& w)
: Adds two nodes with a set of connections of weightsw
.add(const N& n1, const N& n2, int d = 0)
: Adds the nodesn1
andn2
and the connection(n1 -d-> n2)
to the graph.add(const digraph& g)
: Adds an entire graphg
.nodes() const
: Returns the set of nodes in the graph.connections() const
: Returns the set of connections in the graph.destinations(const N& n) const
: Returns the destinations of noden
in the graph.weights(const N& n1, const N& n2) const
: Returns the weights of the connections between two nodes.areConnected(const N& n1, const N& n2) const
: Returnstrue
if there is a connection between nodesn1
andn2
.areConnected(const N& n1, const N& n2, int& d) const
: Returnstrue
if there is a connection between nodesn1
andn2
and the smallest weight is returned ind
.
The Tarjan
class partitions a graph into strongly connected components.
partition() const
: Returns the partition of the graph into strongly connected components.cycles() const
: Returns the number of cycles in the graph.
cycles(const digraph<N>& g)
: Counts the number of cycles in a graph.graph2dag(const digraph<N>& g)
: Transforms a graph into a DAG of supernodes.parallelize(const digraph<N>& g)
: Transforms a DAG into a sequential vector of parallel vectors of nodes.serialize(const digraph<N>& G)
: Transforms a DAG into a sequence of nodes using a topological sort.mapnodes(const digraph<N>& g, std::function<M(const N&)> foo)
: Transforms a graph by applyingfoo
to each node.reverse(const digraph<N>& g)
: Reverses all the connections of a graph.splitgraph(const digraph<N>& G, std::function<bool(const N&)> left, digraph<N>& L, digraph<N>& R)
: Splits a graph into two subgraphs according to a predicate.subgraph(const digraph<N>& G, const std::set<N>& S)
: Extracts a subgraph ofG
according to a set of nodesS
.cut(const digraph<N>& G, int dm)
: Cuts all the connections of a graph with weight >=dm
.chain(const digraph<N>& g, bool strict)
: Keeps only the chain connections of a graph.roots(const digraph<N>& G)
: Returns the roots of a graph.leaves(const digraph<N>& G)
: Returns the leaves of a graph.criticalpath(const digraph<N>& G, const N& n)
: Computes the critical path of a graph.interleave(std::list<N>& list1, std::list<N>& list2)
: Interleaves two lists.recschedulenode(const digraph<N>& G, const N& n)
: Recursive scheduling of a node of a DAG.recschedule(const digraph<N>& G)
: Recursive scheduling of the roots of a DAG.topology(const digraph<N>& g)
: High-level description of a graph.
The schedule
class represents an order of computation of the nodes of a DAG.
size() const
: Returns the number of elements in the schedule.elements() const
: Returns the vector of elements.order(const N& n) const
: Returns the order of an element in the schedule.append(const N& n)
: Adds a new element to the schedule.append(const schedule<N>& S)
: Adds all the elements of a schedule.reverse() const
: Returns a schedule in reverse order.
dfschedule(const digraph<N>& G)
: Deep-first scheduling of a DAG.bfschedule(const digraph<N>& G)
: Breadth-first scheduling of a DAG.spschedule(const digraph<N>& G)
: Special schedule for a DAG.schedulingcost(const digraph<N>& G, const schedule<N>& S)
: Computes the cost of a schedule.dfcyclesschedule(const digraph<N>& G)
: Deep-first scheduling of a directed graph with cycles.bfcyclesschedule(const digraph<N>& G)
: Breadth-first scheduling of a directed graph with cycles.rbschedule(const digraph<N>& G)
: Reverse breadth-first schedule for a DAG.