Graph. More...

#include <rgraph.h>

Collaboration diagram for RGraph< V, E, bAllocVertices, bAllocEdges >:
[legend]

Public Member Functions

void Clear (void)
 
virtual E * CreateEdge (V *v1, V *v2, double w)
 
virtual V * CreateVertex (void)
 
virtual V * CreateVertex (const size_t id)
 
void DeleteEdge (E *e)
 
void DeleteVertex (V *v)
 
RCursor< E > GetEdges (void) const
 
V * GetVertex (const size_t id)
 
RCursor< V > GetVertices (void) const
 
void Insert (V *v)
 
void InsertEdge (E *e)
 
void MinSpanningTree (RGraph *g)
 
 RGraph (size_t nb)
 
virtual ~RGraph (void)
 

Protected Attributes

RContainer< E, bAllocEdges, false > Edges
 
RContainer< V, bAllocVertices,
false > 
Vertices
 

Detailed Description

template<class V, class E, bool bAllocVertices = true, bool bAllocEdges = true>
class R::RGraph< V, E, bAllocVertices, bAllocEdges >

Graph.

The RGraph class provides a template that represents of a graph.

Template Parameters
VClass representing a vertex. It must inherits from RVertex.
EClass representing an edge. It must inherits from REdge.
bAllocVerticesSpecify if the vertices are deallocated by the graph.
bAllocEdgesSpecify if the edges are deallocated by the graph. In practice, the RVertex and REdge classes can be used directly to initialize an instance:
int main()
{
// Create a graph
RGraph<RVertex,REdge,true,true> Graph(5);
RVertex* v1(Graph.CreateVertex());
RVertex* v2(Graph.CreateVertex());
RVertex* v3(Graph.CreateVertex());
Graph.CreateEdge(v1,v2,2.0);
Graph.CreateEdge(v2,v3,1.0);
Graph.CreateEdge(v2,v3,5.0);
// Compute the minimum spanning tree
RGraph<RVertex,REdge,true,true> MinTree(5);
Graph.MinSpanningTree(&MinTree);
}

Constructor & Destructor Documentation

RGraph ( size_t  nb)

Constructor of the graph.

Parameters
nbNumber of edges.
virtual ~RGraph ( void  )
virtual

Destruct the graph.

Member Function Documentation

void Clear ( void  )

Clear the graph and destruct the elements.

RCursor<V> GetVertices ( void  ) const

Get a cursor over the vertices of the graph.

RCursor<E> GetEdges ( void  ) const

Get a cursor over the edges of the graph.

void Insert ( V *  v)

Insert a vertex. It cannot have edges.

Parameters
vVertex to insert.
virtual V* CreateVertex ( void  )
virtual

Create a vertex.

Returns
Pointer to the new created vertex.
virtual V* CreateVertex ( const size_t  id)
virtual

Create a vertex with a given identifier.

Parameters
idIdentifier.
Returns
Pointer to the new created vertex.
V* GetVertex ( const size_t  id)

Get the vertex with a given identifier. If the vertex doesn't exist, it's created.

Parameters
idIdentifier.
Returns
Pointer to the vertex.
void InsertEdge ( E *  e)

Insert an edge.

Parameters
eEdge to insert.
virtual E* CreateEdge ( V *  v1,
V *  v2,
double  w 
)
virtual

Create an edge.

Parameters
v1First Vertex.
v2First Vertex.
wWeight.
void DeleteVertex ( V *  v)

Delete a vertex with all the edges connected to it.

Parameters
vVertex.
void DeleteEdge ( E *  e)

Delete an edge with all the corresponding vertices.

Parameters
eEdge.
void MinSpanningTree ( RGraph< V, E, bAllocVertices, bAllocEdges > *  g)

Compute the minimum spanning trees using the Prim's algorithm.

Parameters
gThe graph that will hold the result.

Member Data Documentation

RContainer<V,bAllocVertices,false> Vertices
protected

The vertices of the graph.

RContainer<E,bAllocEdges,false> Edges
protected

The edges of the graph.