PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgrouting::graph Namespace Reference

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

Classes

class  Pgr_base_graph
 
class  Pgr_contractionGraph
 
class  PgrFlowGraph
 

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

Example 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.insert_edges(my_edges, total_edges);
// adding more edges to the graph from a vector container
digraph.insert_edges(new_edges);