Open
Graph Drawing
Framework

 v.2012.05
 

NodePairEnergy.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00045 #ifdef _MSC_VER
00046 #pragma once
00047 #endif
00048 
00049 #ifndef OGDF_NODE_PAIR_ENERGY_H
00050 #define OGDF_NODE_PAIR_ENERGY_H
00051 
00052 
00053 #include <ogdf/internal/energybased/AdjacencyOracle.h>
00054 #include <ogdf/internal/energybased/EnergyFunction.h>
00055 #include <ogdf/internal/energybased/IntersectionRectangle.h>
00056 
00057 
00058 namespace ogdf {
00059 
00060 class NodePairEnergy: public EnergyFunction {
00061 public:
00062     //Initializes data dtructures to speed up later computations
00063     NodePairEnergy(const String energyname, GraphAttributes &AG);
00064     virtual ~NodePairEnergy() {delete m_nodeNums; delete m_pairEnergy;}
00065     //computes the energy of the initial layout
00066     void computeEnergy();
00067 protected:
00068     //computes the energy stored by a pair of vertices at the given positions
00069     virtual double computeCoordEnergy(node, node, const DPoint&, const DPoint&) const = 0;
00070     //returns the internal number given to each vertex
00071     int nodeNum(node v) const {return (*m_nodeNums)[v];};
00072     //returns true in constant time if two vertices are adjacent
00073     bool adjacent(const node v, const node w) const {return m_adjacentOracle.adjacent(v,w);}
00074     //returns the shape of a vertex as an IntersectionRectangle
00075     const IntersectionRectangle& shape(const node v) const {return m_shape[v];}
00076 
00077 #ifdef OGDF_DEBUG
00078     virtual void printInternalData() const;
00079 #endif
00080 
00081 private:
00082     NodeArray<int> *m_nodeNums;//stores internal number of each vertex
00083     Array2D<double> *m_pairEnergy;//stores for each pair of vertices its energy
00084     NodeArray<double> m_candPairEnergy;//stores for each vertex its pair energy with
00085     //respect to the vertex to be moved if its new position is chosen
00086     NodeArray<IntersectionRectangle> m_shape;//stores the shape of each vertex as
00087     //an IntersectionRectangle
00088     List<node> m_nonIsolated;//list of vertices with degree greater zero
00089     const AdjacencyOracle m_adjacentOracle;//structure for constant time adjacency queries
00090     //function computes energy stored in a certain pair of vertices
00091     double computePairEnergy(const node v, const node w) const;
00092     //computes energy of whole layout if new position of the candidate vertex is chosen
00093     void compCandEnergy();
00094     //If a candidate change is chosen as the new position, this function sets the
00095     //internal data accordingly
00096     void internalCandidateTaken();
00097     };
00098 
00099 
00100 }// namespace ogdf
00101 
00102 #endif