Graph Class Reference

Graph superclass to define common interface for Graph objects and provide ability to load up from a file. More...

#include <Graph.h>

Inheritance diagram for Graph:

GraphList List of all members.

Public Member Functions

 Graph ()
 Create empty undirected graph.
 Graph (int n, bool d)
 Create directed graphs with n vertices.
 Graph (int n)
 Create undirected graph with n vertices.
 ~Graph ()
 Release graph memory.
void load (char *fileName)
 Load up the graph encoded in the file.
const int numVertices () const
bool directed () const
bool isEdge (int, int) const
 Does the edge (u,v) exist in the graph?
bool isEdge (int, int, int &) const
 Does the edge (u,v) exist in the graph? And if so, what is its weight?
int edgeWeight (int, int) const
 Return edge weight, or INT_MIN if not present.
VertexList::const_iterator begin (int u) const
VertexList::const_iterator end (int u) const
void addEdge (int u, int v)
void addEdge (int, int, int)
 Add edge to graph structure from (u,v).
bool removeEdge (int, int)
 Remove edge, and if undirected, remove its opposite as well.

Protected Attributes

VertexListvertices_
int n_
bool directed_

Detailed Description

Graph superclass to define common interface for Graph objects and provide ability to load up from a file.

Author:
George Heineman
Date:
6/15/08


Constructor & Destructor Documentation

Graph::Graph (  )  [inline]

Create empty undirected graph.

Graph::Graph ( int  n,
bool  d 
) [inline]

Create directed graphs with n vertices.

Graph::Graph ( int  n  )  [inline]

Create undirected graph with n vertices.

Graph::~Graph (  )  [inline]

Release graph memory.


Member Function Documentation

void Graph::addEdge ( int  u,
int  v,
int  w 
)

Add edge to graph structure from (u,v).

If the graph is undirected, then we must add in reverse as well. It is up to user to ensure that no edge already exists. The check will not be performed here.

Parameters:
u integer identifier of a vertex
v integer identifier of a vertex
w planned weight.

Reimplemented in GraphList.

void Graph::addEdge ( int  u,
int  v 
) [inline]

VertexList::const_iterator Graph::begin ( int  u  )  const [inline]

bool Graph::directed (  )  const [inline]

int Graph::edgeWeight ( int  u,
int  v 
) const

Return edge weight, or INT_MIN if not present.

Parameters:
u integer identifier of a vertex
v integer identifier of a vertex
Returns:
INT_MIN if edge doesn't exist, otherwise return its weight.

VertexList::const_iterator Graph::end ( int  u  )  const [inline]

bool Graph::isEdge ( int  u,
int  v,
int &  w 
) const

Does the edge (u,v) exist in the graph? And if so, what is its weight?

Parameters:
u integer identifier of a vertex
v integer identifier of a vertex
w returned weight of the edge, should it exist
Returns:
true if edge exists (and w contains meaningful information), otherwise false (and w is not meaningful).

bool Graph::isEdge ( int  u,
int  v 
) const

Does the edge (u,v) exist in the graph?

Parameters:
u integer identifier of a vertex
v integer identifier of a vertex
Returns:
true if edge exists, otherwise false

void Graph::load ( char *  fileName  ) 

Load up the graph encoded in the file.

File contains:

     Header
     V E
     v1,v2
     v1,v5
     ...
     

Parameters:
fileName contains the graph information.

const int Graph::numVertices (  )  const [inline]

bool Graph::removeEdge ( int  u,
int  v 
)

Remove edge, and if undirected, remove its opposite as well.

Parameters:
u integer identifier of a vertex
v integer identifier of a vertex
Returns:
true if edge was removed, false otherwise

Reimplemented in GraphList.


Member Data Documentation

bool Graph::directed_ [protected]

int Graph::n_ [protected]

VertexList* Graph::vertices_ [protected]


The documentation for this class was generated from the following files: Algorithm Development Kit 1.0