47 template<
class T,
class X,
class Y>
176 void writeGML(
const char *fileName);
817 template<
class T,
class X,
class Y>
822 if (!leafKeys.empty())
839 for (++it; it.
valid(); ++it)
870 template<
class T,
class X,
class Y>
879 if (child !=
nullptr)
912 template<
class T,
class X,
class Y>
920 if (parent !=
nullptr)
924 if ((leftBrother ==
nullptr) && (rightBrother ==
nullptr))
926 else if (child !=
nullptr)
943 PQNode<T,X,Y>* brother = (leftBrother !=
nullptr) ? leftBrother : rightBrother;
952 else if (leftBrother ==
nullptr)
983 else if (rightBrother ==
nullptr)
1056 else if (leftBrother !=
nullptr && rightBrother !=
nullptr)
1098 template<
class T,
class X,
class Y>
1135 for (it = leafKeys.begin(); it.
valid(); ++it)
1139 processNodes.
append(checkLeaf);
1149 while ((processNodes.
size() + blockCount + offTheTop) > 1)
1151 if (processNodes.
size() == 0)
1172 blockedNodes.
push(checkNode);
1174 int blockedSiblings = 0;
1265 if (blockedSiblings > 0)
1318 if (parent ==
nullptr)
1327 processNodes.
append(parent);
1333 blockCount -= blockedSiblings;
1334 blockedSiblings = 0;
1347 blockCount += 1 - blockedSiblings;
1353 if (blockCount == 1)
1373 while (!blockedNodes.
empty())
1390 template<
class T,
class X,
class Y>
1417 bool notFull =
false;
1427 (*seqEnd) = firstFull;
1428 if (leftNext !=
nullptr)
1436 while (fullCount > 0 && !notFull)
1446 leftOld = checkNode;
1447 checkNode = leftNext;
1451 (*seqEnd) = checkNode;
1457 (*seqEnd) = leftOld;
1461 (*seqEnd) = firstFull;
1472 (*seqStart) = firstFull;
1473 if(rightNext !=
nullptr)
1481 while (fullCount > 0 && !notFull)
1491 rightOld = checkNode;
1492 checkNode = rightNext;
1495 (*seqStart) = checkNode;
1500 (*seqStart) = rightOld;
1505 (*seqStart) = firstFull;
1509 if (firstFull == (*seqEnd))
1512 (*seqEnd) = (*seqStart);
1513 (*seqStart) = checkNode;
1524 template<
class T,
class X,
class Y>
1549 template<
class T,
class X,
class Y>
1586 if (
m_root->m_referenceChild !=
nullptr)
1589 helpqueue.
append(firstSon);
1593 while (nextSon != firstSon)
1595 helpqueue.
append(nextSon);
1603 helpqueue.
append(firstSon);
1605 lastSon =
m_root->m_rightEndmost;
1606 helpqueue.
append(lastSon);
1610 while (nextSon != firstSon)
1612 helpqueue.
append(nextSon);
1623 while (!helpqueue.
empty())
1637 helpqueue.
append(firstSon);
1641 while (nextSon != firstSon)
1643 helpqueue.
append(nextSon);
1653 helpqueue.
append(firstSon);
1656 helpqueue.
append(lastSon);
1660 while (nextSon != firstSon)
1662 helpqueue.
append(nextSon);
1688 template<
class T,
class X,
class Y>
1691 return (nodePtr !=
nullptr) ? 1 : 0;
1695 template<
class T,
class X,
class Y>
1698 return (nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintStatus: NO NODE ACCESSED";
1701 template<
class T,
class X,
class Y>
1704 return (nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintType: NO NODE ACCESSED";
1719 template<
class T,
class X,
class Y>
1759 template<
class T,
class X,
class Y>
1777 if (fullNodes->size() == 1)
1783 newNode = fullNodes->popFrontRet();
1823 while (!fullNodes->empty())
1843 template<
class T,
class X,
class Y>
1849 switch (nodePtr->
status())
1880 template<
class T,
class X,
class Y>
1891 template<
class T,
class X,
class Y>
1917 if (oldNode->
m_parent->m_leftEndmost == oldNode)
1918 oldNode->
m_parent->m_leftEndmost = newNode;
1919 else if (oldNode->
m_parent->m_rightEndmost == oldNode)
1920 oldNode->
m_parent->m_rightEndmost = newNode;
1966 if (oldNode->
m_sibLeft->m_sibRight == oldNode)
1967 oldNode->
m_sibLeft->m_sibRight = newNode;
1971 oldNode->
m_sibLeft->m_sibLeft = newNode;
1979 if (oldNode->
m_sibRight->m_sibLeft == oldNode)
1994 template<
class T,
class X,
class Y>
2000 helpqueue.
append(nodePtr);
2002 while (!helpqueue.
empty())
2007 leafKeys.pushBack(checkNode->
getKey());
2025 helpqueue.
append(firstSon);
2028 while (nextSon && nextSon != firstSon)
2030 helpqueue.
append(nextSon);
2039 template<
class T,
class X,
class Y>
2044 if (!leafKeys.empty())
2049 if (leafKeys.begin() != leafKeys.end())
2067 template<
class T,
class X,
class Y>
2072 if ((installed !=
nullptr) && (newChild !=
nullptr))
2095 template<
class T,
class X,
class Y>
2098 ofstream os(fileName);
2102 template<
class T,
class X,
class Y>
2111 os.setf(ios::showpoint);
2114 os <<
"Creator \"ogdf::PQTree::writeGML\"\n";
2116 os <<
" directed 1\n";
2135 if (checkNode->
getKey() != 0)
2136 checkNode->
getKey()->print(os);
2139 os <<
" graphics [\n";
2143 os <<
" fill \"#FF0000\"\n";
2145 os <<
" fill \"#0000A0\"\n";
2147 os <<
"fill \"#FFFFE6\"\n";
2152 os <<
" fill \"#FF0000\"\n";
2154 os <<
" fill \"#0000A0\"\n";
2156 os <<
" fill \"#00FF00\"\n";
2161 os <<
" fill \"#FF0000\"\n";
2163 os <<
" fill \"#0000A0\"\n";
2165 os <<
" fill \"#FFFFE6\"\n";
2170 os <<
" fill \"#FF0000\"\n";
2172 os <<
" fill \"#0000A0\"\n";
2174 os <<
" fill \"#FFFFE6\"\n";
2189 while (nextSon != firstSon)
2205 if ( firstSon != lastSon)
2210 while (nextSon != firstSon)
2219 if (!helpQueue.
empty())
2232 for (it = secondTrace.
begin(); it.
valid(); ++it)
2247 while (nextSon != firstSon)
2269 if ( firstSon != lastSon)
2278 while (nextSon != firstSon)
2294 template<
class T,
class X,
class Y>
2311 int pertLeafCount = 0;
2321 for (it = leafKeys.begin(); it.
valid(); ++it)
2326 processNodes.
append(checkLeaf);
2331 while ((checkNode !=
nullptr) && (processNodes.
size() > 0))
2333 checkNode = processNodes.
pop();
2349 checkNode->
m_parent->m_pertLeafCount =
2350 checkNode->
m_parent->m_pertLeafCount
2353 checkNode->
m_parent->m_pertChildCount--;
2354 if (!checkNode->
m_parent->m_pertChildCount)
2385 checkNode =
nullptr;
2394 template<
class T,
class X,
class Y>
2400 bool success =
Bubble(leafKeys);
2408 template<
class T,
class X,
class Y>
2569 int endmostcheck = 0;
2574 nodePtr->
m_parent->partialChildren->pushFront(nodePtr);
2589 realfull_1 = checkVarLeft;
2596 realfull_1 = checkVarRight;
2602 realempty_1 = checkVarLeft;
2609 realempty_1 = checkVarRight;
2668 realempty_2 = checkVarLeft;
2675 realempty_2 = checkVarRight;
2709 if (partial_1 !=
nullptr && partial_2 !=
nullptr)
2725 if (sibfull_1 !=
nullptr && sibfull_2 !=
nullptr)
2739 else if (sibpartial_1 !=
nullptr && sibpartial_2 !=
nullptr)
2745 if (partial_1 == sibpartial_2 && partial_2 == sibpartial_1)
2767 if (sibempty_1 ==
nullptr)
2773 if (nonstatussib_1 ==
nullptr)
2797 if (sibempty_2 ==
nullptr)
2803 if (nonstatussib_2 ==
nullptr)
2850 else if (partial_1 !=
nullptr)
2871 if (sibfull_1 !=
nullptr)
2882 else if (!endmostcheck)
2907 if (nonstatussib_1 ==
nullptr)
2925 if (sibempty_1 ==
nullptr)
2932 if (nonstatussib_1 ==
nullptr)
2971 template<
class T,
class X,
class Y>
2996 if (nodePtr->
m_parent->m_leftEndmost == nodePtr)
2997 nodePtr->
m_parent->m_leftEndmost = sibling;
2998 else if (nodePtr->
m_parent->m_rightEndmost == nodePtr)
2999 nodePtr->
m_parent->m_rightEndmost = sibling;
3000 if (sibling !=
nullptr)
3010 if (nodePtr->
m_sibRight->m_sibLeft == nodePtr)
3020 if (nodePtr->
m_sibLeft->m_sibRight == nodePtr)
3033 template<
class T,
class X,
class Y>
3036 if (parent !=
nullptr)
3051 template<
class T,
class X,
class Y>
3054 bool changed =
true;
3058 for (
int i = 0; i < (arraySize-1); i++)
3060 if (Exceptions[i] > Exceptions[i+1])
3062 swap(Exceptions[i],Exceptions[i+1]);
3069 template<
class T,
class X,
class Y>
3075 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3082 template<
class T,
class X,
class Y>
3092 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3098 template<
class T,
class X,
class Y>
3102 (*nodePtr)->partialChildren->size() > 0)
3105 (*nodePtr)->m_childCount =
3106 (*nodePtr)->m_childCount - (*nodePtr)->fullChildren->size() + 1;
3116 newNode->
m_sibRight = (*nodePtr)->m_referenceChild->m_sibRight;
3118 newNode->
m_sibLeft->m_sibRight = newNode;
3123 (*nodePtr) = newNode;
3128 template<
class T,
class X,
class Y>
3190 newQnode->
m_parent->partialChildren->pushFront(newQnode);
3195 template<
class T,
class X,
class Y>
3199 (*nodePtr)->partialChildren->size() != 1)
3211 *nodePtr = partialChild;
3216 template<
class T,
class X,
class Y>
3254 nodePtr->
m_parent->partialChildren->pushFront(partialChild);
3259 if (emptyChildCount > 0)
3270 if (emptyChildCount == 1)
3276 emptyNode = nodePtr;
3300 emptyNode->
m_parent = partialChild;
3306 if (emptyChildCount <= 1)
3312 template<
class T,
class X,
class Y>
3341 (*nodePtr)->partialChildren->size() != 2)
3356 (*nodePtr)->m_childCount--;
3418 realEmptyEnd_2->
m_parent = partial_1;
3432 *nodePtr = partial_1;
3437 template<
class T,
class X,
class Y>
3451 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3459 template<
class T,
class X,
class Y>
3489 bool sequenceCons =
false;
3526 if (fullNode !=
nullptr)
3527 sequenceCons =
checkChain(nodePtr,fullNode,&sequenceBegin,&sequenceEnd);
3532 sequenceCons =
false;
3536 sequenceCons =
true;
3557 sequenceCons =
true;
3564 return sequenceCons;
3567 template<
class T,
class X,
class Y>
3596 bool conssequence =
false;
3628 conssequence =
checkChain(nodePtr,fullChild,&fullStart,&fullEnd);
3642 conssequence = found;
3658 conssequence = found;
3664 return conssequence;
int m_pertChildCount
Stores the number of pertinent children of the node.
List< PQNode< T, X, Y > * > * partialChildren
Stores all partial children of a node during a reduction.
int size() const
Returns the number of elements in the queue.
virtual int removeNodeFromTree(PQNode< T, X, Y > *parent, PQNode< T, X, Y > *child)
The objective is to remove a node child from the PQ-tree.
void copyFullChildrenToPartial(PQNode< T, X, Y > *nodePtr, PQNode< T, X, Y > *partialChild)
Copies all full children of nodePtr to a new P-node The node nodePtr has to be a P-node.
The parameterized class Queue<E> implements list-based queues.
bool valid() const
Returns true iff the iterator points to an element.
PQNode< T, X, Y > * root() const
Returns a pointer of the root node of the PQTree.
int m_pertLeafCount
Stores the number of pertinent leaves in the frontier of the node.
iterator append(const E &x)
Adds x at the end of queue.
bool addNewLeavesToTree(PQInternalNode< T, X, Y > *father, SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Adds a set of elements to the already existing set of elements of a PQ-tree.
bool empty() const
Returns true iff the list is empty.
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
Declaration and implementation of the class PQLeafKey.
virtual bool Bubble(SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Realizes a function described in [Booth].
PQNode< T, X, Y > * m_referenceParent
Is a pointer to the parent, in case that the parent is a P-node and the node itself is its reference ...
virtual void destroyNode(PQNode< T, X, Y > *nodePtr)
Marks a node as PQNodeRoot::PQNodeStatus::ToBeDeleted.
virtual void Cleanup()
Removes the entire PQ-tree.
virtual bool Reduction(SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Tests whether permissible permutations of the elements of U exist such that the elements of a subset ...
virtual bool templateQ3(PQNode< T, X, Y > *nodePtr)
PQNode< T, X, Y > * createNodeAndCopyFullChildren(List< PQNode< T, X, Y > *> *fullNodes)
Copies the full children of a P-node that are stored in the stack fullNodes to a new P-node...
virtual bool templateQ1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for Q-nodes with only full children.
virtual int Initialize(SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Initializes the PQ-tree with a set of elements.
Encapsulates a pointer to an ogdf::SList element.
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-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 PQNode< T, X, Y > * clientSibRight(PQNode< T, X, Y > *nodePtr) const
virtual bool Reduce(SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Performs the reduction of the pertinent leaves with the help of the template matchings, designed by Booth and Lueker.
virtual void removeChildFromSiblings(PQNode< T, X, Y > *nodePtr)
Removes the node nodePtr from the doubly linked list of its parent.
PQNode< T, X, Y > * m_pertinentRoot
a pointer to the root of the pertinent subtree.
bool empty() const
Returns true iff the stack is empty.
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
bool endmostChild()
The function endmostChild() checks if a node is endmost child of a Q-node.
void emptyNode(PQNode< T, X, Y > *nodePtr)
Cleans up all stacks, flags and pointers of a pertinent node that has been visited during the reducti...
Declaration and implementation of Array class and Array algorithms.
PQNode< T, X, Y > * m_root
a pointer to the root of the $PQ$-tree.
virtual void linkChildrenOfQnode(PQNode< T, X, Y > *installed, PQNode< T, X, Y > *newChild)
Links the two endmost children of two different Q-nodes via their sibling pointers together...
virtual void exchangeNodes(PQNode< T, X, Y > *oldNode, PQNode< T, X, Y > *newNode)
Replaces the oldNode by the newNode in the tree.
SibDirection putSibling(PQNode< T, X, Y > *newSib)
The default function putSibling() stores a new sibling at a free sibling pointer of the node...
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
virtual bool addNodeToNewParent(PQNode< T, X, Y > *parent, PQNode< T, X, Y > *child)
Adds a node child as a child to another node specified in parent.
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
List< PQNode< T, X, Y > * > * partialChildren(PQNode< T, X, Y > *nodePtr)
virtual bool templateL1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for leaves.
virtual void front(PQNode< T, X, Y > *nodePtr, SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Returns the keys stored in the leaves of the front of nodePtr.
virtual bool checkIfOnlyChild(PQNode< T, X, Y > *child, PQNode< T, X, Y > *parent)
Checks if child is the only child of parent.
virtual void clientDefinedEmptyNode(PQNode< T, X, Y > *nodePtr)
If the user wishes to use different flags in a derived class of PQTree that are not available in this...
virtual PQNode< T, X, Y > * clientRightEndmost(PQNode< T, X, Y > *nodePtr) const
virtual const char * clientPrintStatus(PQNode< T, X, Y > *nodePtr)
If the user wishes to use different status in a derived class of PQTree that are not available in thi...
bool changeSiblings(PQNode< T, X, Y > *oldSib, PQNode< T, X, Y > *newSib)
The function changeSiblings() replaces the old sibling oldSib of the node by a new sibling newSib...
List< PQNode< T, X, Y > * > * m_pertinentNodes
Stores all nodes that have been marked PQNodeRoot::PQNodeStatus::Full or PQNodeRoot::PQNodeStatus::Pa...
iterator begin()
Returns an iterator to the first element of the list.
E pop()
Removes the top-most element from the stack and returns it.
virtual PQNode< T, X, Y > * clientSibLeft(PQNode< T, X, Y > *nodePtr) const
iterator pushBack(const E &x)
Adds element x at the end of the list.
bool checkChain(PQNode< T, X, Y > *nodePtr, PQNode< T, X, Y > *firstFull, PQNode< T, X, Y > **seqStart, PQNode< T, X, Y > **seqEnd)
Checks whether all full children of a Q-node nodePtr form a consecutive sequence. ...
Declaration and implementation of the class PQleaf.
int m_identificationNumber
Each node that has been introduced once into the tree gets a unique number.
Doubly linked lists (maintaining the length of the list).
PQNode< T, X, Y > * m_referenceChild
Stores a pointer to one child, the reference child of the doubly linked cirkular list of children of ...
PQNode< T, X, Y > * getNextSib(PQNode< T, X, Y > *other) const
The function getNextSib() returns one of the siblings of the node.
Declaration and implementation of list-based queues (classes QueuePure<E> and Queue<E>).
void push(const E &x)
Adds element x as top-most element to the stack.
void writeGML(const char *fileName)
The function writeGML() prints the PQ-tree in the GML fileformat.
virtual bool templateP3(PQNode< T, X, Y > *nodePtr)
Template matching for a P-node with full and empty children that is not the root of the pertinent sub...
virtual bool templateP5(PQNode< T, X, Y > *nodePtr)
Template matching for a P-node with full, empty children and exactly one partial child.
virtual bool templateP4(PQNode< T, X, Y > **nodePtr)
Template matching for a P-node with full, empty and exactly one partial children. ...
virtual void emptyAllPertinentNodes()
Cleans up all flags that have been set in the pertinent nodes during the reduction process...
PQNode< T, X, Y > * m_pseudoRoot
a pointer to the virtual root of the pertinent subtree, in case that the pertinent root cannot be det...
bool empty() const
Returns true iff the queue is empty.
Encapsulates a pointer to a list element.
PQNode< T, X, Y > * m_leftEndmost
virtual PQNode< T, X, Y > * clientLeftEndmost(PQNode< T, X, Y > *nodePtr) const
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
virtual bool templateP1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for P-nodes with only full children.
Declaration and implementation of the class PQNodeKey.
void removeBlock(PQNode< T, X, Y > *nodePtr, bool isRoot)
Of every partial node that is found in the sequence of children of nodePtr, all children are removed ...
E popFrontRet()
Removes the first element from the list and returns it.
The class template PQLeafKey is a derived class of class template PQBasicKey.
The class template PQBasicKey is an abstract base class.
virtual int clientPrintNodeCategorie(PQNode< T, X, Y > *nodePtr)
If the user wishes to use different flags in a derived class of PQTree that are not available in this...
The class template PQInternalNode is used to present P-nodes and Q-nodes in the PQ-Tree.
virtual void CleanNode(PQNode< T, X, Y > *)
virtual bool templateP6(PQNode< T, X, Y > **nodePtr)
Template matching for a P-node with full, empty and exactly two partial children. ...
Declaration and implementation of the class PQInternalKey.
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
Declaration and implementation of the class PQInternalNode.
The datastructure PQ-tree was designed to present a set of permutations on an arbitrary set of elemen...
void sortExceptions(int Exceptions[], int arraySize)
Sorts the exceptions before frontExcept() scans the frontier.
List< PQNode< T, X, Y > * > * fullChildren(PQNode< T, X, Y > *nodePtr)
virtual PQNodeRoot::PQNodeType type() const
Returns the variable m_type in the derived class PQInternalNode.
virtual PQNode< T, X, Y > * clientNextSib(PQNode< T, X, Y > *nodePtr, PQNode< T, X, Y > *other) const
virtual bool templateP2(PQNode< T, X, Y > **nodePtr)
Template matching for a P-node with full and empty children that is the root of the pertinent subtree...
virtual const char * clientPrintType(PQNode< T, X, Y > *nodePtr)
If the user wishes to use different types in a derived class of PQTree that are not available in this...
The namespace for all OGDF objects.
virtual ~PQTree()
Destructor.
Declaration and implementation of the class PQNode.
E pop()
Removes front element and returns it.
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
bool changeEndmost(PQNode< T, X, Y > *oldEnd, PQNode< T, X, Y > *newEnd)
The function changeEndmost() replaces the old endmost child oldEnd of the node by a new child newEnd...
int m_numberOfLeaves
Stores the number of leaves.
bool valid() const
Returns true iff the iterator points to an element.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
virtual bool templateQ2(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for Q-nodes with a pertinent sequence of children on one side of the Q-node...
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
The parameterized class Stack<E> implements list-based stacks.
Declaration and implementation of list-based stacks (StackPure<E> and Stack<E>).
const_reference top() const
Returns a reference to the front element.
int m_identificationNumber
Stores the total number of nodes that have been allocated.