LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::weightedGraph< P, D, W > Class Template Reference

Weighted Graph container class. More...

#include <ltiWeightedGraph.h>

Inheritance diagram for lti::weightedGraph< P, D, W >:
Inheritance graph
[legend]
Collaboration diagram for lti::weightedGraph< P, D, W >:
Collaboration graph
[legend]

List of all members.

Classes

class  node
 the elements of the graph are instances of this class More...

Public Types

typedef D value_type
typedef P point_type
typedef W weight_type
typedef std::pair< int, int > edge

Public Member Functions

 weightedGraph ()
 weightedGraph (const weightedGraph< P, D, W > &other)
virtual ~weightedGraph ()
const char * getTypeName () const
weightedGraph< P, D, W > & copy (const weightedGraph< P, D, W > &other)
virtual mathObjectclone () const
bool empty () const
void clear ()
void clearEdges ()
int insertNode (const D &data, const P &point)
void insertNode (int id, const D &data, const P &point)
bool removeNode (int id)
bool getNode (int id, node *&nodePtr) const
const std::map< int, node * > & getNodes () const
void setData (const int id, const D &data)
bool getData (const int id, D &data) const
void setPoint (const int id, const P &pos)
bool getPoint (const int id, P &pos) const
void setWeight (const int idA, const int idB, const W &weight)
getWeight (const int idA, const int idB) const
void insertEdge (const int idA, const int idB, const W &weight)
void removeEdge (const int idA, const int idB)
bool adjacentNodes (const int idA, const int idB) const
const std::map< edge, W > getEdges () const
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)

Detailed Description

template<class P, class D = int, class W = double>
class lti::weightedGraph< P, D, W >

Weighted Graph container class.

This class allows the representation of weighted undirected graphs. This class is implemented as template with tree template arguments. The first P is the point type, that describes the position of the node. This can be a e.g. a dvector or a rgbPixel. Second parameter is D. This is the data type of the data a node contains, and third W is the type of the weights of the edges between the nodes.

The following code will build this graph:

 #include "ltiWeightedGraph.h"
 #include "ltiL2Distance.h"

 double a[]={ 10,10, 12,12, 11,12, 11,11, 10,11,
               0, 0,  1, 0,  2, 0,  1, 1,  2, 1,
              10, 0, 12, 0, 11, 0, 11, 1, 10, 1}; 

 dmatrix data;
 data.useExternData(15,2,a); // don't copy the data, but use it!
 
 l2Distantor<double> distantor;
 weightedGraph<dvector,int,l2Distantor<double>::distance_type> myGraph;
 
 int i,j;
 for (i=0; i<data.rows(); i++) {
   graph.insertNode(data.getRow(i),i);
 }

 for (i=0; i<data.rows(); i++) {
   for (i=i+1; j<data.rows(); j++) {
     graph.insertEdge(i,j,distantor(data.getRow(i),data.getRow(j)));
   }
 }

Member Typedef Documentation

template<class P, class D = int, class W = double>
typedef std::pair<int,int> lti::weightedGraph< P, D, W >::edge

An edge is identified with the ids of the nodes it connects.

template<class P, class D = int, class W = double>
typedef P lti::weightedGraph< P, D, W >::point_type

type of the point in the nodes

template<class P, class D = int, class W = double>
typedef D lti::weightedGraph< P, D, W >::value_type

type of the data in the nodes

template<class P, class D = int, class W = double>
typedef W lti::weightedGraph< P, D, W >::weight_type

type of the weight of the edges


Constructor & Destructor Documentation

template<class P, class D = int, class W = double>
lti::weightedGraph< P, D, W >::weightedGraph (  ) 

default constructor creates an emppty graph;

template<class P, class D = int, class W = double>
lti::weightedGraph< P, D, W >::weightedGraph ( const weightedGraph< P, D, W > &  other  ) 

create this graph as a copy of another graph

Parameters:
other the tree to be copied.
template<class P, class D = int, class W = double>
virtual lti::weightedGraph< P, D, W >::~weightedGraph (  )  [virtual]

destructor


Member Function Documentation

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::adjacentNodes ( const int  idA,
const int  idB 
) const [inline]

check, wether two nodes are adjacent (connected)

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::clear (  ) 

Clears the graph.

All nodes and edges will be removed

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::clearEdges (  ) 

Clears the Edges of the graph.

All nodes will be unconnected

template<class P, class D = int, class W = double>
virtual mathObject* lti::weightedGraph< P, D, W >::clone (  )  const [virtual]

create a clone of this graph

Returns:
a pointer to a copy of this graph

Implements lti::mathObject.

template<class P, class D = int, class W = double>
weightedGraph<P,D,W>& lti::weightedGraph< P, D, W >::copy ( const weightedGraph< P, D, W > &  other  ) 

assigment operator.

copy the contents of other in this object.

Parameters:
other the source graph to be copied.

Reimplemented from lti::ioObject.

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::empty (  )  const

returns true if the graph is empty

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::getData ( const int  id,
D &  data 
) const

Fetch data from the specified node Returns false, if node doesn't exist, true otherwise.

template<class P, class D = int, class W = double>
const std::map<edge,W> lti::weightedGraph< P, D, W >::getEdges (  )  const [inline]

Returns the map with the edges of the graph.

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::getNode ( int  id,
node *&  nodePtr 
) const

Fetch pointer to the specified node.

Return true, if successful.

template<class P, class D = int, class W = double>
const std::map<int,node*>& lti::weightedGraph< P, D, W >::getNodes (  )  const

Returns the map with the nodes.

As key the id of the node is used.

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::getPoint ( const int  id,
P &  pos 
) const

Fetch position of the specified node Returns false, if node doesn't exist, true otherwise.

template<class P, class D = int, class W = double>
const char* lti::weightedGraph< P, D, W >::getTypeName (  )  const [virtual]

returns the name of this class: "weightedGraph"

Reimplemented from lti::mathObject.

template<class P, class D = int, class W = double>
W lti::weightedGraph< P, D, W >::getWeight ( const int  idA,
const int  idB 
) const [inline]

Returns the weight of the edge between node with idA and node with idB.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::insertEdge ( const int  idA,
const int  idB,
const W &  weight 
)

Inserts an edge between node with idA and node with idB into the tree.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::insertNode ( int  id,
const D &  data,
const P &  point 
)

Inserts a node with the specified id and data in the tree.

template<class P, class D = int, class W = double>
int lti::weightedGraph< P, D, W >::insertNode ( const D &  data,
const P &  point 
)

Inserts a node that contains the given data into the tree Returns the ID of the new node.

template<class P, class D = int, class W = double>
virtual bool lti::weightedGraph< P, D, W >::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

read the object from the given ioHandler

Reimplemented from lti::mathObject.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::removeEdge ( const int  idA,
const int  idB 
)

removes the edge between nodes with ids idA and idB

template<class P, class D = int, class W = double>
bool lti::weightedGraph< P, D, W >::removeNode ( int  id  ) 

Removes node with given id.

All edges from an to this node will also be removed.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::setData ( const int  id,
const D &  data 
)

Fills the node with id with the given data.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::setPoint ( const int  id,
const P &  pos 
)

Set position of a single node.

template<class P, class D = int, class W = double>
void lti::weightedGraph< P, D, W >::setWeight ( const int  idA,
const int  idB,
const W &  weight 
)

Sets the weight of the edge between node with idA and node with idB.

template<class P, class D = int, class W = double>
virtual bool lti::weightedGraph< P, D, W >::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

write the object in the given ioHandler

Reimplemented from lti::mathObject.


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:52 2010 for LTI-Lib by Doxygen 1.6.1