1 /** \file 2 * \brief Declaration and implementation of the class PQleaf. 3 * 4 * \author Sebastian Leipert 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/pqtree/PQNode.h> 35 36 namespace ogdf { 37 38 /** 39 * The datastructure PQ-tree was designed to present a set of 40 * permutations on an arbitrary set of elements. These elements are the 41 * leafs of a PQ-tree. The client has to specify, what kind 42 * of elements he uses. The element of a node is stored in the PQLeafKey 43 * of a PQLeaf. The PQLeaf is the only concrete class 44 * template of the abstract base class template PQNode 45 * that is allowed to have a key. 46 */ 47 template<class T,class X,class Y> 48 class PQLeaf : public PQNode<T,X,Y> 49 { 50 public: 51 /** 52 * The client may choose between two different constructors. 53 * In both cases the constructor expects an integer value \a count, 54 * setting the value of the variable #m_identificationNumber in the base class, 55 * an integer value \a status setting the variable #m_status of 56 * PQLeaf and a pointer to an element of type PQLeafKey. 57 * 58 * One of the constructors expects additional information of type 59 * PQNodeKey and will automatically set 60 * the PQBasicKey::m_nodePointer (see basicKey) of the element of type 61 * PQNodeKey to the newly allocated PQLeaf (see also 62 * PQNode). The second constructor is called, if no 63 * information for the PQLeaf is available or necessary. 64 * Both constructors will automatically set the PQBasicKey::m_nodePointer of the 65 * \p keyPtr to the newly allocated PQLeaf. 66 */ PQLeaf(int count,PQNodeRoot::PQNodeStatus stat,PQLeafKey<T,X,Y> * keyPtr,PQNodeKey<T,X,Y> * infoPtr)67 PQLeaf( 68 int count, 69 PQNodeRoot::PQNodeStatus stat, 70 PQLeafKey<T,X,Y>* keyPtr, 71 PQNodeKey<T,X,Y>* infoPtr) 72 : PQNode<T,X,Y>(count,infoPtr) 73 { 74 m_status = stat; 75 m_pointerToKey = keyPtr; 76 m_mark = PQNodeRoot::PQNodeMark::Unmarked; 77 keyPtr->setNodePointer(this); 78 } 79 80 // Constructor PQLeaf(int count,PQNodeRoot::PQNodeStatus stat,PQLeafKey<T,X,Y> * keyPtr)81 PQLeaf( 82 int count, 83 PQNodeRoot::PQNodeStatus stat, 84 PQLeafKey<T,X,Y>* keyPtr) 85 : PQNode<T,X,Y>(count) 86 { 87 m_status = stat; 88 m_pointerToKey = keyPtr; 89 m_mark = PQNodeRoot::PQNodeMark::Unmarked; 90 keyPtr->setNodePointer(this); 91 } 92 93 /** 94 * The destructor does not delete any 95 * accompanying information class as PQLeafKey, 96 * PQNodeKey and PQInternalKey. 97 * This has been avoided, since applications may need the existence of 98 * these information classes after the corresponding node has been 99 * deleted. If the deletion of an accompanying information class should 100 * be performed with the deletion of a node, either derive a new class 101 * with an appropriate destructor, or make use of the function 102 * CleanNode() of the class template PQTree. 103 */ ~PQLeaf()104 virtual ~PQLeaf() {} 105 106 /** 107 * getKey() returns a pointer to the PQLeafKey 108 * of PQLeaf. The adress of the PQLeafKey is stored in the 109 * private variable #m_pointerToKey. 110 * The key contains informations of the element that is represented by 111 * the PQLeaf in the PQ-tree and is of type PQLeafKey. 112 */ getKey()113 virtual PQLeafKey<T,X,Y>* getKey() const { return m_pointerToKey; } 114 115 /** 116 * setKey() sets the pointer variable #m_pointerToKey to the 117 * specified address of \p pointerToKey that is of type PQLeafKey. 118 * 119 * Observe that \p pointerToKey has 120 * to be instantiated by the client. The function setKey() does 121 * not instantiate the corresponding variable in the derived class. 122 * Using this function will automatically set the PQBasicKey::m_nodePointer 123 * of the element of type key (see PQLeafKey) 124 * to this PQLeaf. The return value is always 1 unless \p pointerKey 125 * was equal to 0. 126 */ setKey(PQLeafKey<T,X,Y> * pointerToKey)127 virtual bool setKey(PQLeafKey<T,X,Y>* pointerToKey) 128 { 129 m_pointerToKey = pointerToKey; 130 if (pointerToKey != nullptr) 131 { 132 m_pointerToKey->setNodePointer(this); 133 return true; 134 } 135 else 136 return false; 137 } 138 139 /** 140 * getInternal() returns 0. The function is designed to 141 * return a pointer to the PQInternalKey 142 * information of a node, in case that 143 * the node is supposed to have internal information. The class 144 * template PQLeaf does not have PQInternalKey information. 145 */ getInternal()146 virtual PQInternalKey<T,X,Y>* getInternal() const { return nullptr; } 147 148 /** 149 * setInternal() accepts only pointers \p pointerToInternal = 0. 150 * 151 * The function setInternal() is designed to set a 152 * specified pointer variable in a derived class 153 * of PQNode to the adress stored in \p pointerToInternal. 154 * which is of type PQInternalKey. 155 * The class template PQLeaf does not store 156 * informations of type PQInternalKey. 157 * 158 * setInternal() ignores the informations as long as 159 * \p pointerToInternal = 0. The return value then is 1. 160 * In case that \p pointerToInternal != 0, the return value is 0. 161 */ setInternal(PQInternalKey<T,X,Y> * pointerToInternal)162 virtual bool setInternal(PQInternalKey<T,X,Y>* pointerToInternal) 163 { 164 if (pointerToInternal != nullptr) 165 return false; 166 else 167 return true; 168 } 169 170 //! Returns the variable #m_mark. 171 /** 172 * The variable #m_mark describes the designation used in 173 * the first pass of Booth and Luekers algorithm called Bubble(). A 174 * PQLeaf is either marked \b BLOCKED, \b UNBLOCKED or \b QUEUED (see 175 * PQNode). 176 */ mark()177 virtual PQNodeRoot::PQNodeMark mark() const { return m_mark; } 178 179 //! Sets the variable #m_mark. mark(PQNodeRoot::PQNodeMark m)180 virtual void mark(PQNodeRoot::PQNodeMark m) { m_mark = m; } 181 182 //! Returns the variable #m_status in the derived class PQLeaf. 183 /** 184 * The functions manage the status of a node in the PQ-tree. A status is 185 * any kind of information of the current situation in the frontier of 186 * a node (the frontier of a node are all descendant leaves of the 187 * node). A status can be anything such as \b EMPTY, \b FULL or 188 * \b PARTIAL (see PQNode). Since there might be more than those three 189 * possibilities, 190 * (e.g. in computing planar subgraphs) this 191 * function may to be overloaded by the client. 192 */ status()193 virtual PQNodeRoot::PQNodeStatus status() const { return m_status; } 194 195 //! Sets the variable #m_status in the derived class PQLeaf. status(PQNodeRoot::PQNodeStatus s)196 virtual void status(PQNodeRoot::PQNodeStatus s) { m_status = s; } 197 198 //! Returns the variable PQInternalNode::m_type in the derived class PQLeaf. 199 /** 200 * The type of a node is either \b PNode, \b QNode or 201 * \b leaf (see PQNodeRoot). 202 * Since the type of an element of type PQLeaf is \b leaf every 203 * input is ignored and the return value will always be \b leaf. 204 */ type()205 virtual PQNodeRoot::PQNodeType type() const { return PQNodeRoot::PQNodeType::Leaf; } 206 207 //! Sets the variable PQInternalNode::m_type in the derived class PQLeaf. type(PQNodeRoot::PQNodeType)208 virtual void type(PQNodeRoot::PQNodeType) { } 209 210 private: 211 212 /** 213 * #m_mark is a variable, storing if the PQLeaf is 214 * \b QUEUEUD, \b BLOCKED or \b UNBLOCKED (see PQNode) 215 * during the first phase of the procedure Bubble(). 216 */ 217 PQNodeRoot::PQNodeMark m_mark; 218 219 /** 220 * #m_pointerToKey stores the adress of the corresponding 221 * PQLeafKey. 222 * This PQLeafKey can be overloaded by the 223 * client in order to represent different sets of elements, where 224 * possible permutations have to be examined by the PQ-tree. 225 */ 226 PQLeafKey<T,X,Y>* m_pointerToKey; 227 228 /** 229 * #m_status is a variable storing the status of a PQLeaf. 230 * A PQLeaf can be either \b FULL or \b EMPTY (see PQNode). 231 */ 232 PQNodeRoot::PQNodeStatus m_status; 233 }; 234 235 } 236