latest version v1.9 - last update 10 Apr 2010 |
Weighted Graph container class. More...
#include <ltiWeightedGraph.h>
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 mathObject * | clone () 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) |
W | 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) |
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))); } }
typedef std::pair<int,int> lti::weightedGraph< P, D, W >::edge |
An edge is identified with the ids of the nodes it connects.
typedef P lti::weightedGraph< P, D, W >::point_type |
type of the point in the nodes
typedef D lti::weightedGraph< P, D, W >::value_type |
type of the data in the nodes
typedef W lti::weightedGraph< P, D, W >::weight_type |
type of the weight of the edges
lti::weightedGraph< P, D, W >::weightedGraph | ( | ) |
default constructor creates an emppty graph;
lti::weightedGraph< P, D, W >::weightedGraph | ( | const weightedGraph< P, D, W > & | other | ) |
create this graph as a copy of another graph
other | the tree to be copied. |
virtual lti::weightedGraph< P, D, W >::~weightedGraph | ( | ) | [virtual] |
destructor
bool lti::weightedGraph< P, D, W >::adjacentNodes | ( | const int | idA, | |
const int | idB | |||
) | const [inline] |
check, wether two nodes are adjacent (connected)
void lti::weightedGraph< P, D, W >::clear | ( | ) |
Clears the graph.
All nodes and edges will be removed
void lti::weightedGraph< P, D, W >::clearEdges | ( | ) |
Clears the Edges of the graph.
All nodes will be unconnected
virtual mathObject* lti::weightedGraph< P, D, W >::clone | ( | ) | const [virtual] |
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.
other | the source graph to be copied. |
Reimplemented from lti::ioObject.
bool lti::weightedGraph< P, D, W >::empty | ( | ) | const |
returns true if the graph is empty
bool lti::weightedGraph< P, D, W >::getData | ( | const int | id, | |
D & | data | |||
) | const |
const std::map<edge,W> lti::weightedGraph< P, D, W >::getEdges | ( | ) | const [inline] |
Returns the map with the edges of the graph.
bool lti::weightedGraph< P, D, W >::getNode | ( | int | id, | |
node *& | nodePtr | |||
) | const |
Fetch pointer to the specified node.
Return true, if successful.
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.
bool lti::weightedGraph< P, D, W >::getPoint | ( | const int | id, | |
P & | pos | |||
) | const |
const char* lti::weightedGraph< P, D, W >::getTypeName | ( | ) | const [virtual] |
returns the name of this class: "weightedGraph"
Reimplemented from lti::mathObject.
W lti::weightedGraph< P, D, W >::getWeight | ( | const int | idA, | |
const int | idB | |||
) | const [inline] |
void lti::weightedGraph< P, D, W >::insertEdge | ( | const int | idA, | |
const int | idB, | |||
const W & | weight | |||
) |
void lti::weightedGraph< P, D, W >::insertNode | ( | int | id, | |
const D & | data, | |||
const P & | point | |||
) |
int lti::weightedGraph< P, D, W >::insertNode | ( | const D & | data, | |
const P & | point | |||
) |
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.
void lti::weightedGraph< P, D, W >::removeEdge | ( | const int | idA, | |
const int | idB | |||
) |
removes the edge between nodes with ids idA and idB
bool lti::weightedGraph< P, D, W >::removeNode | ( | int | id | ) |
void lti::weightedGraph< P, D, W >::setData | ( | const int | id, | |
const D & | data | |||
) |
Fills the node with id with the given data.
void lti::weightedGraph< P, D, W >::setPoint | ( | const int | id, | |
const P & | pos | |||
) |
Set position of a single node.
void lti::weightedGraph< P, D, W >::setWeight | ( | const int | idA, | |
const int | idB, | |||
const W & | weight | |||
) |
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.