49template<
class T,
class X,
class Y>
103template<
class T,
class Y>
392template<
class T,
class Y>
406 for (it = leafKeys.begin(); it.
valid(); ++it) {
408 processNodes.
append(checkLeaf);
409 cleanUp.pushBack(checkLeaf);
416 checkLeaf->
getNodeInfo()->userStructInfo()->m_notVisitedCount = 1;
429 while (!processNodes.
empty()) {
431 nodePtr->
parent(GetParent(nodePtr));
432 if (nodePtr->
parent() && !nodePtr->
parent()->getNodeInfo())
439 nodePtr->
parent()->setNodeInfo(infoPtr);
442 if (nodePtr != this->m_root) {
445 cleanUp.pushBack(nodePtr->
parent());
448 nodePtr->
parent()->getNodeInfo()->userStructInfo()->m_notVisitedCount++;
449 int childCount = nodePtr->
parent()->pertChildCount();
450 nodePtr->
parent()->pertChildCount(++childCount);
468 for (itn = cleanUp.begin(); itn.
valid(); ++itn) {
475template<
class T,
class Y>
483template<
class T,
class Y>
497template<
class T,
class Y>
501 while (!cleanUp.empty()) {
502 nodePtr = cleanUp.popFrontRet();
514 nodePtr->
getNodeInfo()->userStructInfo()->m_notVisitedCount = 0;
515 nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount = 0;
520 for (it = this->m_pertinentNodes->begin(); it.
valid(); ++it) {
524 eliminatedNodes.pushBack(nodePtr);
530 nodePtr->
getNodeInfo()->userStructInfo()->defaultValues();
536template<
class T,
class Y>
543 int countDeletedLeaves = 0;
545 int maxPertLeafCount = 0;
562 for (it = leafKeys.begin(); it.
valid(); ++it) {
564 checkLeaf->
getNodeInfo()->userStructInfo()->m_pertLeafCount = 1;
565 checkLeaf->
getNodeInfo()->userStructInfo()->m_notVisitedCount--;
566 processNodes.
append(checkLeaf);
567 archiv.
push(checkLeaf);
572 while (!processNodes.
empty()) {
573 nodePtr = processNodes.
pop();
577 if (nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount) {
585 nodePtr->
parent()->getNodeInfo()->userStructInfo()->m_pertLeafCount =
586 nodePtr->
parent()->getNodeInfo()->userStructInfo()->m_pertLeafCount
587 + nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount;
588 nodePtr->
parent()->getNodeInfo()->userStructInfo()->m_notVisitedCount--;
589 if (!nodePtr->
parent()->getNodeInfo()->userStructInfo()->m_notVisitedCount) {
600 if (nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount) {
601 fullChildren(nodePtr->
parent())->pushFront(nodePtr);
607 nodePtr->
getNodeInfo()->userStructInfo()->m_w = sumPertChild(nodePtr);
609 if (fullChildren(nodePtr)->size() == nodePtr->
childCount()) {
614 if (nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount) {
615 fullChildren(nodePtr->
parent())->pushFront(nodePtr);
626 if (nodePtr->
getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount) {
627 partialChildren(nodePtr->
parent())->pushFront(nodePtr);
645 this->m_pertinentRoot = nodePtr;
646 if (this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_h
647 < this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_a) {
648 countDeletedLeaves = this->m_pertinentRoot->
getNodeInfo()->userStructInfo()->m_h;
650 countDeletedLeaves = this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_a;
653 if (countDeletedLeaves > 0) {
654 if (this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_h
655 < this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_a) {
656 this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_deleteType =
whaType::H;
658 this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_deleteType =
whaType::A;
662 findMinWHASequence(archiv, eliminatedKeys);
664 return countDeletedLeaves;
667template<
class T,
class Y>
682 while (!archiv.empty()) {
699 this->m_pertinentNodes->pushFront(nodePtr);
709 eliminatedKeys.pushBack(nodePtr->
getKey());
711 this->m_pertinentNodes->pushFront(nodePtr);
721 switch (nodePtr->
getNodeInfo()->userStructInfo()->m_deleteType) {
723 this->m_pertinentNodes->pushFront(nodePtr);
729 this->m_pertinentNodes->pushFront(nodePtr);
744 if (nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1) {
754 - partialChildren(nodePtr)->size());
769 this->m_pertinentNodes->pushFront(nodePtr);
797 if (nodePtr->
getNodeInfo()->userStructInfo()->m_aChild) {
806 if (nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1) {
816 if (nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2) {
827 - partialChildren(nodePtr)->size());
853 if (nodePtr->
getNodeInfo()->userStructInfo()->m_aChild) {
870 this->m_pertinentNodes->pushFront(nodePtr);
880 fullChildren(nodePtr)->clear();
881 partialChildren(nodePtr)->clear();
883 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1 =
nullptr;
884 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2 =
nullptr;
885 nodePtr->
getNodeInfo()->userStructInfo()->m_aChild =
nullptr;
893template<
class T,
class Y>
896 int pertinentChildCount = 0;
899 bool fullLabel =
false;
905 if (hChild1 !=
nullptr) {
922 nextSibling = currentNode->
getNextSib(oldSibling);
929 pertinentChildCount++;
935 if ((currentNode->
getNodeInfo()->userStructInfo()->m_pertLeafCount
936 - currentNode->
getNodeInfo()->userStructInfo()->m_h)
938 pertinentChildCount++;
943 oldSibling = currentNode;
944 currentNode = nextSibling;
947 return pertinentChildCount;
950template<
class T,
class Y>
963 int pertinentChildCount = 0;
978 if (currentNode->
getNodeInfo()->userStructInfo()->m_w
979 - currentNode->
getNodeInfo()->userStructInfo()->m_h
981 pertinentChildCount++;
987 nextSibling = hChild2Sib;
988 oldSibling = hChild2;
990 if (nextSibling !=
nullptr) {
991 currentNode = nextSibling;
994 bool reachedEnd =
false;
996 while (!reachedEnd) {
999 pertinentChildCount++;
1003 if ((currentNode->
getNodeInfo()->userStructInfo()->m_w
1004 - currentNode->
getNodeInfo()->userStructInfo()->m_h)
1006 pertinentChildCount++;
1012 nextSibling = currentNode->
getNextSib(oldSibling);
1013 if (nextSibling ==
nullptr) {
1016 oldSibling = currentNode;
1017 currentNode = nextSibling;
1022 return pertinentChildCount;
1025template<
class T,
class Y>
1038 for (it = partialChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1039 (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1041 for (it = fullChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1042 (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1046 for (it = partialChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1047 (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1053 for (it = fullChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1054 (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1059template<
class T,
class Y>
1100 for (it = partialChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1101 currentNode = (*it);
1102 sumParW = sumParW + currentNode->
getNodeInfo()->userStructInfo()->m_w;
1103 int sumHelp = currentNode->
getNodeInfo()->userStructInfo()->m_w
1104 - currentNode->
getNodeInfo()->userStructInfo()->m_h;
1105 if (sumMax1 <= sumHelp) {
1109 hChild1 = currentNode;
1110 }
else if (sumMax2 <= sumHelp) {
1112 hChild2 = currentNode;
1115 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1 = hChild1;
1116 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2 = hChild2;
1117 nodePtr->
getNodeInfo()->userStructInfo()->m_h = sumParW - sumMax1;
1135 int alpha2 = sumParW - sumMax1 - sumMax2;
1136 int alpha1 = alpha1beta1Number(nodePtr, &aChild);
1138 if (alpha1 <= alpha2) {
1139 nodePtr->
getNodeInfo()->userStructInfo()->m_a = alpha1;
1140 nodePtr->
getNodeInfo()->userStructInfo()->m_aChild = aChild;
1142 nodePtr->
getNodeInfo()->userStructInfo()->m_a = alpha2;
1143 nodePtr->
getNodeInfo()->userStructInfo()->m_aChild =
nullptr;
1147template<
class T,
class Y>
1153 int sumAllW = sumPertChild(nodePtr);
1155 hNumQnode(nodePtr, sumAllW);
1156 aNumQnode(nodePtr, sumAllW);
1159template<
class T,
class Y>
1184 bool fullLabel =
true;
1216 sumLeft = sumLeft + leftChild->
getNodeInfo()->userStructInfo()->m_w
1217 - leftChild->
getNodeInfo()->userStructInfo()->m_h;
1218 checkSibling = leftChild->
getNextSib(holdSibling);
1219 if (checkSibling ==
nullptr) {
1222 holdSibling = leftChild;
1223 leftChild = checkSibling;
1240 holdSibling =
nullptr;
1241 checkSibling =
nullptr;
1248 sumRight = sumRight + rightChild->
getNodeInfo()->userStructInfo()->m_w
1249 - rightChild->
getNodeInfo()->userStructInfo()->m_h;
1251 checkSibling = rightChild->
getNextSib(holdSibling);
1253 if (checkSibling ==
nullptr) {
1257 holdSibling = rightChild;
1258 rightChild = checkSibling;
1272 if (sumLeft == 0 && sumRight == 0) {
1273 nodePtr->
getNodeInfo()->userStructInfo()->m_h = sumAllW;
1274 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1 =
nullptr;
1275 }
else if (sumLeft < sumRight) {
1276 nodePtr->
getNodeInfo()->userStructInfo()->m_h = sumAllW - sumRight;
1277 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1 = rightChild;
1279 nodePtr->
getNodeInfo()->userStructInfo()->m_h = sumAllW - sumLeft;
1280 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild1 = leftChild;
1284template<
class T,
class Y>
1312 int beta1 = alpha1beta1Number(nodePtr, &aChild);
1316 bool endReached = 0;
1334 while (!endReached) {
1342 if (sequence.
empty()) {
1390 while (!sequence.
empty()) {
1392 aSum = aSum + currentNode->
getNodeInfo()->userStructInfo()->m_w
1393 - currentNode->
getNodeInfo()->userStructInfo()->m_h;
1394 if (sequence.
size() == 1) {
1395 leftSib = currentNode;
1398 leftMost = currentNode;
1400 if (aHoldSum < aSum) {
1402 leftMostHold = leftMost;
1403 leftSibHold = leftSib;
1420 while (!sequence.
empty()) {
1422 aSum = aSum + currentNode->
getNodeInfo()->userStructInfo()->m_w
1423 - currentNode->
getNodeInfo()->userStructInfo()->m_h;
1424 if (sequence.
size() == 1) {
1425 leftSib = currentNode;
1428 if (leftSib ==
nullptr) {
1429 leftSib = actualNode;
1431 leftMost = currentNode;
1433 if (aHoldSum < aSum) {
1435 leftMostHold = leftMost;
1436 leftSibHold = leftSib;
1444 if (actualNode != lastChild) {
1445 checkSibling = actualNode->
getNextSib(holdSibling);
1446 holdSibling = actualNode;
1447 actualNode = checkSibling;
1464 if (!sequence.
empty()) {
1466 while (!sequence.
empty()) {
1468 aSum = aSum + currentNode->
getNodeInfo()->userStructInfo()->m_w
1469 - currentNode->
getNodeInfo()->userStructInfo()->m_h;
1470 if (sequence.
size() == 1) {
1471 leftSib = currentNode;
1474 leftMost = currentNode;
1476 if (aHoldSum < aSum) {
1478 leftMostHold = leftMost;
1479 leftSibHold = leftSib;
1492 beta2 = sumAllW - aHoldSum;
1493 if (beta2 < beta1) {
1494 nodePtr->
getNodeInfo()->userStructInfo()->m_a = beta2;
1495 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2 = leftMostHold;
1496 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2Sib = leftSibHold;
1497 nodePtr->
getNodeInfo()->userStructInfo()->m_aChild =
nullptr;
1499 nodePtr->
getNodeInfo()->userStructInfo()->m_a = beta1;
1500 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2 =
nullptr;
1501 nodePtr->
getNodeInfo()->userStructInfo()->m_hChild2Sib =
nullptr;
1502 nodePtr->
getNodeInfo()->userStructInfo()->m_aChild = aChild;
1506template<
class T,
class Y>
1528 for (it = fullChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1529 currentNode = (*it);
1530 sumAllW = sumAllW + currentNode->
getNodeInfo()->userStructInfo()->m_w;
1531 sumHelp = currentNode->
getNodeInfo()->userStructInfo()->m_w
1532 - currentNode->
getNodeInfo()->userStructInfo()->m_a;
1533 if (sumMaxA < sumHelp) {
1535 (*aChild) = currentNode;
1539 for (it = partialChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1540 currentNode = (*it);
1541 sumAllW = sumAllW + currentNode->
getNodeInfo()->userStructInfo()->m_w;
1542 sumHelp = currentNode->
getNodeInfo()->userStructInfo()->m_w
1543 - currentNode->
getNodeInfo()->userStructInfo()->m_a;
1544 if (sumMaxA < sumHelp) {
1546 (*aChild) = currentNode;
1549 return sumAllW - sumMaxA;
1552template<
class T,
class Y>
1565 for (it = fullChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1566 sum =
sum + (*it)->getNodeInfo()->userStructInfo()->m_w;
1568 for (it = partialChildren(nodePtr)->
begin(); it.
valid(); ++it) {
1569 sum =
sum + (*it)->getNodeInfo()->userStructInfo()->m_w;
1575template<
class T,
class Y>
1577 if (nodePtr->
parent() ==
nullptr) {
1580 return nodePtr->
parent();
1593 oldSib = currentNode;
1594 currentNode = nextNode;
1596 while (!L.
empty()) {
1599 return currentNode->
parent();
Declaration and implementation of ArrayBuffer class.
Declaration of doubly linked lists and iterators.
Declaration and implementation of the class PQNode.
Declaration and implementation of the class PQNodeKey.
Declaration and implementation of the class PQNodeRoot.
Declaration and implementation of the class PQTree.
Declaration of singly linked lists and iterators.
Declaration and implementation of list-based queues (classes QueuePure<E> and Queue<E>).
Basic declarations, included by all source files.
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
void push(E e)
Puts a new element in the buffer.
Encapsulates a pointer to a list element.
bool valid() const
Returns true iff the iterator points to an element.
The class template MaxSequencePQTree is designed to compute a maximal consecutive sequence of pertine...
int determineMinRemoveSequence(SListPure< PQLeafKey< T, whaInfo *, Y > * > &leafKeys, SList< PQLeafKey< T, whaInfo *, Y > * > &eliminatedKeys)
Computes the maximal pertinent sequence S' of elements of the set S, that can be reduced in a PQ-tree...
void markPertinentChildren(PQNode< T, whaInfo *, Y > *nodePtr, PQNodeRoot::PQNodeStatus label, whaType deleteType)
Marks all full and/or partial children of nodePtr as either an a-, b-, h- or w-node.
PQNode< T, whaInfo *, Y > * GetParent(PQNode< T, whaInfo *, Y > *nodePtr)
Computes for the node nodePtr its valid parent in the PQ-tree.
void aNumQnode(PQNode< T, whaInfo *, Y > *nodePtr, int sumAllW)
Computes the a-number of the partial Q-node nodePtr.
void findMinWHASequence(ArrayBuffer< PQNode< T, whaInfo *, Y > * > &archiv, SList< PQLeafKey< T, whaInfo *, Y > * > &eliminatedKeys)
Checks the [w,h,a]-number of the pertinent root.
SListPure< PQNode< T, whaInfo *, Y > * > eliminatedNodes
Used to store all eliminated nodes (status == PQNodeRoot::PQNodeStatus::Eliminated) of the PQTree.
int alpha1beta1Number(PQNode< T, whaInfo *, Y > *nodePtr, PQNode< T, whaInfo *, Y > **aChild)
Returns alpha_1 = beta_1 = sum_{i in P(nodePtr)} w_i - max_{i in P(nodePtr)}{(w_i = a_i)},...
virtual void CleanNode(PQNode< T, whaInfo *, Y > *nodePtr)
Frees the memory allocated for the node information class of a node in the PQTree.
int sumPertChild(PQNode< T, whaInfo *, Y > *nodePtr)
Returns w = sum_{i in P(nodePtr)}w_i, where nodePtr is any pertinent node of the PQ-tree.
SListPure< PQNode< T, whaInfo *, Y > * > cleanUp
Used to store all pertinent Nodes of the pertinent subtree before removing the minimal pertinent subs...
void haNumQnode(PQNode< T, whaInfo *, Y > *nodePtr)
Computes the h- and a-number of the partial Q-node nodePtr.
virtual bool Bubble(SListPure< PQLeafKey< T, whaInfo *, Y > * > &leafKeys)
The function Bubble() is an overloaded function of the base template class PQTree.
int setAchildren(PQNode< T, whaInfo *, Y > *hChild2, PQNode< T, whaInfo *, Y > *hChild2Sib)
Traces all children of the largest consecutive sequence of pertinent children of a Q-node.
int setHchild(PQNode< T, whaInfo *, Y > *hChild1)
Processes the children of a Q-node, marking a full sequence of children with at most incident partial...
virtual void emptyAllPertinentNodes()
Does a clean up after a reduction.
void hNumQnode(PQNode< T, whaInfo *, Y > *nodePtr, int sumAllW)
Computes the h-number of the partial Q-node nodePtr.
void haNumPnode(PQNode< T, whaInfo *, Y > *nodePtr)
Computes the h- and a-number of a P-node nodePtr.
virtual void clientDefinedEmptyNode(PQNode< T, whaInfo *, Y > *nodePtr)
Does a clean up of a node. Called by emptyAllPertinentNodes.
void setNodePointer(PQNode< T, X, Y > *pqNode)
The function setNodePointer() sets the private member m_nodePointer.
The class template PQLeafKey is a derived class of class template PQBasicKey.
The class template PQBasicKey is an abstract base class.
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * getEndmost(PQNode< T, X, Y > *other) const
Returns one of the endmost children of node, if node is a Q-node.
int childCount() const
Returns the number of children of a node.
virtual PQLeafKey< T, X, Y > * getKey() const =0
getKey() returns a pointer to the PQLeafKeyof a node, in case that the node is supposed to have a key...
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * getNextSib(PQNode< T, X, Y > *other) const
The function getNextSib() returns one of the siblings of the node.
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
int pertChildCount() const
Returs the number of pertinent children of a node.
The class template PQNodeKey is a derived class of class template PQBasicKey.
@ Eliminated
Nodes removed during the template reduction are marked as as Eliminated. Their memory is not freed....
@ WhaDelete
Nodes that need to be removed in order to obtain a maximal pertinent sequence are marked WhaDelete.
@ PertRoot
The pertinent Root is marked PertRoot during the clean up after a reduction. Technical.
List< PQNode< T, whaInfo *, Y > * > * partialChildren(PQNode< T, whaInfo *, Y > *nodePtr)
void emptyNode(PQNode< T, whaInfo *, Y > *nodePtr)
Cleans up all stacks, flags and pointers of a pertinent node that has been visited during the reducti...
virtual void emptyAllPertinentNodes()
Cleans up all flags that have been set in the pertinent nodes during the reduction process.
List< PQNode< T, whaInfo *, Y > * > * fullChildren(PQNode< T, whaInfo *, Y > *nodePtr)
The parameterized class Queue<E> implements list-based queues.
E pop()
Removes front element and returns it.
bool empty() const
Returns true iff the queue is empty.
iterator append(const E &x)
Adds x at the end of queue.
Singly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
E popFrontRet()
Removes the first element from the list and returns it.
SListIterator< E > pushFront(const E &x)
Adds element x at the beginning of the list.
Encapsulates a pointer to an ogdf::SList element.
bool valid() const
Returns true iff the iterator points to an element.
bool empty() const
Returns true iff the list is empty.
E popFrontRet()
Removes the first element from the list and returns it.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
whaType
The definitions for W, B, H and A describe the type of a node during the computation of the maximal p...
Declaration of class whaInfo.