6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
10 * \brief Declares class NodePairEnergy which implements an energy
11 * function where the energy of a layout depends on the
14 * \author Rene Weiskircher
17 * This file is part of the Open Graph Drawing Framework (OGDF).
21 * See README.txt in the root directory of the OGDF installation for details.
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * Version 2 or 3 as published by the Free Software Foundation;
27 * see the file LICENSE.txt included in the packaging of this file
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public
38 * License along with this program; if not, write to the Free
39 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
40 * Boston, MA 02110-1301, USA.
42 * \see http://www.gnu.org/copyleft/gpl.html
43 ***************************************************************/
50 #ifndef OGDF_NODE_PAIR_ENERGY_H
51 #define OGDF_NODE_PAIR_ENERGY_H
54 #include <ogdf/internal/energybased/AdjacencyOracle.h>
55 #include <ogdf/internal/energybased/EnergyFunction.h>
56 #include <ogdf/internal/energybased/IntersectionRectangle.h>
61 class NodePairEnergy
: public EnergyFunction
{
63 //Initializes data dtructures to speed up later computations
64 NodePairEnergy(const String energyname
, GraphAttributes
&AG
);
65 virtual ~NodePairEnergy() {delete m_nodeNums
; delete m_pairEnergy
;}
66 //computes the energy of the initial layout
69 //computes the energy stored by a pair of vertices at the given positions
70 virtual double computeCoordEnergy(node
, node
, const DPoint
&, const DPoint
&) const = 0;
71 //returns the internal number given to each vertex
72 int nodeNum(node v
) const { return (*m_nodeNums
)[v
]; }
73 //returns true in constant time if two vertices are adjacent
74 bool adjacent(const node v
, const node w
) const {return m_adjacentOracle
.adjacent(v
,w
);}
75 //returns the shape of a vertex as an IntersectionRectangle
76 const IntersectionRectangle
& shape(const node v
) const {return m_shape
[v
];}
79 virtual void printInternalData() const;
83 NodeArray
<int> *m_nodeNums
;//stores internal number of each vertex
84 Array2D
<double> *m_pairEnergy
;//stores for each pair of vertices its energy
85 NodeArray
<double> m_candPairEnergy
;//stores for each vertex its pair energy with
86 //respect to the vertex to be moved if its new position is chosen
87 NodeArray
<IntersectionRectangle
> m_shape
;//stores the shape of each vertex as
88 //an IntersectionRectangle
89 List
<node
> m_nonIsolated
;//list of vertices with degree greater zero
90 const AdjacencyOracle m_adjacentOracle
;//structure for constant time adjacency queries
91 //function computes energy stored in a certain pair of vertices
92 double computePairEnergy(const node v
, const node w
) const;
93 //computes energy of whole layout if new position of the candidate vertex is chosen
94 void compCandEnergy();
95 //If a candidate change is chosen as the new position, this function sets the
96 //internal data accordingly
97 void internalCandidateTaken();