| 1 | /** \file |
| 2 | * \brief Declaration of MultilevelBuilder |
| 3 | * |
| 4 | * \author Gereon Bartel |
| 5 | * |
| 6 | * \par License: |
| 7 | * This file is part of the Open Graph Drawing Framework (OGDF). |
| 8 | * |
| 9 | * \par |
| 10 | * Copyright (C)<br> |
| 11 | * See README.md in the OGDF root directory for details. |
| 12 | * |
| 13 | * \par |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * Version 2 or 3 as published by the Free Software Foundation; |
| 17 | * see the file LICENSE.txt included in the packaging of this file |
| 18 | * for details. |
| 19 | * |
| 20 | * \par |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * \par |
| 27 | * You should have received a copy of the GNU General Public |
| 28 | * License along with this program; if not, see |
| 29 | * http://www.gnu.org/copyleft/gpl.html |
| 30 | */ |
| 31 | |
| 32 | #pragma once |
| 33 | |
| 34 | #include <ogdf/basic/Graph.h> |
| 35 | #include <ogdf/energybased/multilevel_mixer/MultilevelGraph.h> |
| 36 | |
| 37 | namespace ogdf { |
| 38 | |
| 39 | //! Base class for merger modules. |
| 40 | /** |
| 41 | * @ingroup gd-multi |
| 42 | */ |
| 43 | class OGDF_EXPORT MultilevelBuilder |
| 44 | { |
| 45 | private: |
| 46 | /** |
| 47 | * \brief This method constructs one more level on top of an existing MultilevelGraph. |
| 48 | * It must be implemented in any MultilevelBuilder. A level is built by |
| 49 | * adding node-merges to the MultilevelGraph and updating the graph accordingly. |
| 50 | * This is achieved by calling MLG. |
| 51 | * |
| 52 | * @param MLG is the MultilevelGraph for which a new gevel will be built. |
| 53 | * |
| 54 | * @return true if the Graph was changed or false if no level can be built. |
| 55 | */ |
| 56 | virtual bool buildOneLevel(MultilevelGraph &MLG) = 0; |
| 57 | |
| 58 | protected: |
| 59 | // if set to true the length of the edge between two merged nodes will be added to |
| 60 | // all edges that are moved to the other node in this merge. |
| 61 | int m_adjustEdgeLengths; |
| 62 | int m_numLevels; //!< stores number of levels for statistics purposes |
| 63 | |
| 64 | public: |
| 65 | virtual ~MultilevelBuilder() { } |
| 66 | MultilevelBuilder():m_adjustEdgeLengths(0),m_numLevels(1) { } |
| 67 | |
| 68 | virtual void buildAllLevels(MultilevelGraph &MLG) |
| 69 | { |
| 70 | m_numLevels = 1; |
| 71 | MLG.updateReverseIndizes(); |
| 72 | MLG.updateMergeWeights(); |
| 73 | while (buildOneLevel(MLG)) |
| 74 | { |
| 75 | m_numLevels++; |
| 76 | } |
| 77 | MLG.updateReverseIndizes(); |
| 78 | } |
| 79 | |
| 80 | void setEdgeLengthAdjustment(int factor) { m_adjustEdgeLengths = factor; } |
| 81 | int getNumLevels() {return m_numLevels;} |
| 82 | }; |
| 83 | |
| 84 | } |
| 85 | |