Aleph-w 7.10.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. A copy of the graph keeps the positions of its nodes.

Example: City network with geographic positions
using EG = Euclidian_Graph<Euclidian_Node<std::string>, Euclidian_Arc<Empty_Class>>;
EG city_map;
auto nyc = city_map.insert_node("NYC", Point(40.7128, -74.0060));
auto boston = city_map.insert_node("Boston", Point(42.3601, -71.0589));
auto dc = city_map.insert_node("DC", Point(38.9072, -77.0369));
// An arc has no weight of its own: its distance comes from the
// positions of its nodes
auto arc = city_map.insert_arc(nyc, boston);
Geom_Number distance = city_map.get_distance(arc);
mpq_class Geom_Number
Numeric type used by the geometry module.
Definition point.H:113
Example: Nearest neighbor search
const Point query(41.0, -73.0);
EG::Node * nearest = nullptr;
Geom_Number min_dist2 = 0;
for (EG::Node_Iterator it(city_map); it.has_curr(); it.next_ne())
{
auto node = it.get_curr();
const Geom_Number d2 = query.distance_squared_to(node->get_position());
if (nearest == nullptr or d2 < min_dist2)
{
min_dist2 = d2;
nearest = node;
}
}
See also
point_utils.H Point utilities
Author
Leandro Rabindranath León

Definition in file tpl_euclidian_graph.H.