8template<
class G>
requires (G::edge_type::isDirected()==
true)
12 using N =
typename G::node_type;
13 using E =
typename G::edge_type;
22 bool hasCycleAfterAddingEdge(
const N & from,
const N & to)
noexcept{
39 this->g = std::move(other.g);
45 bool addEdge(
const N & from,
const N & to)
noexcept{
46 if(hasCycleAfterAddingEdge(from,to))
48 this->g.addEdge(from,to);
52 bool addEdge(N && from, N && to)
noexcept{
53 if(hasCycleAfterAddingEdge(from,to))
55 this->g.addEdge(std::move(from),std::move(to));
60 return addEdge(edge.getFrom(),edge.getTo());
64 std::ranges::for_each(edges,[
this](
auto && pair){
65 auto && [from,to] = pair;
66 this->addEdge(from,to);
71 addEdges(std::views::transform(edges,[](
auto && edge){
return std::make_pair(edge.getFrom(),edge.getTo());}));
83 return this->g.getNodes() | std::views::filter([
this](
const auto & node){
return inDegree(node)==0;});
Definition DirectedAcyclicGraph.hpp:9
bool addEdge(N &&from, N &&to) noexcept
Definition DirectedAcyclicGraph.hpp:52
void addEdges(util::forward_range_of< E > auto &&edges) noexcept
Definition DirectedAcyclicGraph.hpp:70
DirectedAcyclicGraph & operator=(DirectedAcyclicGraph &&other)
Definition DirectedAcyclicGraph.hpp:38
DirectedAcyclicGraph(G &&underlyingGraph)
Definition DirectedAcyclicGraph.hpp:27
void addEdges(util::forward_range_of< std::pair< N, N > > auto &&edges) noexcept
Definition DirectedAcyclicGraph.hpp:63
size_t outDegree(const N &node) const noexcept
Definition DirectedAcyclicGraph.hpp:78
DirectedAcyclicGraph(const DirectedAcyclicGraph &other)
Definition DirectedAcyclicGraph.hpp:31
size_t inDegree(const N &node) const noexcept
Definition DirectedAcyclicGraph.hpp:74
DirectedAcyclicGraph & operator=(const DirectedAcyclicGraph &other)
Definition DirectedAcyclicGraph.hpp:33
util::forward_range_of< N > auto rootNodes() const noexcept
Definition DirectedAcyclicGraph.hpp:82
bool addEdge(const N &from, const N &to) noexcept
Definition DirectedAcyclicGraph.hpp:45
DirectedAcyclicGraph()
Definition DirectedAcyclicGraph.hpp:43
bool addEdge(const E &edge) noexcept
Definition DirectedAcyclicGraph.hpp:59
DirectedAcyclicGraph(DirectedAcyclicGraph &&other)
Definition DirectedAcyclicGraph.hpp:29
Abstract Graph Decorator using CRTP.
Definition GraphDecorator.hpp:14
G g
Definition GraphDecorator.hpp:16
Definition CollectionConcepts.hpp:27
auto findPath(const G &graph, const typename G::node_type &start, const typename G::node_type &goal)
Find breadth-first search between between start and goal node.
Definition BFSAlgorithm.hpp:156
Definition AdjacencyContainer.hpp:4
constexpr size_t size(std::ranges::range auto &&range) noexcept
Definition CollectionConcepts.hpp:50