Sequoia
Loading...
Searching...
No Matches
GraphAlgorithms.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2018. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
16
17namespace sequoia::maths
18{
19 template<class G, class Pred>
20 [[nodiscard]]
21 G sub_graph(const G& g, Pred nodePred)
22 {
23 G subGraph{g};
24
25 std::size_t pos{};
26 while(pos < subGraph.order())
27 {
28 if(!nodePred(*(subGraph.cbegin_node_weights() + pos)))
29 {
30 subGraph.erase_node(pos);
31 }
32 else
33 {
34 ++pos;
35 }
36 }
37
38 return subGraph;
39 }
40}
Edge & Node storage traits, base class and final classes for dynamic graphs.