45template<
class T,
class X,
class Y>
654 return nodePtr->partialChildren;
662 return nodePtr->m_rightEndmost;
784template<
class T,
class X,
class Y>
804 for (++it; it.
valid(); ++it) {
821 firstSon->m_referenceParent = father;
834template<
class T,
class X,
class Y>
840 if (child !=
nullptr) {
869template<
class T,
class X,
class Y>
872 if (parent !=
nullptr) {
877 return addNodeToNewParent(parent, child);
878 }
else if (child !=
nullptr) {
898 sister->m_sibLeft = child;
1037template<
class T,
class X,
class Y>
1124 if (clientSibLeft(
checkNode) ==
nullptr)
1136 else if (clientSibRight(
checkNode) ==
nullptr)
1205 if (clientSibLeft(
checkNode) !=
nullptr) {
1220 if (clientSibRight(
checkNode) !=
nullptr) {
1251 if (parent ==
nullptr) {
1260 m_pertinentNodes->pushFront(parent);
1304 m_pseudoRoot->m_pertChildCount++;
1314template<
class T,
class X,
class Y>
1433 (*seqEnd) = (*seqStart);
1446template<
class T,
class X,
class Y>
1451 removeChildFromSiblings(child);
1454 exchangeNodes(parent, child);
1456 exchangeNodes(parent, child);
1459 destroyNode(parent);
1466template<
class T,
class X,
class Y>
1491 if (m_root !=
nullptr) {
1492 emptyAllPertinentNodes();
1501 if (m_root->m_referenceChild !=
nullptr) {
1505 if (
firstSon->m_sibRight !=
nullptr) {
1517 lastSon = m_root->m_rightEndmost;
1543 if (
checkNode->m_referenceChild !=
nullptr) {
1547 if (
firstSon->m_sibRight !=
nullptr) {
1579 CleanNode(m_pseudoRoot);
1580 delete m_pseudoRoot;
1582 delete m_pertinentNodes;
1585 m_pertinentRoot =
nullptr;
1586 m_pseudoRoot =
nullptr;
1587 m_pertinentNodes =
nullptr;
1589 m_numberOfLeaves = 0;
1590 m_identificationNumber = 0;
1593template<
class T,
class X,
class Y>
1595 return (
nodePtr !=
nullptr) ? 1 : 0;
1599template<
class T,
class X,
class Y>
1601 return (
nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintStatus: NO NODE ACCESSED";
1604template<
class T,
class X,
class Y>
1606 return (
nodePtr !=
nullptr) ?
"ERROR" :
"ERROR: clientPrintType: NO NODE ACCESSED";
1609template<
class T,
class X,
class Y>
1612 m_pertinentRoot =
nullptr;
1613 m_pseudoRoot =
nullptr;
1615 m_numberOfLeaves = 0;
1616 m_identificationNumber = 0;
1618 m_pertinentNodes =
nullptr;
1621template<
class T,
class X,
class Y>
1624 if (
nodePtr->fullChildren->size() > 0)
1640 linkChildrenOfQnode(
checkNode, newNode);
1648 linkChildrenOfQnode(
checkNode, newNode);
1656template<
class T,
class X,
class Y>
1678 removeChildFromSiblings(newNode);
1694 m_pertinentNodes->pushFront(newNode);
1730 firstSon->m_referenceParent = newNode;
1736template<
class T,
class X,
class Y>
1738 while (!m_pertinentNodes->empty()) {
1759 clientDefinedEmptyNode(
nodePtr);
1763 m_pseudoRoot->m_pertChildCount = 0;
1764 m_pseudoRoot->m_pertLeafCount = 0;
1765 m_pseudoRoot->fullChildren->clear();
1766 m_pseudoRoot->partialChildren->clear();
1771template<
class T,
class X,
class Y>
1774 nodePtr->m_pertChildCount = 0;
1776 nodePtr->fullChildren->clear();
1777 nodePtr->partialChildren->clear();
1781template<
class T,
class X,
class Y>
1783 if (
oldNode->m_referenceParent !=
nullptr) {
1790 oldNode->m_referenceParent->m_referenceChild = newNode;
1792 oldNode->m_referenceParent =
nullptr;
1795 else if (
oldNode->endmostChild()) {
1803 oldNode->m_parent->m_leftEndmost = newNode;
1805 oldNode->m_parent->m_rightEndmost = newNode;
1824 oldNode->m_sibRight =
nullptr;
1825 if (
oldNode->m_parent ==
nullptr) {
1844 if (
oldNode->m_sibLeft !=
nullptr) {
1846 oldNode->m_sibLeft->m_sibRight = newNode;
1850 oldNode->m_sibLeft->m_sibLeft = newNode;
1856 if (
oldNode->m_sibRight !=
nullptr) {
1858 oldNode->m_sibRight->m_sibLeft = newNode;
1862 oldNode->m_sibRight->m_sibRight = newNode;
1865 oldNode->m_sibRight =
nullptr;
1872template<
class T,
class X,
class Y>
1908template<
class T,
class X,
class Y>
1923 m_root->m_sibRight = m_root;
1924 return addNewLeavesToTree(newNode,
leafKeys);
1929 m_root->m_sibLeft = m_root;
1930 m_root->m_sibRight = m_root;
1937template<
class T,
class X,
class Y>
1942 if (
newChild->m_sibRight ==
nullptr) {
1952 if (
newChild->m_sibLeft ==
nullptr) {
1961template<
class T,
class X,
class Y>
1967template<
class T,
class X,
class Y>
1975 os.setf(std::ios::showpoint);
1978 os <<
"Creator \"ogdf::PQTree::writeGML\"\n";
1980 os <<
" directed 1\n";
1998 os <<
" label \"" <<
checkNode->m_identificationNumber;
2004 os <<
" graphics [\n";
2007 os <<
" fill \"#FF0000\"\n";
2009 os <<
" fill \"#0000A0\"\n";
2011 os <<
"fill \"#FFFFE6\"\n";
2015 os <<
" fill \"#FF0000\"\n";
2017 os <<
" fill \"#0000A0\"\n";
2019 os <<
" fill \"#00FF00\"\n";
2023 os <<
" fill \"#FF0000\"\n";
2025 os <<
" fill \"#0000A0\"\n";
2027 os <<
" fill \"#FFFFE6\"\n";
2031 os <<
" fill \"#FF0000\"\n";
2033 os <<
" fill \"#0000A0\"\n";
2035 os <<
" fill \"#FFFFE6\"\n";
2094 os <<
" source " <<
id[
checkNode->m_identificationNumber] <<
"\n";
2095 os <<
" target " <<
id[
firstSon->m_identificationNumber] <<
"\n";
2103 os <<
" source " <<
id[
checkNode->m_identificationNumber] <<
"\n";
2104 os <<
" target " <<
id[
nextSon->m_identificationNumber] <<
"\n";
2117 os <<
" source " <<
id[
checkNode->m_identificationNumber] <<
"\n";
2118 os <<
" target " <<
id[
lastSon->m_identificationNumber] <<
"\n";
2123 os <<
" source " <<
id[
checkNode->m_identificationNumber] <<
"\n";
2124 os <<
" target " <<
id[
nextSon->m_identificationNumber] <<
"\n";
2133 os <<
" source " <<
id[
checkNode->m_identificationNumber] <<
"\n";
2134 os <<
" target " <<
id[
nextSon->m_identificationNumber] <<
"\n";
2143template<
class T,
class X,
class Y>
2197 checkNode->m_parent->m_pertChildCount--;
2198 if (!
checkNode->m_parent->m_pertChildCount) {
2226 return m_pertinentRoot !=
nullptr;
2229template<
class T,
class X,
class Y>
2243template<
class T,
class X,
class Y>
2411 if (!
nodePtr->partialChildren->empty()) {
2444 if (clientSibLeft(
partial_1) !=
nullptr) {
2456 if (clientSibRight(
partial_1) !=
nullptr) {
2472 if (!
nodePtr->partialChildren->empty()) {
2502 if (clientSibLeft(
partial_2) !=
nullptr) {
2515 if (clientSibRight(
partial_2) !=
nullptr) {
2647 while (!
partial_2->fullChildren->empty()) {
2655 while (!
partial_1->fullChildren->empty()) {
2770 while (!
partial_1->fullChildren->empty()) {
2781template<
class T,
class X,
class Y>
2783 if (
nodePtr->m_referenceParent !=
nullptr) {
2789 nodePtr->m_referenceParent->m_referenceChild =
nodePtr->m_sibRight;
2790 nodePtr->m_sibRight->m_referenceParent =
nodePtr->m_referenceParent;
2792 nodePtr->m_referenceParent->m_referenceChild =
nullptr;
2794 nodePtr->m_referenceParent =
nullptr;
2795 }
else if (
nodePtr->endmostChild()) {
2836 nodePtr->m_sibRight =
nullptr;
2840template<
class T,
class X,
class Y>
2842 if (parent !=
nullptr) {
2843 removeChildFromSiblings(child);
2856template<
class T,
class X,
class Y>
2861 for (
int i = 0; i < (
arraySize - 1); i++) {
2870template<
class T,
class X,
class Y>
2883template<
class T,
class X,
class Y>
2898template<
class T,
class X,
class Y>
2901 || (*nodePtr)->partialChildren->size() > 0) {
2905 (*nodePtr)->m_childCount = (*nodePtr)->m_childCount - (*nodePtr)->fullChildren->size() + 1;
2910 PQNode<T, X, Y>* newNode = createNodeAndCopyFullChildren((*nodePtr)->fullChildren);
2915 newNode->
m_sibRight = (*nodePtr)->m_referenceChild->m_sibRight;
2917 newNode->
m_sibLeft->m_sibRight = newNode;
2922 (*nodePtr) = newNode;
2927template<
class T,
class X,
class Y>
2950 m_pertinentNodes->pushFront(
newQnode);
2965 if (
nodePtr->fullChildren->size() > 0) {
2985 checkIfOnlyChild(emptyNode,
nodePtr);
2993template<
class T,
class X,
class Y>
2996 || (*nodePtr)->partialChildren->size() != 1) {
3014template<
class T,
class X,
class Y>
3035 || (
nodePtr->partialChildren->size() != 1)) {
3067 emptyNode =
nodePtr->m_referenceChild;
3068 removeChildFromSiblings(emptyNode);
3093 linkChildrenOfQnode(
checkNode, emptyNode);
3107template<
class T,
class X,
class Y>
3135 || (*nodePtr)->partialChildren->size() != 2) {
3151 (*nodePtr)->m_childCount--;
3203 while (!
partial_2->fullChildren->empty()) {
3234template<
class T,
class X,
class Y>
3253template<
class T,
class X,
class Y>
3283 if (
nodePtr->fullChildren->size() > 0) {
3289 if (
nodePtr->m_leftEndmost !=
nullptr) {
3332 if (!
nodePtr->partialChildren->empty()) {
3341 nodePtr->partialChildren->startAtBottom();
3359template<
class T,
class X,
class Y>
3407 if (!
nodePtr->fullChildren->empty()) {
3422 for (it =
nodePtr->partialChildren->begin(); it.
valid(); ++it) {
3438 else if (
nodePtr->partialChildren->size() == 2) {
Declaration and implementation of Array class and Array algorithms.
Declaration and implementation of the class PQInternalKey.
Declaration and implementation of the class PQInternalNode.
Declaration and implementation of the class PQleaf.
Declaration and implementation of the class PQLeafKey.
Declaration and implementation of the class PQNode.
Declaration and implementation of the class PQNodeKey.
Declaration and implementation of list-based queues (classes QueuePure<E> and Queue<E>).
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
The parameterized class Array implements dynamic arrays of type E.
Doubly linked lists (maintaining the length of the list).
Encapsulates a pointer to a list element.
bool valid() const
Returns true iff the iterator points to an element.
The class template PQInternalNode is used to present P-nodes and Q-nodes in the PQ-Tree.
virtual PQNodeRoot::PQNodeType type() const
Returns the variable m_type in the derived class PQInternalNode.
The datastructure PQ-tree was designed to present a set of permutations on an arbitrary set of elemen...
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.
PQNode< T, X, Y > * m_referenceChild
Stores a pointer to one child, the reference child of the doubly linked cirkular list of children of ...
PQNodeType m_parentType
Stores the type of the parent which can be either a P- or Q-node.
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * m_rightEndmost
Stores the right endmost child of a Q-node.
PQNode< T, X, Y > * m_sibLeft
Stores a pointer ot the left sibling of PQNode.
PQNode< T, X, Y > * m_leftEndmost
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 ...
List< PQNode< T, X, Y > * > * fullChildren
Stores all full children of a node during a reduction.
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
PQNode< T, X, Y > * m_parent
Is a pointer to the parent.
PQNode< T, X, Y > * m_sibRight
Stores a pointer ot the right sibling of PQNode.
int m_pertChildCount
Stores the number of pertinent children of the node.
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.
void sortExceptions(int Exceptions[], int arraySize)
Sorts the exceptions before frontExcept() scans the frontier.
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.
virtual bool templateP4(PQNode< T, X, Y > **nodePtr)
Template matching for a P-node with full, empty and exactly one partial children.
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...
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...
virtual void destroyNode(PQNode< T, X, Y > *nodePtr)
Marks a node as PQNodeRoot::PQNodeStatus::ToBeDeleted.
virtual bool templateQ1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for Q-nodes with only full children.
virtual bool templateP6(PQNode< T, X, Y > **nodePtr)
Template matching for a P-node with full, empty and exactly two partial children.
virtual bool templateL1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for leaves.
virtual PQNode< T, X, Y > * clientRightEndmost(PQNode< T, X, Y > *nodePtr) const
virtual bool templateP1(PQNode< T, X, Y > *nodePtr, bool isRoot)
Template matching for P-nodes with only full children.
PQNode< T, X, Y > * m_pertinentRoot
a pointer to the root of the pertinent subtree.
List< PQNode< T, X, Y > * > * partialChildren(PQNode< T, X, Y > *nodePtr)
virtual bool Reduce(SListPure< PQLeafKey< T, X, Y > * > &leafKeys)
Performs the reduction of the pertinent leaves with the help of the template matchings,...
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 ...
virtual ~PQTree()
Destructor.
virtual bool addNodeToNewParent(PQNode< T, X, Y > *parent, PQNode< T, X, Y > *child, PQNode< T, X, Y > *leftBrother, PQNode< T, X, Y > *rightBrother)
Adds a node child to the children of another node specified in parent.
virtual void Cleanup()
Removes the entire PQ-tree.
virtual void exchangeNodes(PQNode< T, X, Y > *oldNode, PQNode< T, X, Y > *newNode)
Replaces the oldNode by the newNode in the tree.
virtual bool templateP5(PQNode< T, X, Y > *nodePtr)
Template matching for a P-node with full, empty children and exactly one partial child.
void writeGML(const char *fileName)
The function writeGML() prints the PQ-tree in the GML fileformat.
PQNode< T, X, Y > * m_root
a pointer to the root of the $PQ$-tree.
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 bool checkIfOnlyChild(PQNode< T, X, Y > *child, PQNode< T, X, Y > *parent)
Checks if child is the only child of parent.
int m_identificationNumber
Stores the total number of nodes that have been allocated.
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...
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.
virtual PQNode< T, X, Y > * clientNextSib(PQNode< T, X, Y > *nodePtr, PQNode< T, X, Y > *other) const
virtual void emptyAllPertinentNodes()
Cleans up all flags that have been set in the pertinent nodes during the reduction process.
void writeGML(std::ostream &os)
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...
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 int removeNodeFromTree(PQNode< T, X, Y > *parent, PQNode< T, X, Y > *child)
The objective is to remove a node child from the PQ-tree.
int m_numberOfLeaves
Stores the number of leaves.
virtual PQNode< T, X, Y > * clientSibRight(PQNode< T, X, Y > *nodePtr) const
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 void CleanNode(PQNode< T, X, Y > *)
virtual PQNode< T, X, Y > * clientSibLeft(PQNode< T, X, Y > *nodePtr) const
List< PQNode< T, X, Y > * > * fullChildren(PQNode< T, X, Y > *nodePtr)
virtual void removeChildFromSiblings(PQNode< T, X, Y > *nodePtr)
Removes the node nodePtr from the doubly linked list of its parent.
List< PQNode< T, X, Y > * > * m_pertinentNodes
Stores all nodes that have been marked PQNodeRoot::PQNodeStatus::Full or PQNodeRoot::PQNodeStatus::Pa...
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...
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 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...
PQNode< T, X, Y > * root() const
Returns a pointer of the root node of the PQTree.
virtual int Initialize(SListPure< PQLeafKey< T, X, Y > * > &leafKeys)
Initializes the PQ-tree with a set of elements.
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.
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.
virtual PQNode< T, X, Y > * clientLeftEndmost(PQNode< T, X, Y > *nodePtr) const
virtual bool Bubble(SListPure< PQLeafKey< T, X, Y > * > &leafKeys)
Realizes a function described in [Booth].
virtual bool templateQ3(PQNode< T, X, Y > *nodePtr)
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.
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.
Encapsulates a pointer to an ogdf::SList element.
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.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.