4#include <unordered_map>
6#include <boost/graph/adjacency_list.hpp>
7#include <boost/graph/graph_traits.hpp>
8#include <boost/graph/graphviz.hpp>
9#include <boost/graph/visitors.hpp>
10#include <boost/graph/depth_first_search.hpp>
11#include <boost/graph/exception.hpp>
12#include <boost/graph/named_function_params.hpp>
13#include <boost/range/adaptor/filtered.hpp>
14#include <boost/range/adaptor/transformed.hpp>
15#include <boost/range/adaptor/reversed.hpp>
17#include <features/Features.hpp>
18#include <FeatureBuilder.hpp>
20#include "HY_Features_Ids.hpp"
56 template <
typename OutputIterator >
61 template <
typename Edge,
typename Graph >
64 BOOST_THROW_EXCEPTION(boost::not_a_dag());
67 template <
typename Vertex,
typename Graph >
89 template <
typename VertexListGraph,
typename OutputIterator,
typename P,
90 typename T,
typename R >
92 const boost::bgl_named_params< P, T, R >& params)
95 depth_first_search(g, params.visitor(PreOrderVisitor(result)));
103 template <
typename VertexListGraph,
typename OutputIterator >
107 g, result, boost::bgl_named_params< int, boost::buffer_param_t >(0));
114 typedef boost::property<boost::vertex_index_t, std::size_t>
IndexT;
119 typedef boost::property<boost::vertex_name_t, std::string, IndexT>
NodeT;
126 typedef boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, NodeT>
Graph;
138 using IndexPair = std::pair< NetworkIndexT::const_iterator, NetworkIndexT::const_iterator>;
180 NetworkIndexT::const_reverse_iterator
begin();
187 NetworkIndexT::const_reverse_iterator
end();
211 | boost::adaptors::transformed([
this](
int const& i) {
return get_id(i); })
212 | boost::adaptors::filtered([type](std::string
const& s) {
224 return id_type == type;
252 | boost::adaptors::transformed([
this](
int const& i) {
return get_id(i); })
253 | boost::adaptors::filtered([
this,type,target_layer](std::string
const& s) {
258 (this->
layer_map.find(s) != this->
layer_map.end() && this->layer_map[s] == target_layer);
262 (this->
layer_map.find(s) != this->
layer_map.end() && this->layer_map[s] == target_layer);
264 return (id_type == type) &&
265 (this->
layer_map.find(s) != this->
layer_map.end() && (this->layer_map[s] == target_layer));
276 std::string
get_id( Graph::vertex_descriptor idx);
320 boost::dynamic_properties dp;
321 dp.property(
"node_id", get(boost::vertex_name, this->
graph));
322 boost::write_graphviz_dp(std::cout,
graph, dp);
A lightweight, graph based index of hydrologic features.
Definition network.hpp:146
NetworkIndexT tdfp_order
Definition network.hpp:341
std::vector< std::string > get_origination_ids(const std::string &id)
Get the origination (upstream) ids (immediate neighbors) of all vertices with an edge connecting to i...
Definition network.cpp:172
NetworkIndexT::const_reverse_iterator begin()
Iterator to the first graph vertex descriptor of the topologically ordered graph vertices.
Definition network.cpp:142
NetworkIndexT topo_order
Vector of topologically sorted features.
Definition network.hpp:339
std::string get_id(Graph::vertex_descriptor idx)
Get the string id of a given graph vertex_descriptor idx.
Definition network.cpp:160
NetworkIndexT::const_reverse_iterator end()
Iterator to the end of the topologically ordered graph vertices.
Definition network.cpp:147
auto filter(std::string type, int target_layer, SortOrder order=SortOrder::Topological)
Provides a boost transform_iterator, filtered by type , to the topologically ordered graph vertex str...
Definition network.hpp:246
auto filter(std::string type, SortOrder order=SortOrder::Topological)
Provides a boost transform_iterator, filtered by type , to the topologically ordered graph vertex str...
Definition network.hpp:205
IndexPair tailwaters()
An iterator pair (begin, end) of the network tailwater features.
Definition network.cpp:156
void print_network()
Print a graphviz (text) representation of the network.
Definition network.hpp:319
IndexPair headwaters()
An iterator pair (begin, end) of the network headwater features.
Definition network.cpp:152
std::vector< std::string > get_destination_ids(const std::string &id)
Get the destination (downstream) ids (immediate neighbors) of all vertices with an edge from id.
Definition network.cpp:183
void init_indicies()
Initializes the head/tailwater iterators after the underlying graph is constructed.
Definition network.cpp:83
std::unordered_map< std::string, long > layer_map
Mapping of identifier to hydrofabric layer.
Definition network.hpp:377
NetworkIndexT headwaters_idx
Vector of headwater features.
Definition network.hpp:347
Graph graph
The underlying boost::Graph.
Definition network.hpp:365
const NetworkIndexT & get_sorted_index(SortOrder order=SortOrder::Topological, bool cache=true)
Get an index of the graph in a particular order.
Definition network.cpp:195
virtual ~Network()
Destroy the Network object.
Definition network.hpp:173
std::size_t size()
The number of features in the network (number of vertices)
Definition network.cpp:168
Network()
Construct a new empty Network object.
Definition network.hpp:152
std::unordered_map< std::string, Graph::vertex_descriptor > descriptor_map
Mapping of identity to graph vertex descriptor.
Definition network.hpp:371
NetworkIndexT tailwaters_idx
Vector of tailwater features.
Definition network.hpp:353
std::shared_ptr< FeatureCollection > GeoJSON
Easy short-hand for a smart pointer to a FeatureCollection.
Definition FeatureBuilder.hpp:21
const bool isCatchment(const std::string &type)
Determine if a provided prefix/type is representative of a Catchment concept.
Definition HY_Features_Ids.hpp:33
static const std::string seperator
Namespace constants, define the string prefixes for various hydrofabric identifier types.
Definition HY_Features_Ids.hpp:11
static const std::string nexus
Definition HY_Features_Ids.hpp:12
const bool isNexus(const std::string &type)
Determine if a provided prefix/type is representative of a Nexus concept.
Definition HY_Features_Ids.hpp:24
static const std::string catchment
Definition HY_Features_Ids.hpp:15
Definition network.hpp:22
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, NodeT > Graph
Parameterized graph storing network::NodeT vertices.
Definition network.hpp:126
std::pair< NetworkIndexT::const_iterator, NetworkIndexT::const_iterator > IndexPair
A type for holding a pair of network::NetworkIndexT iterators, pair.first=begin, pair....
Definition network.hpp:138
boost::property< boost::vertex_index_t, std::size_t > IndexT
Type used to index network::NodeT types.
Definition network.hpp:114
void df_preorder_sort(VertexListGraph &g, OutputIterator result, const boost::bgl_named_params< P, T, R > ¶ms)
Pre-order depth first sort function.
Definition network.hpp:91
boost::property< boost::vertex_name_t, std::string, IndexT > NodeT
Type used to label node properties in a network::Graph.
Definition network.hpp:119
SortOrder
Selector for using different traversal orders for linear return.
Definition network.hpp:29
@ TransposedDepthFirstPreorder
A depth-first, pre-order recorded traversal on a transposed graph.
@ Topological
Topological order.
static const int DEFAULT_LAYER_ID
Definition network.hpp:24
std::vector< Graph::vertex_descriptor > NetworkIndexT
A vector of network::Graph vertex_descriptors.
Definition network.hpp:131
Definition network.hpp:47
std::string id
The structure defining graph vertex properties.
Definition network.hpp:48
Pre-order recording dfs_visitor.
Definition network.hpp:58
preorder_visitor(OutputIterator _iter)
Definition network.hpp:59
void discover_vertex(const Vertex &u, Graph &)
Definition network.hpp:68
void back_edge(const Edge &, Graph &)
Definition network.hpp:62
OutputIterator m_iter
Definition network.hpp:74