pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgrouting Namespace Reference

boost::graph simplified to pgRouting needs More...

Namespaces

 contraction
 
 graph
 
 tsp
 
 vrp
 

Classes

class  Basic_edge
 
class  Basic_vertex
 
class  Pgr_deadEndContraction
 
class  Pgr_linearContraction
 
class  XY_vertex
 

Typedefs

typedef
graph::Pgr_contractionGraph
< boost::adjacency_list
< boost::listS, boost::vecS,
boost::bidirectionalS,
contraction::Vertex,
contraction::Edge >
, contraction::Vertex,
contraction::Edge
CHDirectedGraph
 
typedef
graph::Pgr_contractionGraph
< boost::adjacency_list
< boost::listS, boost::vecS,
boost::undirectedS,
contraction::Vertex,
contraction::Edge >
, contraction::Vertex,
contraction::Edge
CHUndirectedGraph
 
typedef Simple_cartasian::Point_2 Point
 
typedef CGAL::Simple_cartesian
< double > 
Simple_cartasian
 
Graph types
Type pgRouting
UndirectedGraph Basic undirected graph
DirectedGraph Basic directed graph
xyUndirectedGraph X & Y values stored on the vertex
xyDirectedGraph X & Y values stored on the vertex
typedef graph::Pgr_base_graph
< boost::adjacency_list
< boost::vecS, boost::vecS,
boost::undirectedS,
Basic_vertex, Basic_edge >
, Basic_vertex, Basic_edge
UndirectedGraph
 
typedef graph::Pgr_base_graph
< boost::adjacency_list
< boost::vecS, boost::vecS,
boost::bidirectionalS,
Basic_vertex, Basic_edge >
, Basic_vertex, Basic_edge
DirectedGraph
 
typedef graph::Pgr_base_graph
< boost::adjacency_list
< boost::listS, boost::vecS,
boost::undirectedS, XY_vertex,
Basic_edge >, XY_vertex,
Basic_edge
xyUndirectedGraph
 
typedef graph::Pgr_base_graph
< boost::adjacency_list
< boost::listS, boost::vecS,
boost::bidirectionalS,
XY_vertex, Basic_edge >
, XY_vertex, Basic_edge
xyDirectedGraph
 

Functions

size_t check_vertices (std::vector< Basic_vertex > vertices)
 
size_t check_vertices (std::vector< XY_vertex > vertices)
 
std::vector< Basic_vertexextract_vertices (std::vector< Basic_vertex > vertices, const std::vector< pgr_edge_t > data_edges)
 
std::vector< XY_vertexextract_vertices (const std::vector< Pgr_edge_xy_t > &data_edges)
 
std::vector< Basic_vertexextract_vertices (const std::vector< pgr_edge_t > data_edges)
 
std::vector< XY_vertexextract_vertices (const Pgr_edge_xy_t *data_edges, int64_t count)
 
std::vector< Basic_vertexextract_vertices (const pgr_edge_t *data_edges, int64_t count)
 
std::vector< Basic_vertexextract_vertices (std::vector< Basic_vertex > vertices, const pgr_edge_t *data_edges, int64_t count)
 
std::ostream & operator<< (std::ostream &log, const XY_vertex &v)
 
std::ostream & operator<< (std::ostream &log, const Basic_vertex &v)
 

Detailed Description

boost::graph simplified to pgRouting needs

This class gives the handling basics of a boost::graph of kind G where G: can be an undirected graph or a directed graph.

Requiremets:

A vertex class T_V

Current Available vertex classes:

An edge class T_E

Current Available edge classes:

extract_vertices function

Data obtained from postgresql is stored in A C array of pgr_edge_t type.

std::vector< T_V >

Data obtained from postgresql is stored in o a vector container.

std::vector< T_V >
extract_vertices(std::vector< pgr_edge_t >)

Boost Graph

The code is prepared to be used for:

  • boost::adjacency_list graph type
  • boost::undirectedS when the graph is UNDIRECTED
  • boost::bidirectionalS when the graph is DIRECTED
boost::adjacency_list
< boost::vecS, // not tested with other values
boost::vecS, // not tested with other values
boost::undirectedS, // USinG UNDIRECTED
Basic_vertex, // the vertex class
Basic_edge > // the edge class

Eample Usage:

For this example we will use:

Create Graph type

typedef typename
graph::Pgr_base_graph <
boost::adjacency_list <
boost::vecS,
boost::vecS,
boost::bidirectionalS,
Basic_vertex,
Basic_edge >,
Basic_vertex,
Basic_edge >

Initializing the graph

Graph initialization is for seting the Vertices of the graph.

TODO discuss if also the edges

Vector of unique vertices of the graph

size_t total_edges;
pgr_edge_t *my_edges = NULL;
pgr_get_edges(edges_sql, &my_edges, &total_tuples);
std::vector< Basic_Vertex > vertices(pgrouting::extract_vertices(my_edges));

There are several ways to initialize the graph

