46 template<
class T,
class X,
class Y>
175 void writeGML(
const char *fileName);
816 template<
class T,
class X,
class Y>
821 if (!leafKeys.empty())
838 for (++it; it.
valid(); ++it)
869 template<
class T,
class X,
class Y>
878 if (child !=
nullptr)
911 template<
class T,
class X,
class Y>
919 if (parent !=
nullptr)
923 if (leftBrother ==
nullptr && rightBrother ==
nullptr)
925 else if (child !=
nullptr)
942 PQNode<T,X,Y>* brother = (leftBrother !=
nullptr) ? leftBrother : rightBrother;
951 else if (leftBrother ==
nullptr)
982 else if (rightBrother ==
nullptr)
1055 else if (leftBrother !=
nullptr && rightBrother !=
nullptr)
1097 template<
class T,
class X,
class Y>
1134 for (it = leafKeys.begin(); it.
valid(); ++it)
1138 processNodes.
append(checkLeaf);
1148 while ((processNodes.
size() + blockCount + offTheTop) > 1)
1150 if (processNodes.
size() == 0)
1171 blockedNodes.
push(checkNode);
1173 int blockedSiblings = 0;
1264 if (blockedSiblings > 0)
1316 if (parent ==
nullptr)
1325 processNodes.
append(parent);
1331 blockCount -= blockedSiblings;
1332 blockedSiblings = 0;
1341 blockCount += 1 - blockedSiblings;
1346 if (blockCount == 1)
1366 while (!blockedNodes.
empty())
1383 template<
class T,
class X,
class Y>
1410 bool notFull =
false;
1420 (*seqEnd) = firstFull;
1421 if (leftNext !=
nullptr)
1429 while (fullCount > 0 && !notFull)
1439 leftOld = checkNode;
1440 checkNode = leftNext;
1444 (*seqEnd) = checkNode;
1450 (*seqEnd) = leftOld;
1454 (*seqEnd) = firstFull;
1465 (*seqStart) = firstFull;
1466 if(rightNext !=
nullptr)
1474 while (fullCount > 0 && !notFull)
1484 rightOld = checkNode;
1485 checkNode = rightNext;
1488 (*seqStart) = checkNode;
1493 (*seqStart) = rightOld;
1498 (*seqStart) = firstFull;
1502 if (firstFull == (*seqEnd))
1505 (*seqEnd) = (*seqStart);
1506 (*seqStart) = checkNode;
1517 template<
class T,
class X,
class Y>
1542 template<
class T,
class X,
class Y>
1579 if (
m_root->m_referenceChild !=
nullptr)
1582 helpqueue.
append(firstSon);
1586 while (nextSon != firstSon)
1588 helpqueue.
append(nextSon);
1596 helpqueue.
append(firstSon);
1598 lastSon =
m_root->m_rightEndmost;
1599 helpqueue.
append(lastSon);
1603 while (nextSon != firstSon)
1605 helpqueue.
append(nextSon);
1616 while (!helpqueue.
empty())
1630 helpqueue.
append(firstSon);
1634 while (nextSon != firstSon)
1636 helpqueue.
append(nextSon);
1646 helpqueue.
append(firstSon);
1649 helpqueue.
append(lastSon);
1653 while (nextSon != firstSon)
1655 helpqueue.
append(nextSon);
1681 template<
class T,
class X,
class Y>
1684 return (nodePtr !=
nullptr) ? 1 : 0;
1688 template<
class T,
class X,
class Y>
1691 return (nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintStatus: NO NODE ACCESSED";
1694 template<
class T,
class X,
class Y>
1697 return (nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintType: NO NODE ACCESSED";
1712 template<
class T,
class X,
class Y>
1752 template<
class T,
class X,
class Y>
1770 if (fullNodes->size() == 1)
1776 newNode = fullNodes->popFrontRet();
1816 while (!fullNodes->empty())
1836 template<
class T,
class X,
class Y>
1842 switch (nodePtr->
status())
1873 template<
class T,
class X,
class Y>
1884 template<
class T,
class X,
class Y>
1910 if (oldNode->
m_parent->m_leftEndmost == oldNode)
1911 oldNode->
m_parent->m_leftEndmost = newNode;
1912 else if (oldNode->
m_parent->m_rightEndmost == oldNode)
1913 oldNode->
m_parent->m_rightEndmost = newNode;
1958 if (oldNode->
m_sibLeft->m_sibRight == oldNode)
1959 oldNode->
m_sibLeft->m_sibRight = newNode;
1963 oldNode->
m_sibLeft->m_sibLeft = newNode;
1971 if (oldNode->
m_sibRight->m_sibLeft == oldNode)
1986 template<
class T,
class X,
class Y>
1992 helpqueue.
append(nodePtr);
1994 while (!helpqueue.
empty())
1999 leafKeys.pushBack(checkNode->
getKey());
2017 helpqueue.
append(firstSon);
2020 while (nextSon && nextSon != firstSon)
2022 helpqueue.
append(nextSon);
2031 template<
class T,
class X,
class Y>
2036 if (!leafKeys.empty())
2041 if (leafKeys.begin() != leafKeys.end())
2059 template<
class T,
class X,
class Y>
2064 if (installed !=
nullptr && newChild !=
nullptr)
2087 template<
class T,
class X,
class Y>
2090 std::ofstream os(fileName);
2094 template<
class T,
class X,
class Y>
2103 os.setf(std::ios::showpoint);
2106 os <<
"Creator \"ogdf::PQTree::writeGML\"\n";
2108 os <<
" directed 1\n";
2127 if (checkNode->
getKey() != 0)
2128 checkNode->
getKey()->print(os);
2131 os <<
" graphics [\n";
2135 os <<
" fill \"#FF0000\"\n";
2137 os <<
" fill \"#0000A0\"\n";
2139 os <<
"fill \"#FFFFE6\"\n";
2144 os <<
" fill \"#FF0000\"\n";
2146 os <<
" fill \"#0000A0\"\n";
2148 os <<
" fill \"#00FF00\"\n";
2153 os <<
" fill \"#FF0000\"\n";
2155 os <<
" fill \"#0000A0\"\n";
2157 os <<
" fill \"#FFFFE6\"\n";
2162 os <<
" fill \"#FF0000\"\n";
2164 os <<
" fill \"#0000A0\"\n";
2166 os <<
" fill \"#FFFFE6\"\n";
2181 while (nextSon != firstSon)
2197 if ( firstSon != lastSon)
2202 while (nextSon != firstSon)
2211 if (!helpQueue.
empty())
2224 for (it = secondTrace.
begin(); it.
valid(); ++it)
2239 while (nextSon != firstSon)
2261 if ( firstSon != lastSon)
2270 while (nextSon != firstSon)
2286 template<
class T,
class X,
class Y>
2303 int pertLeafCount = 0;
2313 for (it = leafKeys.begin(); it.
valid(); ++it)
2318 processNodes.
append(checkLeaf);
2323 while (checkNode !=
nullptr && processNodes.
size() > 0)
2325 checkNode = processNodes.
pop();
2341 checkNode->
m_parent->m_pertLeafCount =
2342 checkNode->
m_parent->m_pertLeafCount
2345 checkNode->
m_parent->m_pertChildCount--;
2346 if (!checkNode->
m_parent->m_pertChildCount)
2377 checkNode =
nullptr;
2386 template<
class T,
class X,
class Y>
2392 bool success =
Bubble(leafKeys);
2400 template<
class T,
class X,
class Y>
2561 int endmostcheck = 0;
2566 nodePtr->
m_parent->partialChildren->pushFront(nodePtr);
2579 realfull_1 = checkVarLeft;
2586 realfull_1 = checkVarRight;
2592 realempty_1 = checkVarLeft;
2599 realempty_1 = checkVarRight;
2656 realempty_2 = checkVarLeft;
2663 realempty_2 = checkVarRight;
2697 if (partial_1 !=
nullptr && partial_2 !=
nullptr)
2713 if (sibfull_1 !=
nullptr && sibfull_2 !=
nullptr)
2727 else if (sibpartial_1 !=
nullptr && sibpartial_2 !=
nullptr)
2733 if (partial_1 == sibpartial_2 && partial_2 == sibpartial_1)
2755 if (sibempty_1 ==
nullptr)
2761 if (nonstatussib_1 ==
nullptr)
2785 if (sibempty_2 ==
nullptr)
2791 if (nonstatussib_2 ==
nullptr)
2838 else if (partial_1 !=
nullptr)
2859 if (sibfull_1 !=
nullptr)
2870 else if (!endmostcheck)
2895 if (nonstatussib_1 ==
nullptr)
2913 if (sibempty_1 ==
nullptr)
2920 if (nonstatussib_1 ==
nullptr)
2959 template<
class T,
class X,
class Y>
2984 if (nodePtr->
m_parent->m_leftEndmost == nodePtr)
2985 nodePtr->
m_parent->m_leftEndmost = sibling;
2986 else if (nodePtr->
m_parent->m_rightEndmost == nodePtr)
2987 nodePtr->
m_parent->m_rightEndmost = sibling;
2988 if (sibling !=
nullptr)
2998 if (nodePtr->
m_sibRight->m_sibLeft == nodePtr)
3008 if (nodePtr->
m_sibLeft->m_sibRight == nodePtr)
3021 template<
class T,
class X,
class Y>
3024 if (parent !=
nullptr)
3039 template<
class T,
class X,
class Y>
3042 bool changed =
true;
3046 for (
int i = 0; i < (arraySize-1); i++)
3048 if (Exceptions[i] > Exceptions[i+1])
3050 std::swap(Exceptions[i], Exceptions[i+1]);
3057 template<
class T,
class X,
class Y>
3063 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3070 template<
class T,
class X,
class Y>
3080 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3086 template<
class T,
class X,
class Y>
3090 (*nodePtr)->partialChildren->size() > 0)
3093 (*nodePtr)->m_childCount =
3094 (*nodePtr)->m_childCount - (*nodePtr)->fullChildren->size() + 1;
3104 newNode->
m_sibRight = (*nodePtr)->m_referenceChild->m_sibRight;
3106 newNode->
m_sibLeft->m_sibRight = newNode;
3111 (*nodePtr) = newNode;
3116 template<
class T,
class X,
class Y>
3178 newQnode->
m_parent->partialChildren->pushFront(newQnode);
3183 template<
class T,
class X,
class Y>
3187 (*nodePtr)->partialChildren->size() != 1)
3199 *nodePtr = partialChild;
3204 template<
class T,
class X,
class Y>
3242 nodePtr->
m_parent->partialChildren->pushFront(partialChild);
3247 if (emptyChildCount > 0)
3258 if (emptyChildCount == 1)
3264 emptyNode = nodePtr;
3288 emptyNode->
m_parent = partialChild;
3294 if (emptyChildCount <= 1)
3300 template<
class T,
class X,
class Y>
3329 (*nodePtr)->partialChildren->size() != 2)
3344 (*nodePtr)->m_childCount--;
3406 realEmptyEnd_2->
m_parent = partial_1;
3420 *nodePtr = partial_1;
3425 template<
class T,
class X,
class Y>
3439 nodePtr->
m_parent->fullChildren->pushFront(nodePtr);
3447 template<
class T,
class X,
class Y>
3477 bool sequenceCons =
false;
3514 if (fullNode !=
nullptr)
3515 sequenceCons =
checkChain(nodePtr,fullNode,&sequenceBegin,&sequenceEnd);
3520 sequenceCons =
false;
3524 sequenceCons =
true;
3545 sequenceCons =
true;
3552 return sequenceCons;
3555 template<
class T,
class X,
class Y>
3584 bool conssequence =
false;
3616 conssequence =
checkChain(nodePtr,fullChild,&fullStart,&fullEnd);
3630 conssequence = found;
3646 conssequence = found;
3652 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.
void push(E e)
Puts a new element in the buffer.
virtual int Initialize(SListPure< PQLeafKey< T, X, Y > *> &leafKeys)
Initializes the PQ-tree with a set of elements.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
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.
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
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...
bool endmostChild() const
The function endmostChild() checks if a node is endmost child of a Q-node.
bool valid() const
Returns true iff the iterator points to an element.
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.
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 empty() const
Returns true if the buffer is empty, false otherwise.
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 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.
E popRet()
Removes the newest element from the buffer and returns it.
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.
#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.
const_reference top() const
Returns a reference to the front element.
int m_identificationNumber
Stores the total number of nodes that have been allocated.