Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_euclidian_graph.H File Reference

Euclidean graph with 2D coordinates. More...

#include <tpl_graph.H>
#include <point.H>
#include <ah-errors.H>
Include dependency graph for tpl_euclidian_graph.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Aleph::Euclidian_Node< Node_Info >
 
class  Aleph::Euclidian_Arc< Arc_Info >
 
class  Aleph::Euclidian_Graph< __Euclidian_Node, __Euclidian_Arc >
 
class  Aleph::Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc >
 
class  Aleph::Abstract_Euclidian_Plane< __Euclidian_Graph >
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Detailed Description

Euclidean graph with 2D coordinates.

Graph where nodes have 2D positions and arc weights are Euclidean distances automatically computed from node positions.

Example: City network with geographic positions
using Point2D = Point2D_Num<double>;
using EG = Euclidian_Graph<Graph_Node<string>, Graph_Arc<Empty_Class>, Point2D>;
EG city_map;
// Add cities with lat/lon coordinates
auto nyc = city_map.insert_node("NYC", Point2D(40.7128, -74.0060));
auto boston = city_map.insert_node("Boston", Point2D(42.3601, -71.0589));
auto dc = city_map.insert_node("DC", Point2D(38.9072, -77.0369));
// Insert arc - distance computed automatically from positions
city_map.insert_arc(nyc, boston);
// Get computed Euclidean distance
auto arc = city_map.search_arc(nyc, boston);
double distance = city_map.get_distance(arc);
Example: Nearest neighbor search
auto query_pos = Point2D(41.0, -73.0);
double min_dist = numeric_limits<double>::max();
EG::Node* nearest = nullptr;
for (Node_Iterator<EG> it(city_map); it.has_curr(); it.next()) {
auto node = it.get_curr();
double dist = query_pos.distance_with(city_map.get_position(node));
if (dist < min_dist) {
min_dist = dist;
nearest = node;
}
}
See also
point_utils.H Point utilities
Author
Leandro Rabindranath León

Definition in file tpl_euclidian_graph.H.