// 1. Initializes an empty graph
pgrouting::DirectedGraph digraph(gType);
// 2. Initializes a graph based on the vertices
verices,
gType);
vertices.clear();
3. Initializes a graph based on the extracted vertices
pgrouting::extract_vertices(my_edges, total_edges);
gType);
4. Initializes a graph based on the extracted vertices
gType);
  1. Initializes an empty graph
    • vertices vector size is 0
  2. Initializes a graph based on the vertices:
    • vertices vector size is vertices.size()
    • the vertices are inserted
    • vertices container can be clared to free memory
  3. Initializes a graph based on the vertices extracted
    • from edges stored on a C array
    • the vertices are inserted
  4. Initializes a graph based on the vertices extracted
    • from edges stored on a vector
    • the vertices are inserted

Fill the graph

After initializing the graph with the vertices, the edges can be added.

// inserting edges from a C array
digraph.graph_insert_data(my_edges, total_edges);
// adding more edges to the graph from a vector container
digraph.graph_insert_data(new_edges);

Typedef Documentation

typedef graph::Pgr_contractionGraph< boost::adjacency_list < boost::listS, boost::vecS, boost::bidirectionalS, contraction::Vertex, contraction::Edge >, contraction::Vertex, contraction::Edge > pgrouting::CHDirectedGraph

Definition at line 71 of file pgr_contractionGraph.hpp.

typedef graph::Pgr_contractionGraph< boost::adjacency_list < boost::listS, boost::vecS, boost::undirectedS, contraction::Vertex, contraction::Edge >, contraction::Vertex, contraction::Edge > pgrouting::CHUndirectedGraph

Definition at line 65 of file pgr_contractionGraph.hpp.

typedef graph::Pgr_base_graph<boost::adjacency_list < boost::vecS, boost::vecS, boost::bidirectionalS, Basic_vertex, Basic_edge >, Basic_vertex, Basic_edge > pgrouting::DirectedGraph

Definition at line 247 of file pgr_base_graph.hpp.

typedef Simple_cartasian::Point_2 pgrouting::Point

Definition at line 39 of file xy_vertex.h.

typedef CGAL::Simple_cartesian<double> pgrouting::Simple_cartasian

Definition at line 38 of file xy_vertex.h.

typedef graph::Pgr_base_graph<boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, Basic_vertex, Basic_edge >, Basic_vertex, Basic_edge > pgrouting::UndirectedGraph

Definition at line 241 of file pgr_base_graph.hpp.

typedef graph::Pgr_base_graph<boost::adjacency_list < boost::listS, boost::vecS, boost::bidirectionalS, XY_vertex, Basic_edge >, XY_vertex, Basic_edge > pgrouting::xyDirectedGraph

Definition at line 259 of file pgr_base_graph.hpp.

typedef graph::Pgr_base_graph<boost::adjacency_list < boost::listS, boost::vecS, boost::undirectedS, XY_vertex, Basic_edge >, XY_vertex, Basic_edge > pgrouting::xyUndirectedGraph

Definition at line 253 of file pgr_base_graph.hpp.

Function Documentation

size_t pgrouting::check_vertices ( std::vector< Basic_vertex >  vertices)
size_t pgrouting::check_vertices ( std::vector< XY_vertex >  vertices)

Definition at line 57 of file xy_vertex.cpp.

References pgrouting::XY_vertex::id.

std::vector< Basic_vertex > pgrouting::extract_vertices ( std::vector< Basic_vertex >  vertices,
const std::vector< pgr_edge_t data_edges 
)
std::vector< XY_vertex > pgrouting::extract_vertices ( const std::vector< Pgr_edge_xy_t > &  data_edges)

Definition at line 74 of file xy_vertex.cpp.

References pgrouting::XY_vertex::id.

std::vector< Basic_vertex > pgrouting::extract_vertices ( const std::vector< pgr_edge_t data_edges)

Definition at line 99 of file basic_vertex.cpp.

References pgrouting::Basic_vertex::id, edge::source, and edge::target.

std::vector< XY_vertex > pgrouting::extract_vertices ( const Pgr_edge_xy_t data_edges,
int64_t  count 
)

Definition at line 106 of file xy_vertex.cpp.

References extract_vertices().

std::vector< Basic_vertex > pgrouting::extract_vertices ( const pgr_edge_t data_edges,
int64_t  count 
)

Definition at line 131 of file basic_vertex.cpp.

References extract_vertices().

std::vector< Basic_vertex > pgrouting::extract_vertices ( std::vector< Basic_vertex >  vertices,
const pgr_edge_t data_edges,
int64_t  count 
)

Definition at line 138 of file basic_vertex.cpp.

References extract_vertices().

std::ostream& pgrouting::operator<< ( std::ostream &  log,
const XY_vertex &  v 
)

Definition at line 44 of file xy_vertex.cpp.

References pgrouting::XY_vertex::id, and pgrouting::XY_vertex::point.

std::ostream& pgrouting::operator<< ( std::ostream &  log,
const Basic_vertex &  v 
)

Definition at line 44 of file basic_vertex.cpp.

References pgrouting::Basic_vertex::id.