Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MaxSequencePQTree.h
Go to the documentation of this file.
1 
35 #pragma once
36 
37 #include <string.h>
38 #include <ogdf/basic/Graph.h>
39 #include <ogdf/basic/PQTree.h>
41 
42 namespace ogdf {
43 
95 template<class T,class Y>
96 class MaxSequencePQTree: public PQTree<T,whaInfo*,Y>
97 {
98 public:
100 
102 
104  while (!eliminatedNodes.empty())
105  {
106  PQNode<T,whaInfo*,Y> *nodePtr = eliminatedNodes.popFrontRet();
107  CleanNode(nodePtr);
108  delete nodePtr;
109  }
110  }
111 
118  virtual void CleanNode(PQNode<T,whaInfo*,Y>* nodePtr);
119 
121 
128  virtual void clientDefinedEmptyNode(PQNode<T,whaInfo*,Y>* nodePtr);
129 
131 
175  virtual void emptyAllPertinentNodes();
176 
204  SList<PQLeafKey<T,whaInfo*,Y>*> &eliminatedKeys);
205 
206 protected:
209 
224  virtual bool Bubble(SListPure<PQLeafKey<T,whaInfo*,Y>*> &leafKeys);
225 
247 
255 
264 
265 private:
287  void findMinWHASequence(
289  SList<PQLeafKey<T,whaInfo*,Y>*> &eliminatedKeys);
290 
301  int setHchild(PQNode<T,whaInfo*,Y> *hChild1);
302 
316  int setAchildren(
317  PQNode<T,whaInfo*,Y> *hChild2,
318  PQNode<T,whaInfo*,Y> *hChild2Sib);
319 
333  PQNode<T,whaInfo*,Y> *nodePtr,
335  whaType deleteType);
336 
338  void haNumPnode(PQNode<T,whaInfo*,Y> *nodePtr);
339 
345  void haNumQnode(PQNode<T,whaInfo*,Y> *nodePtr);
346 
365  void aNumQnode(PQNode<T,whaInfo*,Y> *nodePtr, int sumAllW);
366 
372  void hNumQnode(PQNode<T,whaInfo*,Y> *nodePtr, int sumAllW);
373 
383  int alpha1beta1Number(
384  PQNode<T,whaInfo*,Y> *nodePtr,
385  PQNode<T,whaInfo*,Y> **aChild);
386 
391  int sumPertChild(PQNode<T,whaInfo*,Y> *nodePtr);
392 };
393 
394 template<class T,class Y>
396 {
397  // Queue for storing all pertinent nodes that still have
398  // to be processed.
399  Queue<PQNode<T,whaInfo*,Y>*> processNodes;
400 
401  /*
402  Enter the [[Full]] leaves into the queue [[processNodes]].
403  In a first step the pertinent leaves have to be identified in the tree
404  and entered on to the queue [[processNodes]]. The identification of
405  the leaves can be done with the help of a pointer stored in every
406  [[PQLeafKey]] (see \ref{PQLeafKey}) in constant time for every element.
407  */
409  for (it = leafKeys.begin(); it.valid(); ++it)
410  {
411  PQNode<T,whaInfo*,Y>* checkLeaf = (*it)->nodePointer();
412  processNodes.append(checkLeaf);
413  cleanUp.pushBack(checkLeaf);
414  if (!checkLeaf->getNodeInfo()) // if leaf does not have an information
415  // class for storing the [wha]-number
416  // allocate one.
417  {
418  whaInfo *newInfo = new whaInfo;
419  PQNodeKey<T,whaInfo*,Y> *infoPtr = new PQNodeKey<T,whaInfo*,Y>(newInfo);
420  checkLeaf->setNodeInfo(infoPtr);
421  infoPtr->setNodePointer(checkLeaf);
422  }
423  checkLeaf->getNodeInfo()->userStructInfo()->m_notVisitedCount = 1;
425  }
426 
427  /*
428  For every node in [[processNodes]], its father is detected using the
429  function [[GetParent]] \ref{GetParent}. The father is placed onto the
430  queue as well, if [[_nodePtr]] is its first child, that is popped from
431  the queue. In that case, the father is marked as [[Queued]] to
432  prevent the node from queue more than once. In any case, the number
433  of pertinent children of the father is updated. This is an important
434  number for computing the maximal pertinent sequence.
435  */
436  while (!processNodes.empty())
437  {
438  PQNode<T,whaInfo*,Y>* nodePtr = processNodes.pop();
439  nodePtr->parent(GetParent(nodePtr));
440  if (nodePtr->parent() &&
441  !nodePtr->parent()->getNodeInfo())
442  // if the parent does not have an information
443  // class for storing the [wha]-number
444  // allocate one.
445  {
446  whaInfo *newInfo = new whaInfo;
447  PQNodeKey<T,whaInfo*,Y> *infoPtr = new PQNodeKey<T,whaInfo*,Y>(newInfo);
448  nodePtr->parent()->setNodeInfo(infoPtr);
449  infoPtr->setNodePointer(nodePtr->parent());
450  }
451  if (nodePtr != this->m_root)
452  {
453  if (nodePtr->parent()->mark() == PQNodeRoot::PQNodeMark::Unmarked)
454  {
455  processNodes.append(nodePtr->parent());
456  cleanUp.pushBack(nodePtr->parent());
458  }
460  int childCount = nodePtr->parent()->pertChildCount();
461  nodePtr->parent()->pertChildCount(++childCount);
462  }
463  }
464 
465 
466  /*
467  This chunk belongs to the function [[Bubble]]. After doing some
468  cleaning up and resetting the flags that have been left at the
469  pertinent nodes during the first bubble up, this chunk computes the
470  maximal pertinent sequence by calling the function [[determineMinRemoveSequence]].
471  It then removes
472  all leaves from the tree that have been marked as [[Eliminated]] and
473  possibly some internal nodes of the $PQ$-tree and stores pointers of
474  type [[leafKey]] for the pertinent leaves in the maximal sequence in the
475  array [[survivedElements]].
476  */
477 
479  for (itn = cleanUp.begin(); itn.valid(); ++itn)
480  (*itn)->mark(PQNodeRoot::PQNodeMark::Unmarked);
481 
482  return true;
483 }
484 
485 template<class T,class Y>
487 {
488  if (nodePtr->getNodeInfo())
489  {
490  delete nodePtr->getNodeInfo()->userStructInfo();
491  delete nodePtr->getNodeInfo();
492  }
493 }
494 
495 template<class T,class Y>
497 {
499  {
500  emptyNode(nodePtr);
502  }
503  else if (nodePtr->status() == PQNodeRoot::PQNodeStatus::PertRoot)
504  emptyNode(nodePtr);
505  else {
506  // Node has an invalid status?
508  emptyNode(nodePtr);
509  }
510 }
511 
512 template<class T,class Y>
514 {
515  PQNode<T,whaInfo*,Y>* nodePtr = nullptr;
516 
517  while (!cleanUp.empty())
518  {
519  nodePtr = cleanUp.popFrontRet();
520  nodePtr->pertChildCount(0);
522  {
523  CleanNode(nodePtr);
524  delete nodePtr;
525  }
526 
527  else {
528  // node must have an Information if contained in cleanUp
529  OGDF_ASSERT(nodePtr->getNodeInfo() != nullptr);
530 
531  nodePtr->getNodeInfo()->userStructInfo()->m_notVisitedCount = 0;
532  nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount = 0;
533  }
534  }
535 
537  for (it = this->m_pertinentNodes->begin();it.valid();++it)
538  {
539  nodePtr = *it;
541  {
543  eliminatedNodes.pushBack(nodePtr);
544  }
545  else if (nodePtr->status() == PQNodeRoot::PQNodeStatus::Full)
547  else if (nodePtr->status() == PQNodeRoot::PQNodeStatus::WhaDelete)
549  else if (nodePtr->getNodeInfo())
550  nodePtr->getNodeInfo()->userStructInfo()->defaultValues();
551  }
553 }
554 
555 template<class T,class Y>
558  SList<PQLeafKey<T,whaInfo*,Y>*> &eliminatedKeys)
559 {
560  PQNode<T,whaInfo*,Y> *nodePtr = nullptr; // dummy
561 
562  //Number of leaves that have to be deleted
563  int countDeletedLeaves = 0;
564  //Number of pertinent leaves
565  int maxPertLeafCount = 0;
566 
567  // A queue storing the nodes whose $[w,h,a]$-number has to be computed next.
568  // A node is stored in [[processNodes]], if for all of its children the
569  // [w,h,a]-number has been computed.
570  Queue<PQNode<T,whaInfo*,Y>*> processNodes;
571 
572  // A stack storing all nodes where a $[w,h,a]$-number
573  // has been computed. This is necessary for a valid cleanup.
575 
576  // Compute a valid parent pointer for every pertinent node.
577  Bubble(leafKeys);
578 
579  // Get all pertinent leaves and stores them on [[processNodes]]
580  // and [[_archiv]].
582  for (it = leafKeys.begin(); it.valid(); ++it)
583  {
584  PQNode<T, whaInfo*, Y> *checkLeaf = (*it)->nodePointer();
585  checkLeaf->getNodeInfo()->userStructInfo()->m_pertLeafCount = 1;
586  checkLeaf->getNodeInfo()->userStructInfo()->m_notVisitedCount--;
587  processNodes.append(checkLeaf);
588  archiv.push(checkLeaf);
589 
590  maxPertLeafCount++;
591  }
592 
593  while (!processNodes.empty())
594  {
595  nodePtr = processNodes.pop();
596  // Compute the $[w,h,a]$ number of [[nodePtr]]. Computing this number is
597  // trivial for leaves and full nodes. When considering a partial node, the
598  // computation has to distinguish between $P$- and $Q$-nodes.
599  if (nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount)
600  {
601  // In case that the actual node, depicted by the pointer
602  // [[nodePtr]] is not the root, the counts of the pertinent
603  // children of [[nodePtr]]'s parent are
604  // updated. In case that all pertinent children of the parent of
605  // [[nodePtr]] have a valid $[w,h,a]$-number, it is possible to compute
606  // the $[w,h,a]$-number of parent. Hence the parent is placed onto
607  // [[processNodes]]and [[_archiv]].
610  + nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount;
612  if (!nodePtr->parent()->getNodeInfo()->userStructInfo()->m_notVisitedCount)
613  {
614  processNodes.append(nodePtr->parent());
615  archiv.push(nodePtr->parent());
616  }
617  }
618  if (nodePtr->type() == PQNodeRoot::PQNodeType::Leaf)
619  {
620  // Compute the $[w,h,a]$-number of a leaf. The computation is trivial.
622  nodePtr->getNodeInfo()->userStructInfo()->m_w = 1;
623  nodePtr->getNodeInfo()->userStructInfo()->m_h = 0;
624  nodePtr->getNodeInfo()->userStructInfo()->m_a = 0;
625  if (nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount < maxPertLeafCount)
626  fullChildren(nodePtr->parent())->pushFront(nodePtr);
627  }
628  else
629  {
630  // [[nodePtr]] is a $P$- or $Q$-node
631  // The $[w,h,a]$ number of $P$- or $Q$-nodes is computed identically.
632  // This is done calling the function [[sumPertChild]].
633  nodePtr->getNodeInfo()->userStructInfo()->m_w = sumPertChild(nodePtr);
634 
635  if (fullChildren(nodePtr)->size() == nodePtr->childCount())
636  {
637  // computes the $h$- and $a$-numbers of a full node. The computation
638  // is trivial. It also updates the list of full nodes of the parent
639  // of [[nodePtr]].
641  if (nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount
642  < maxPertLeafCount)
643  fullChildren(nodePtr->parent())->pushFront(nodePtr);
644  nodePtr->getNodeInfo()->userStructInfo()->m_h = 0;
645  nodePtr->getNodeInfo()->userStructInfo()->m_a = 0;
646  }
647  else
648  {
649  // computes the $[w,h,a]$-number of a partial node. The computation is
650  // nontrivial for both $P$- and $Q$-nodes and is performed in the
651  // function [[haNumPnode]] for $P$-nodes and in the
652  // function [[haNumQnode]] for $Q$-nodes.
653  // This chunk also updates the partial children stack of the parent.
655  if (nodePtr->getNodeInfo()->userStructInfo()->m_pertLeafCount <
656  maxPertLeafCount)
657  partialChildren(nodePtr->parent())->pushFront(nodePtr);
658 
659  if (nodePtr->type() == PQNodeRoot::PQNodeType::PNode)
660  haNumPnode(nodePtr);
661  else
662  haNumQnode(nodePtr);
663  }
664  }
665  }
666 
667  // Determine the root of the pertinent subtree, which the last processed node
668  //[[nodePtr]] and finds the minimum of the $h$- and $a$-number of
669  //[[m_pertinentRoot]]. In case that the minimum is equal to $0$, the
670  //[[m_pertinentRoot]] stays of type $B$. Otherwise the type is selected
671  //according to the minimum.
672  this->m_pertinentRoot = nodePtr;
673  if (this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_h <
675  countDeletedLeaves = this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_h;
676  else
677  countDeletedLeaves = this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_a;
678 
679  if (countDeletedLeaves > 0)
680  {
681  if (this->m_pertinentRoot->getNodeInfo()->userStructInfo()->m_h <
684  else
686  }
687 
688  findMinWHASequence(archiv,eliminatedKeys);
689 
690  return countDeletedLeaves;
691 }
692 
693 template<class T, class Y>
696  SList<PQLeafKey<T, whaInfo*, Y>*> &eliminatedKeys)
697 {
698  //a pointer to the first child of type $h$ of [[nodePtr]].
699  PQNode<T, whaInfo*, Y> *hChild1 = nullptr;
700 
701  //a pointer to the second child of type $h$ of [[nodePtr]].
702  PQNode<T, whaInfo*, Y> *hChild2 = nullptr;
703 
704  //a pointer to the child of type $a$ of [[nodePtr]].
705  PQNode<T, whaInfo*, Y> *aChild = nullptr;
706 
707  // pertinent sibling of hChild1
708  PQNode<T, whaInfo*, Y> *hChild2Sib = nullptr;
709 
710  while (!archiv.empty())
711  {
712  //counts the number of children of [[nodePtr]].
713  int childCount = 0;
714 
715  //a pointer to a pertinent node of the $PQ$-tree that is currently examined.
716  PQNode<T, whaInfo*, Y> *nodePtr = archiv.pop();
717 
718  /*
719  Check if [[nodePtr]] is a full node whose delete type is either of
720  type $h$ or type $a$. Since there are no empty leaves in its
721  frontier, the node must therefore keep all its pertinent leaves
722  in its frontier and is depicted to be of type $b$.
723  */
724  if (nodePtr->status() == PQNodeRoot::PQNodeStatus::Full &&
725  (nodePtr->getNodeInfo()->userStructInfo()->m_deleteType == whaType::H ||
727  {
729  this->m_pertinentNodes->pushFront(nodePtr);
730  }
731 
732  /*
733  Check if [[nodePtr]] is a leaf whose delete type is either of type $w$ or
734  $b$. In case it is of type $w$, the leaf has to be removed from the
735  tree to gain reducibility of the set $S$.
736  */
737  else if (nodePtr->type() == PQNodeRoot::PQNodeType::Leaf)
738  {
739  if (nodePtr->getNodeInfo()->userStructInfo()->m_deleteType == whaType::W)
740  eliminatedKeys.pushBack(nodePtr->getKey());
741  else
742  this->m_pertinentNodes->pushFront(nodePtr);
743  }
744 
745  /*
746  Manage the case of [[nodePtr]] being either a partial $P$-node, a partial
747  $Q$-node, or a full $P$- or $Q$-node, where in the latter case the
748  delete type of [[nodePtr]] is of type $b$.
749  */
750  else
751  switch (nodePtr->getNodeInfo()->userStructInfo()->m_deleteType)
752  {
753  case whaType::B:
754  this->m_pertinentNodes->pushFront(nodePtr);
755  break;
756 
757  case whaType::W:
759  nodePtr->pertChildCount(0);
760  this->m_pertinentNodes->pushFront(nodePtr);
761  break;
762 
763  case whaType::H:
764  if (nodePtr->type() == PQNodeRoot::PQNodeType::PNode)
765  {
766  /*
767  [[nodePtr]] is a $P$-node of type $h$. Mark all full
768  children of [[nodePtr]] to be of type $b$ (by doing nothing, since
769  the default is type $b$). It furthermore marks all partial children to
770  be of type $w$ except for the child stored in [[hChild1]] of the
771  information class of type [[whaInfo*]] of [[nodePtr]]. This child is
772  marked to be of type $h$.
773  */
776  if (nodePtr->getNodeInfo()->userStructInfo()->m_hChild1)
777  {
778  hChild1 = (PQNode<T, whaInfo*, Y>*)
779  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1;
781  if (hChild1->getNodeInfo()->userStructInfo()->m_h <
782  hChild1->getNodeInfo()->userStructInfo()->m_w)
783  childCount = 1;
784  }
785  nodePtr->pertChildCount(nodePtr->pertChildCount() +
786  childCount - partialChildren(nodePtr)->size());
787  }
788  else
789  {
790  /*
791  [[nodePtr]] is a $Q$-node. Mark all pertinent children
792  to be of type $w$, except for the full children between the
793  [[hChild1]] and the endmost child of [[nodePtr]]. These full
794  children are marked $b$ while [[hChild1]] is marked to be of type
795  $h$. Setting the type of children to $b$ or $h$ is hidden in the
796  function call [[setHchild]] \label{setHChild}.
797  */
799  hChild1 = (PQNode<T, whaInfo*, Y>*)
800  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1;
801  nodePtr->pertChildCount(setHchild(hChild1));
802  }
803  this->m_pertinentNodes->pushFront(nodePtr);
804  break;
805 
806  case whaType::A:
807  if (nodePtr->type() == PQNodeRoot::PQNodeType::PNode)
808  {
809  /*
810  [[nodePtr]] is a $P$-node of type $a$.
811  Distinguish two main cases, based on the existence of a
812  child of [[nodePtr]] stored in [[aChild]] of the information
813  class of type [[_whaInfo]] of [[nodePtr]].
814  \begin{enumerate}
815  \item
816  If [[aChild]] is not empty, the chunk marks all full
817  and partial children of [[nodePtr]] to be of type $w$ and
818  marks the child [[aChild]] to be of type $a$.
819  \item
820  If [[aChild]] is empty, the chunk
821  marks all full children of [[nodePtr]] to be of type $b$
822  (by doing nothing, since the default is type $b$).
823  It furthermore marks all partial children to be of type $w$
824  except for the children stored in [[hChild1]] and
825  [[hChild2]] of the information class of type [[whaInfo*]] of
826  [[nodePtr]] which are marked to be of type $h$. Observe that
827  we have to distinguish the cases where both, [[_hChild]] and
828  [[hChild2]] are available, just [[_h_Child1]] is available or
829  none of the nodes exist.
830  \end{enumerate}
831  */
832  if (nodePtr->getNodeInfo()->userStructInfo()->m_aChild)
833  {
835  aChild = (PQNode<T, whaInfo*, Y>*)
836  nodePtr->getNodeInfo()->userStructInfo()->m_aChild;
838  nodePtr->pertChildCount(1);
839  }
840  else
841  {
844  if (nodePtr->getNodeInfo()->userStructInfo()->m_hChild1)
845  {
846  hChild1 = (PQNode<T, whaInfo*, Y>*)
847  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1;
849  if (hChild1->getNodeInfo()->userStructInfo()->m_h <
850  hChild1->getNodeInfo()->userStructInfo()->m_w)
851  childCount = 1;
852  }
853  if (nodePtr->getNodeInfo()->userStructInfo()->m_hChild2)
854  {
855  hChild2 = (PQNode<T, whaInfo*, Y>*)
856  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2;
858  if (hChild2->getNodeInfo()->userStructInfo()->m_h <
859  hChild2->getNodeInfo()->userStructInfo()->m_w)
860  childCount++;
861  }
862  nodePtr->pertChildCount(nodePtr->pertChildCount() + childCount -
863  partialChildren(nodePtr)->size());
864  }
865  }
866  else
867  {
868  /*
869  [[nodePtr]] is a $Q$-node of type $a$.
870  Distinguish two main cases, based on the existence of a child of
871  [[nodePtr]] stored in [[aChild]] of the information class of type
872  [[_whaInfo]] of [[nodePtr]].
873  \begin{enumerate}
874  \item
875  If [[aChild]] is not empty, the chunk marks all full
876  and partial children of [[nodePtr]] to be of type $w$ and marks the
877  child [[aChild]] to be of type $a$.
878  \item
879  If [[aChild]] is empty, the chunk
880  marks all full and partial children of [[nodePtr]] to be of type $w$
881  except for the ones in the largest consecutive sequence of pertinent
882  children. This sequence
883  is depicted by the children [[hChild1]] and [[hChild2]] which may be
884  either full or partial. The children between [[hChild1]] and
885  [[hChild2]] are full and are marked $b$, while [[hChild1]] and
886  [[hChild2]] are marked $b$ or $h$, according to their status.
887  Setting the type of the nodes is hidden in calling the function
888  [[setAchildren]] (see \ref{setAchildren}).
889  \end{enumerate}
890  */
891  if (nodePtr->getNodeInfo()->userStructInfo()->m_aChild)
892  {
893  aChild = (PQNode<T, whaInfo*, Y>*)
894  nodePtr->getNodeInfo()->userStructInfo()->m_aChild;
897  nodePtr->pertChildCount(1);
898  }
899  else
900  {
902  hChild2 = (PQNode<T, whaInfo*, Y>*)
903  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2;
904  hChild2Sib = (PQNode<T, whaInfo*, Y>*)
905  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2Sib;
906  nodePtr->pertChildCount(setAchildren(hChild2, hChild2Sib));
907  }
908  }
909  this->m_pertinentNodes->pushFront(nodePtr);
910  break;
911  }
912 
913  /*
914  After successfully determining the type of the children of [[nodePtr]],
915  this chunk cleans up the information needed during the
916  computation at the [[nodePtr]].
917  */
918  fullChildren(nodePtr)->clear();
919  partialChildren(nodePtr)->clear();
921  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1 = nullptr;
922  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2 = nullptr;
923  nodePtr->getNodeInfo()->userStructInfo()->m_aChild = nullptr;
924  nodePtr->getNodeInfo()->userStructInfo()->m_w = 0;
925  nodePtr->getNodeInfo()->userStructInfo()->m_h = 0;
926  nodePtr->getNodeInfo()->userStructInfo()->m_a = 0;
928  }
929 }
930 
931 template<class T, class Y>
933 {
934  // counts the number of pertinent children corresponding to the $[w,h,a]$-numbering.
935  int pertinentChildCount = 0;
936 
937  // is [[true]] as long as children with a full label are found, [[false]] otherwise.
938  bool fullLabel = false;
939 
940  PQNode<T,whaInfo*,Y> *currentNode = hChild1; // dummy
941  PQNode<T,whaInfo*,Y> *nextSibling = nullptr; // dummy
942  PQNode<T,whaInfo*,Y> *oldSibling = nullptr; // dummy
943 
944  if (hChild1 != nullptr)
945  fullLabel = true;
946 
947  /*
948  Trace the sequence of full children with at most one incident
949  pertinent child. It marks all full nodes as $b$-node and the partial
950  child, if available as $h$-child. The beginning of the sequence is
951  stored in [[currentNode]] which is equal to [[h_child1]] before
952  entering the while loop. Observe that this chunk cases if the while
953  loop while scanning the sequence has reached the second endmost child
954  of the $Q$-node (see [[if (nextSibling == 0)]]). This case may
955  appear, if all children of the $Q$-node are pertinent and the second
956  endmost child is the only partial child. The value [[fullLabel]] is
957  set to [[false]] as soon as the end of the sequence is detected.
958  */
959  while (fullLabel)
960  {
961  nextSibling = currentNode->getNextSib(oldSibling);
962  if (!nextSibling)
963  fullLabel = false;
964 
965  if (currentNode->status() == PQNodeRoot::PQNodeStatus::Full)
966  {
967  currentNode->getNodeInfo()->userStructInfo()->m_deleteType = whaType::B;
968  pertinentChildCount++;
969  }
970 
971  else
972  {
973  if (currentNode->status() == PQNodeRoot::PQNodeStatus::Partial)
974  {
975  currentNode->getNodeInfo()->userStructInfo()->m_deleteType = whaType::H;
976  if ((currentNode->getNodeInfo()->userStructInfo()->m_pertLeafCount -
977  currentNode->getNodeInfo()->userStructInfo()->m_h) > 0)
978  pertinentChildCount++;
979  }
980  fullLabel = false;
981  }
982  oldSibling = currentNode;
983  currentNode = nextSibling;
984  }
985 
986  return pertinentChildCount;
987 }
988 
989 template<class T, class Y>
991  PQNode<T, whaInfo*, Y> *hChild2,
992  PQNode<T, whaInfo*, Y> *hChild2Sib)
993 {
994  /* Variables:
995  * - \a pertinentChildCount
996  * - \a reachedEnd
997  * - \a _sum denotes the number of pertinent leaves in the frontier
998  * of the sequence.
999  * - \a currentNode is the currently examined node of the sequence.
1000  * - \a nextSibling is a pointer needed for tracing the sequence.
1001  * - \a oldSibling is a pointer needed for tracing the sequence.
1002  */
1003  // counts the pertinent children of the sequence.
1004  int pertinentChildCount = 0;
1005 
1006  PQNode<T,whaInfo*,Y> *currentNode = hChild2; // dummy
1007  PQNode<T,whaInfo*,Y> *nextSibling = nullptr; // dummy
1008  PQNode<T,whaInfo*,Y> *oldSibling = nullptr; // dummy
1009 
1010  //Mark [[hChild2]] either as $b$- or as $h$-node.
1011  if (hChild2->status() == PQNodeRoot::PQNodeStatus::Full)
1013  else {
1014  //1. node of sequence is Empty?
1017  }
1018 
1019  if (currentNode->getNodeInfo()->userStructInfo()->m_w -
1020  currentNode->getNodeInfo()->userStructInfo()->m_h > 0)
1021  pertinentChildCount++;
1022 
1023  //Trace the sequence of pertinent children, marking the full children as $b$-node.
1024  //If a partial or empty node is detected, the end of the sequence is
1025  //reached and the partial node is marked as $h$-node.
1026  nextSibling = hChild2Sib;
1027  oldSibling = hChild2;
1028 
1029  if (nextSibling != nullptr)
1030  {
1031  currentNode = nextSibling;
1032 
1033  // is false]as long as the end of the sequence is not detected; true otherwise.
1034  bool reachedEnd = false;
1035 
1036  while(!reachedEnd)
1037  {
1038  if (currentNode->status() == PQNodeRoot::PQNodeStatus::Full)
1039  {
1040  currentNode->getNodeInfo()->userStructInfo()->m_deleteType = whaType::B;
1041  pertinentChildCount++;
1042  }
1043  else
1044  {
1045  if (currentNode->status() == PQNodeRoot::PQNodeStatus::Partial)
1046  {
1047  currentNode->getNodeInfo()->userStructInfo()->m_deleteType = whaType::H;
1048  if ((currentNode->getNodeInfo()->userStructInfo()->m_w -
1049  currentNode->getNodeInfo()->userStructInfo()->m_h) > 0)
1050  pertinentChildCount++;
1051  }
1052  reachedEnd = true;
1053  }
1054  if (!reachedEnd)
1055  {
1056  nextSibling = currentNode->getNextSib(oldSibling);
1057  if (nextSibling == nullptr)
1058  reachedEnd = true;
1059  oldSibling = currentNode;
1060  currentNode = nextSibling;
1061  }
1062  }
1063  }
1064 
1065  return pertinentChildCount;
1066 }
1067 
1068 template<class T,class Y>
1070  PQNode<T,whaInfo*,Y> *nodePtr,
1072  whaType deleteType)
1073 {
1078 #if 0
1079  PQNode<T,whaInfo*,Y> *currentNode = 0;
1080 #endif
1081 
1083  {
1085  for (it = partialChildren(nodePtr)->begin(); it.valid(); ++it)
1086  (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1087  for (it = fullChildren(nodePtr)->begin(); it.valid(); ++it)
1088  (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1089  }
1090  else if (label == PQNodeRoot::PQNodeStatus::Partial)
1091  {
1093  for (it = partialChildren(nodePtr)->begin(); it.valid(); ++it)
1094  (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1095  }
1096 
1097  else
1098  {
1100  for (it = fullChildren(nodePtr)->begin(); it.valid(); ++it)
1101  (*it)->getNodeInfo()->userStructInfo()->m_deleteType = deleteType;
1102  }
1103 }
1104 
1105 template<class T, class Y>
1107 {
1108  /* Variables:
1109  * - \a sumParW = sum_{i in Par(\p nodePtr)} w_i, where
1110  * Par(\p nodePtr) denotes the set of partial children of \p nodePtr.
1111  * - \a sumMax1 = max_{i in Par(\p nodePtr)}1 {(w_i - h_i)}
1112  * where Par(\p nodePtr) denotes the set of partial children of
1113  * - \p nodePtr and max 1 the first maximum.
1114  * - \a sumMax2 = max_{i in Par(\p nodePtr)}2 {(w_i - h_i)}
1115  * where Par(\p nodePtr) denotes the set of partial children of
1116  * \p nodePtr and max2 the second maximum.
1117  * - \a currentNode
1118  * - \a hChild1 is a pointer to the \a hChild1 of \p nodePtr.
1119  * - \a hChild2 is a pointer to the \a hChild2 of \p nodePtr.
1120  * - \a aChild is a pointer to the \a aChild of \p nodePtr.
1121  */
1122  int sumParW = 0;
1123  int sumMax1 = 0;
1124  int sumMax2 = 0;
1125  PQNode<T,whaInfo*,Y> *currentNode = nullptr;
1126  PQNode<T,whaInfo*,Y> *hChild1 = nullptr;
1127  PQNode<T,whaInfo*,Y> *hChild2 = nullptr;
1128  PQNode<T,whaInfo*,Y> *aChild = nullptr;
1129 
1130  /*
1131  Computes the $h$-number
1132  \[ h = \sum_{i \in Par(\mbox{[[nodePtr]]})}w_i - \max_{i\in
1133  Par(\mbox{[[nodePtr]]})}1\left\{(w_i - h_i)\right\}\]
1134  of the $P$-node [[nodePtr]].
1135  This is done by scanning all partial children stored in the
1136  [[partialChildrenStack]] of [[nodePtr]] summing up the $w_i$ for every
1137  $i \in Par(\mbox{[[nodePtr]]})$ and detecting
1138  \[\max_{i\in Par(\mbox{[[nodePtr]]})}1\left\{(w_i - h_i)\right\}.\]
1139  Since this can be simultaneously it also computes
1140  \[\max_{i\in Par(\mbox{[[nodePtr]]})}2\left\{(w_i - h_i)\right\}\]
1141  which is needed to determine the $a$-number.
1142  After successfully determining the $h$-number, the [[hChild1]] and
1143  [[hChild2]] of [[nodePtr]] are set.
1144  */
1145 
1147  for (it = partialChildren(nodePtr)->begin(); it.valid(); ++it)
1148  {
1149  currentNode = (*it);
1150  sumParW = sumParW + currentNode->getNodeInfo()->userStructInfo()->m_w;
1151  int sumHelp = currentNode->getNodeInfo()->userStructInfo()->m_w -
1152  currentNode->getNodeInfo()->userStructInfo()->m_h;
1153  if (sumMax1 <= sumHelp)
1154  {
1155  sumMax2 = sumMax1;
1156  hChild2 = hChild1;
1157  sumMax1 = sumHelp;
1158  hChild1 = currentNode;
1159  }
1160  else if (sumMax2 <= sumHelp)
1161  {
1162  sumMax2 = sumHelp;
1163  hChild2 = currentNode;
1164  }
1165  }
1166  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1 = hChild1;
1167  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2 = hChild2;
1168  nodePtr->getNodeInfo()->userStructInfo()->m_h = sumParW - sumMax1;
1169 
1170  /*
1171  Compute the $a$-number of the $P$-node [[nodePtr]] where
1172  \[ a = \min \{ \alpha_1, \alpha_2\}\]
1173  such that
1174  \[\alpha_1 = \sum_{i \in P(\mbox{[[nodePtr]]})}w_i - \max_{i\in
1175  P(\mbox{[[nodePtr]]})}\left\{(w_i - h_i)\right\} \]
1176  which can be computed calling the function [[alpha1beta1Number]] and
1177  \[{\alpha}_2 \sum_{i \in Par(\mbox{[[nodePtr]]})}w_i -
1178  \max_{i\in Par(\mbox{[[nodePtr]]})}1\left\{(w_i - h_i)\right\}
1179  - \max_{i\in Par(\mbox{[[nodePtr]]})}2\left\{(w_i - h_i)\right\}\]
1180  This chunk uses two extra variables
1181  \begin{description}
1182  \item[[alpha1]] $ = \alpha_1$.
1183  \item[[alpha2]] $ = \alpha_2$.
1184  \end{description}
1185  */
1186  int alpha2 = sumParW - sumMax1 - sumMax2;
1187  int alpha1 = alpha1beta1Number(nodePtr,&aChild);
1188 
1189  if (alpha1 <= alpha2)
1190  {
1191  nodePtr->getNodeInfo()->userStructInfo()->m_a = alpha1;
1192  nodePtr->getNodeInfo()->userStructInfo()->m_aChild = aChild;
1193  }
1194  else
1195  {
1196  nodePtr->getNodeInfo()->userStructInfo()->m_a = alpha2;
1197  nodePtr->getNodeInfo()->userStructInfo()->m_aChild = nullptr;
1198  }
1199 }
1200 
1201 template<class T,class Y>
1203 {
1204  /* Variables:
1205  * - sumAllW = sum_{i in P(\p nodePtr)} w_i, where
1206  * P(\p nodePtr) denotes the set of pertinent children of \p nodePtr.
1207  */
1208  int sumAllW = sumPertChild(nodePtr);
1209 
1210  hNumQnode(nodePtr,sumAllW);
1211  aNumQnode(nodePtr,sumAllW);
1212 }
1213 
1214 template<class T,class Y>
1216  PQNode<T,whaInfo*,Y> *nodePtr,
1217  int sumAllW)
1218 {
1219  /* Variables:
1220  * - \a sumLeft = sum_{i in P(\p nodePtr)} w_i - sum_{i
1221  * in P_L(\p nodePtr)}(w_i - h_i), where
1222  * P_L(\p nodePtr) denotes the maximal consecutive sequence
1223  * of pertinent children on the left side of the Q-node
1224  * \p nodePtr such that only the rightmost node in
1225  * P_L(\p nodePtr) may be partial.
1226  * - \a sumRight = sum_{i in P(\p [nodePtr)}w_i - sum_{i
1227  * in P_L(\p nodePtr)}(w_i - h_i), where
1228  * P_L(\p nodePtr) denotes the maximal consecutive sequence
1229  * of pertinent children on the left side of the Q-node
1230  * \p nodePtr such that only the rightmost node in
1231  * P_L(\p nodePtr) may be partial.
1232  * - \a fullLabel
1233  * - \a aChild is a pointer to the a-child of \p nodePtr.
1234  * - \a leftChild is a pointer to the left endmost child of \p nodePtr.
1235  * - \a rightChild is a pointer to the right endmost child of \p nodePtr.
1236  * - \a holdSibling is a pointer to a child of \p nodePtr, needed
1237  * to proceed through sequences of pertinent children.
1238  * - \a checkSibling is a pointer to a currently examined child of \p nodePtr.
1239  */
1240  int sumLeft = 0;
1241  int sumRight = 0;
1242  bool fullLabel = true;
1243  PQNode<T,whaInfo*,Y> *leftChild = nullptr;
1244  PQNode<T,whaInfo*,Y> *rightChild = nullptr;
1245  PQNode<T,whaInfo*,Y> *holdSibling = nullptr;
1246  PQNode<T,whaInfo*,Y> *checkSibling = nullptr;
1247 
1248  //Compute the $h$-number of the $Q$-node [[nodePtr]]
1249 
1250  //Get endmost children of the $Q$-node [[nodePtr]].
1251  leftChild = nodePtr->getEndmost(0);
1252  rightChild = nodePtr->getEndmost(leftChild);
1253  OGDF_ASSERT(leftChild);
1254  OGDF_ASSERT(rightChild);
1255 
1256  /*
1257  Check the left
1258  side of the $Q$-node [[nodePtr]] for the maximal consecutive sequence
1259  of full nodes, including at most one partial child at the end of the sequence.
1260 
1261  The variable [[fullLabel]] is [[true]] as long as the [[while]]-loop
1262  has not detected an partial <b>or</b> empty child (see case [[if
1263  (leftChild->status() != Full)]]. Observe that the
1264  construction of the [[while]]-loop examines the last child if it is a
1265  partial child as well (see case [[if (leftChild->status() !=
1266  Empty)]] where in the computation in [[sumLeft]] we take advantage
1267  of the fact, that the $h$-number of a full child is zero).
1268  */
1269  while (fullLabel)
1270  {
1271  if (leftChild->status() != PQNodeRoot::PQNodeStatus::Full)
1272  fullLabel = false;
1273  if (leftChild->status() != PQNodeRoot::PQNodeStatus::Empty)
1274  {
1275  sumLeft = sumLeft +
1276  leftChild->getNodeInfo()->userStructInfo()->m_w -
1277  leftChild->getNodeInfo()->userStructInfo()->m_h;
1278  checkSibling = leftChild->getNextSib(holdSibling);
1279  if (checkSibling == nullptr)
1280  fullLabel = false;
1281  holdSibling = leftChild;
1282  leftChild = checkSibling;
1283  }
1284  }
1285 
1286  /*
1287  Check the right
1288  side of the $Q$-node [[nodePtr]] for the maximal consecutive sequence
1289  of full nodes, including at most one partial child at the end of the sequence.
1290 
1291  The variable [[fullLabel]] is [[true]] as long as the [[while]]-loop
1292  has not detected an partial <b>or</b> empty child (see case [[if
1293  (leftChild->status() != Full)]]. Observe that the
1294  construction of the [[while]]-loop examines the last child if it is a
1295  partial child as well (see case [[if (leftChild->status() !=
1296  Empty)]] where in the computation in [[sumLeft]] we take advantage
1297  of the fact, that the $h$-number of a full child is zero).
1298  */
1299  holdSibling = nullptr;
1300  checkSibling = nullptr;
1301  fullLabel = true;
1302  while (fullLabel)
1303  {
1304  if (rightChild->status() != PQNodeRoot::PQNodeStatus::Full)
1305  fullLabel = false;
1306  if (rightChild->status() != PQNodeRoot::PQNodeStatus::Empty)
1307  {
1308  sumRight = sumRight +
1309  rightChild->getNodeInfo()->userStructInfo()->m_w -
1310  rightChild->getNodeInfo()->userStructInfo()->m_h;
1311 
1312  checkSibling = rightChild->getNextSib(holdSibling);
1313 
1314  if (checkSibling == nullptr)
1315  fullLabel = false;
1316 
1317  holdSibling = rightChild;
1318  rightChild = checkSibling;
1319  }
1320  }
1321 
1322  /*
1323  After computing the number of pertinent leaves that stay in the $PQ$-tree
1324  when keeping either the left pertinent or the right pertinent side of
1325  the $Q$-node in the tree, this chunk chooses the side where the
1326  maximum number of leaves stay in the tree.
1327  Observe that we have to case the fact, that on both sides of the
1328  $Q$-node [[nodePtr]] no pertinent children are.
1329  */
1330  leftChild = nodePtr->getEndmost(0);
1331  rightChild = nodePtr->getEndmost(leftChild);
1332  if (sumLeft == 0 && sumRight == 0)
1333  {
1334  nodePtr->getNodeInfo()->userStructInfo()->m_h = sumAllW;
1335  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1 = nullptr;
1336  }
1337  else if (sumLeft < sumRight)
1338  {
1339  nodePtr->getNodeInfo()->userStructInfo()->m_h = sumAllW - sumRight;
1340  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1 = rightChild;
1341  }
1342  else
1343  {
1344  nodePtr->getNodeInfo()->userStructInfo()->m_h = sumAllW - sumLeft;
1345  nodePtr->getNodeInfo()->userStructInfo()->m_hChild1 = leftChild;
1346  }
1347 }
1348 
1349 template<class T,class Y>
1351  PQNode<T,whaInfo*,Y> *nodePtr,
1352  int sumAllW)
1353 {
1354  /* Variables:
1355  * - \a beta1 = sum_{i in P(\p nodePtr} w_i - max_{i in P(\p nodePtr)}{(w_i =
1356  * a_i)}, where $P(\p nodePtr) denotes the set of all pertinent
1357  * children of the Q-node \p nodePtr. Depicts the a-number if just one
1358  * child of \p nodePtr is made a-node. Computed by calling the function alpha1beta1Number().
1359  * - \a beta2 = sum_{i in P(\p nodePtr)} w_i - max_{P_A(\p nodePtr)}{sum_{i in
1360  * P_A(\p nodePtr)}(w_i-h_i)}, where $P_A(\p nodePtr) is a maximal consecutive
1361  * sequence of pertinent children of the Q-node \p nodePtr such that all
1362  * nodes in P_A(\p nodePtr) except for the leftmost and rightmost ones are
1363  * full. Computed by this chunk.
1364  * - \a aSum depicts the number of pertinent leaves of the actual visited sequence.
1365  * - \a aHoldSum depicts the number of leaves in the actual maximum sequence.
1366  * - \a endReached is true if reached the end of the Q-node \p nodePtr and false otherwise.
1367  * - \a leftMost pointer to the leftmost end of the actual visited sequence.
1368  * - \a leftMostHold pointer to the leftmost end of the current maximum sequence.
1369  * - \a actualNode pointer to a child of the Q-node. It is the
1370  * node that is actually processed in the sequence of children.
1371  * - \a currentNode pointer to a node in a consecutive pertinent
1372  * sequence. Needed to process all nodes stored in \a sequence.
1373  * - \a lastChild is a pointer to the endmost child of the Q-node
1374  * that is opposite to the endmost child, where this chunk starts
1375  * processing the sequence of children.
1376  * - \a sequence is a SList of type PQNode<T,whaInfo*,Y>* storing
1377  * the nodes of a consecutive sequence that is actually processed.
1378  */
1379  PQNode<T,whaInfo*,Y> *aChild = nullptr;
1380  int beta1 = alpha1beta1Number(nodePtr,&aChild);
1381  int beta2 = 0;
1382  int aSum = 0;
1383  int aHoldSum = 0;
1384  bool endReached = 0;
1385  PQNode<T,whaInfo*,Y> *leftMost = nullptr;
1386  PQNode<T,whaInfo*,Y> *leftSib = nullptr;
1387  PQNode<T,whaInfo*,Y> *leftMostHold = nullptr;
1388  PQNode<T,whaInfo*,Y> *leftSibHold = nullptr;
1389  PQNode<T,whaInfo*,Y> *actualNode = nullptr;
1390  PQNode<T,whaInfo*,Y> *currentNode = nullptr;
1391  PQNode<T,whaInfo*,Y> *lastChild = nullptr;
1392  PQNode<T,whaInfo*,Y> *holdSibling = nullptr;
1393  PQNode<T,whaInfo*,Y> *checkSibling = nullptr;
1394  // pointer to the second endmost child
1395 
1396  SList<PQNode<T,whaInfo*,Y>*> sequence;
1397 
1398  actualNode = nodePtr->getEndmost(0);
1399  lastChild = nodePtr->getEndmost(actualNode);
1400 
1401  endReached = false;
1402  while (!endReached)
1403  {
1404  /*
1405  Process the children of a $Q$-node [[nodePtr]] from one end of [[nodePtr]] to the
1406  other, searching for a consecutive sequence of pertinent nodes with
1407  the maximum number of pertinent leaves, such that all nodes of the
1408  pertinent sequence are full except possibly the two endmost children
1409  which are allowed to be partial.
1410  */
1411  if (sequence.empty())
1412  {
1413  /*
1414  Currently no consecutive sequence of pertinent children
1415  is detected while scanning the children of the $Q$-node.
1416  Check the [[actualNode]] if it is the first child of
1417  such a sequence. If so, place [[actualNode]] on the stack [[sequence]].
1418  */
1419  if (actualNode->status() != PQNodeRoot::PQNodeStatus::Empty)
1420  {
1421  sequence.pushFront(actualNode);
1422  leftMost = nullptr;
1423  leftSib = nullptr;
1424  }
1425  }
1426  else
1427  {
1428  /*
1429  [[actualNode]] is a sibling of a consecutive pertinent sequence that has
1430  been detected in an earlier step, while scanning the children of the $Q$-node.
1431  This chunk cases on the status of the [[actualNode]].
1432 
1433  In case that the status of
1434  the [[actualNode]] is [[Full]], [[actualNode]] is included into the
1435  sequence of pertinent children by pushing it onto the stack
1436  [[sequence]].
1437 
1438  If [[actualNode]] is Empty, we have reached the end of
1439  the actual consecutive sequence of pertinent children. In this case
1440  the $a$-numbers of the nodes in the sequence have to be summed up.
1441 
1442  If the [[actualNode]] is [[Partial]], the end of the consecutive sequence
1443  is reached and similar actions to the [[Empty]] have to be
1444  performed. However, [[actualNode]] might mark the beginning of
1445  another pertinent sequence. Hence it has to be stored again in [[sequence]].
1446  */
1447  if (actualNode->status() == PQNodeRoot::PQNodeStatus::Full)
1448  sequence.pushFront(actualNode);
1449 
1450  else if (actualNode->status() == PQNodeRoot::PQNodeStatus::Empty)
1451  {
1452  /*
1453  If [[actualNode]] is Empty, the end of
1454  the actual consecutive sequence of pertinent children is reached . In
1455  this case, all nodes of the currently examined consecutive sequence are stored in
1456  [[sequence]].
1457  They are removed from the stack and their $a$-numbers are summed up.
1458  If necessary, the sequence with the largest number of full leaves in
1459  its frontier is updated.
1460  */
1461  aSum = 0;
1462 
1463  while (!sequence.empty())
1464  {
1465  currentNode = sequence.popFrontRet();
1466  aSum = aSum + currentNode->getNodeInfo()->userStructInfo()->m_w
1467  - currentNode->getNodeInfo()->userStructInfo()->m_h;
1468  if (sequence.size() == 1)
1469  leftSib = currentNode;
1470  }
1471  leftMost = currentNode;
1472 
1473  if (aHoldSum < aSum)
1474  {
1475  aHoldSum = aSum;
1476  leftMostHold = leftMost;
1477  leftSibHold = leftSib;
1478  }
1479 
1480  }
1481  else
1482  {
1483  /*
1484  If the [[actualNode]] is [[Partial]], the end of the consecutive sequence
1485  is reached. In
1486  this case, all nodes of the currently examined consecutive sequence are stored in
1487  [[sequence]].
1488  They are removed from the stack and their $a$-numbers are summed up.
1489  If necessary, the sequence with the largest number of full leaves in
1490  its frontier is updated.
1491  However, [[actualNode]] might mark the beginning of
1492  another pertinent sequence. Hence it has to be stored again in [[sequence]].
1493  */
1494  sequence.pushFront(actualNode);
1495  aSum = 0;
1496  while (!sequence.empty())
1497  {
1498  currentNode = sequence.popFrontRet();
1499  aSum = aSum + currentNode->getNodeInfo()->userStructInfo()->m_w -
1500  currentNode->getNodeInfo()->userStructInfo()->m_h;
1501  if (sequence.size() == 1)
1502  leftSib = currentNode;
1503  }
1504  if (leftSib == nullptr)
1505  leftSib = actualNode;
1506  leftMost = currentNode;
1507 
1508  if (aHoldSum < aSum)
1509  {
1510  aHoldSum = aSum;
1511  leftMostHold = leftMost;
1512  leftSibHold = leftSib;
1513  }
1514 
1515  sequence.pushFront(actualNode);
1516 
1517  }
1518  }
1519 
1520  // Get the next sibling
1521  if (actualNode != lastChild)
1522  {
1523  checkSibling = actualNode->getNextSib(holdSibling);
1524  holdSibling = actualNode;
1525  actualNode = checkSibling;
1526  }
1527  else
1528  // End of Q-node reached.
1529  endReached = true;
1530  }
1531 
1532 
1533  /*
1534  After processing
1535  the last child of the $Q$-node, this chunk checks, if this child was
1536  part of a pertinent consecutive sequence. If this is the case, the
1537  stack storing this seuquence was not emptied and the number of
1538  pertinent leaves in its frontier was not computed. Furhtermore the
1539  last child was not stored in [[sequence]].
1540  This chunk does the necessary updates for the last consecutive sequence.
1541  */
1542  if (!sequence.empty())
1543  {
1544  aSum = 0;
1545  while (!sequence.empty())
1546  {
1547  currentNode = sequence.popFrontRet();
1548  aSum = aSum + currentNode->getNodeInfo()->userStructInfo()->m_w -
1549  currentNode->getNodeInfo()->userStructInfo()->m_h;
1550  if (sequence.size() == 1)
1551  leftSib = currentNode;
1552  }
1553  leftMost = currentNode;
1554 
1555  if (aHoldSum < aSum)
1556  {
1557  aHoldSum = aSum;
1558  leftMostHold = leftMost;
1559  leftSibHold = leftSib;
1560  }
1561  }
1562  /*
1563  After computing
1564  ${\beta}_1$ and ${\beta}_2$, describing the number of pertinent leaves
1565  that have to be deleted when choosing either one node to be an
1566  $a$-node or a complete sequence, this chunk gets the $a$-number of the
1567  $Q$-node [[nodePtr]] by choosing
1568  \[a = \min\{{\beta}_1,{\beta}_2\]
1569  Also set [[aChild]] and [[hChild2]] of [[nodePtr]] according to the
1570  chosen minimum.
1571  */
1572  beta2 = sumAllW - aHoldSum;
1573  if (beta2 < beta1)
1574  {
1575  nodePtr->getNodeInfo()->userStructInfo()->m_a = beta2;
1576  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2 = leftMostHold;
1577  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2Sib = leftSibHold;
1578  nodePtr->getNodeInfo()->userStructInfo()->m_aChild = nullptr;
1579  }
1580  else
1581  {
1582  nodePtr->getNodeInfo()->userStructInfo()->m_a = beta1;
1583  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2 = nullptr;
1584  nodePtr->getNodeInfo()->userStructInfo()->m_hChild2Sib = nullptr;
1585  nodePtr->getNodeInfo()->userStructInfo()->m_aChild = aChild;
1586  }
1587 }
1588 
1589 template<class T, class Y>
1591  PQNode<T, whaInfo*, Y> *nodePtr,
1592  PQNode<T, whaInfo*, Y> **aChild)
1593 {
1594  /* Variables:
1595  * - \a sumMaxA = max_{i in P(\p nodePtr)}{(w_i = a_i)}.
1596  * - \a sumAllW = w = sum_{i in P(\p nodePtr)}w_i.
1597  * - \a sumHelp is a help variable.
1598  * - \a currentNode depicts a currently examined pertinent node.
1599  *
1600  * The function uses two while loops over the parial and the full
1601  * children of \p nodePtr. It hereby computes the values \p w and
1602  * max_{i in P(\p nodePtr}{(w_i = a_i)}.
1603  * After finishing the while loops, the function
1604  * alpha1beta1Number() returns the numbers alpha_1 = beta_1
1605  * and the \p aChild.
1606  */
1607  int sumMaxA = 0;
1608  int sumAllW = 0;
1609  int sumHelp = 0;
1610  PQNode<T,whaInfo*,Y> *currentNode = nullptr;
1611 
1613  for (it = fullChildren(nodePtr)->begin(); it.valid(); ++it)
1614  {
1615  currentNode = (*it);
1616  sumAllW = sumAllW +
1617  currentNode->getNodeInfo()->userStructInfo()->m_w;
1618  sumHelp = currentNode->getNodeInfo()->userStructInfo()->m_w
1619  - currentNode->getNodeInfo()->userStructInfo()->m_a;
1620  if (sumMaxA < sumHelp)
1621  {
1622  sumMaxA = sumHelp;
1623  (*aChild) = currentNode;
1624  }
1625  }
1626 
1627  for (it = partialChildren(nodePtr)->begin(); it.valid(); ++it)
1628  {
1629  currentNode = (*it);
1630  sumAllW = sumAllW + currentNode->getNodeInfo()->userStructInfo()->m_w;
1631  sumHelp = currentNode->getNodeInfo()->userStructInfo()->m_w - currentNode->getNodeInfo()->userStructInfo()->m_a;
1632  if (sumMaxA < sumHelp)
1633  {
1634  sumMaxA = sumHelp;
1635  (*aChild) = currentNode;
1636  }
1637  }
1638  return sumAllW - sumMaxA;
1639 }
1640 
1641 template<class T,class Y>
1643 {
1644  /* Variables:
1645  * - \a it depicts a currently examined pertinent node.
1646  * - \a sum = \a w = sum_{i in P(\p nodePtr)}w_i.
1647  *
1648  * The function uses two for loops over the parial and the full
1649  * children of \p nodePtr. It hereby computes the values $w$ stored in \a sum.
1650  * After finishing the while loops, the function
1651  * sumPertChild() returns the number \a w.
1652  */
1653  int sum = 0;
1655  for (it = fullChildren(nodePtr)->begin(); it.valid(); ++it)
1656  sum = sum + (*it)->getNodeInfo()->userStructInfo()->m_w;
1657  for (it = partialChildren(nodePtr)->begin(); it.valid(); ++it)
1658  sum = sum + (*it)->getNodeInfo()->userStructInfo()->m_w;
1659 
1660  return sum;
1661 }
1662 
1663 template<class T, class Y>
1665 {
1666  if (nodePtr->parent() == nullptr)
1667  return nullptr;
1668  else if (nodePtr->parent()->status() != PQNodeRoot::PQNodeStatus::Eliminated)
1669  return nodePtr->parent();
1670  else
1671  {
1672  PQNode<T, whaInfo*, Y> *nextNode = nodePtr;
1673  PQNode<T, whaInfo*, Y> *currentNode = nullptr;
1674  PQNode<T, whaInfo*, Y> *oldSib = nullptr;
1676 
1677  currentNode = nodePtr->getNextSib(nullptr);
1678  oldSib = nodePtr;
1679  L.pushFront(nodePtr);
1680  while (currentNode->parent()->status() == PQNodeRoot::PQNodeStatus::Eliminated)
1681  {
1682  L.pushFront(currentNode);
1683  nextNode = currentNode->getNextSib(oldSib);
1684  oldSib = currentNode;
1685  currentNode = nextNode;
1686  }
1687  while (!L.empty())
1688  L.popFrontRet()->parent(currentNode->parent());
1689  return currentNode->parent();
1690  }
1691 }
1692 
1693 }
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 pertChildCount() const
Returs the number of pertinent children of a node.
Definition: PQNode.h:233
Declaration of class whaInfo.
SListPure< PQNode< T, whaInfo *, Y > * > cleanUp
Used to store all pertinent Nodes of the pertinent subtree before removing the minimal pertinent subs...
The parameterized class Queue<E> implements list-based queues.
Definition: Queue.h:213
bool valid() const
Returns true iff the iterator points to an element.
Definition: SList.h:113
iterator append(const E &x)
Adds x at the end of queue.
Definition: Queue.h:343
bool empty() const
Returns true iff the list is empty.
Definition: SList.h:220
Nodes that need to be removed in order to obtain a maximal pertinent sequence are marked WhaDelete...
PQNodeRoot * m_aChild
Definition: whaInfo.h:115
int size() const
Returns the number of elements in the list.
Definition: SList.h:815
Singly linked lists.
Definition: SList.h:38
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.
Nodes removed during the template reduction are marked as as Eliminated. Their memory is not freed...
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 clientDefinedEmptyNode(PQNode< T, whaInfo *, Y > *nodePtr)
Does a clean up of a node. Called by emptyAllPertinentNodes.
Declaration and implementation of the class PQTree.
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:40
void haNumQnode(PQNode< T, whaInfo *, Y > *nodePtr)
Computes the h- and a-number of the partial Q-node nodePtr.
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...
PQNode< T, whaInfo *, Y > * m_pertinentRoot
a pointer to the root of the pertinent subtree.
Definition: PQTree.h:185
virtual PQNodeMark mark() const =0
mark() returns the variable PQLeaf::m_mark in the derived class PQLeaf and PQInternalNode.
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...
Definition: PQTree.h:1881
PQNode< T, whaInfo *, Y > * m_root
a pointer to the root of the $PQ$-tree.
Definition: PQTree.h:182
PQNode< T, whaInfo *, Y > * GetParent(PQNode< T, whaInfo *, Y > *nodePtr)
Computes for the node nodePtr its valid parent in the PQ-tree.
Singly linked lists (maintaining the length of the list).
Definition: SList.h:777
virtual PQNodeStatus status() const =0
Returns the variable PQLeaf::m_status in the derived class PQLeaf and PQInternalNode.
List< PQNode< T, whaInfo *, Y > *> * partialChildren(PQNode< T, whaInfo *, Y > *nodePtr)
Definition: PQTree.h:680
E popFrontRet()
Removes the first element from the list and returns it.
Definition: SList.h:908
void push(const E &x)
Adds element x as top-most element to the stack.
Definition: Stack.h:127
List< PQNode< T, whaInfo *, Y > *> * m_pertinentNodes
Stores all nodes that have been marked PQNodeRoot::PQNodeStatus::Full or PQNodeRoot::PQNodeStatus::Pa...
Definition: PQTree.h:208
int m_notVisitedCount
Definition: whaInfo.h:111
List-based stacks.
Definition: SList.h:39
PQNode< T, X, Y > * getNextSib(PQNode< T, X, Y > *other) const
The function getNextSib() returns one of the siblings of the node.
Definition: PQNode.h:183
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.
virtual void CleanNode(PQNode< T, whaInfo *, Y > *nodePtr)
Frees the memory allocated for the node information class of a node in the PQTree.
virtual void emptyAllPertinentNodes()
Cleans up all flags that have been set in the pertinent nodes during the reduction process...
Definition: PQTree.h:1844
bool setNodeInfo(PQNodeKey< T, X, Y > *pointerToInfo)
Sets the pointer m_pointerToInfo to the specified adress of pointerToInfo.
Definition: PQNode.h:304
bool empty() const
Returns true iff the queue is empty.
Definition: Queue.h:251
void findMinWHASequence(StackPure< PQNode< T, whaInfo *, Y > *> &archiv, SList< PQLeafKey< T, whaInfo *, Y > *> &eliminatedKeys)
Checks the [w,h,a]-number of the pertinent root.
PQNodeKey< T, X, Y > * getNodeInfo() const
Returns the identification number of a node.
Definition: PQNode.h:158
virtual X userStructInfo()
Returns m_userStructInfo.
Definition: PQNodeKey.h:72
Encapsulates a pointer to a list element.
Definition: List.h:41
whaType m_deleteType
Definition: whaInfo.h:104
The pertinent Root is marked PertRoot during the clean up after a reduction. Technical.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: SList.h:437
PQNodeRoot * m_hChild1
Definition: whaInfo.h:119
whaType
The definitions for W, B, H and A describe the type of a node during the computation of the maximal p...
Definition: whaInfo.h:49
SListIterator< E > pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: SList.h:863
void defaultValues()
Definition: whaInfo.h:75
E popFrontRet()
Removes the first element from the list and returns it.
Definition: SList.h:512
SListPure< PQNode< T, whaInfo *, Y > * > eliminatedNodes
Used to store all eliminated nodes (status == PQNodeRoot::PQNodeStatus::Eliminated) of the PQTree...
PQNode< T, X, Y > * parent() const
The function parent() returns a pointer to the parent of a node.
Definition: PQNode.h:209
The class template PQLeafKey is a derived class of class template PQBasicKey.
Definition: PQLeafKey.h:86
Includes declaration of graph class.
PQNodeRoot * m_hChild2Sib
Definition: whaInfo.h:129
int childCount() const
Returns the number of children of a node.
Definition: PQNode.h:197
List< PQNode< T, whaInfo *, Y > *> * fullChildren(PQNode< T, whaInfo *, Y > *nodePtr)
Definition: PQTree.h:675
int m_pertLeafCount
Definition: whaInfo.h:107
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.
Definition: PQNode.h:134
void setNodePointer(PQNode< T, X, Y > *pqNode)
The function setNodePointer() sets the private member m_nodePointer.
Definition: PQBasicKey.h:153
The namespace for all OGDF objects.
The class template MaxSequencePQTree is designed to compute a maximal consecutive sequence of pertine...
PQNodeRoot * m_hChild2
Definition: whaInfo.h:124
int determineMinRemoveSequence(SListPure< PQLeafKey< T, whaInfo *, Y > *> &leafKeys, SList< PQLeafKey< T, whaInfo *, Y > *> &eliminatedKeys)
Computes the maximal pertinent sequence S&#39; of elements of the set S, that can be reduced in a PQ-tree...
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)}...
E pop()
Removes front element and returns it.
Definition: Queue.h:357
void aNumQnode(PQNode< T, whaInfo *, Y > *nodePtr, int sumAllW)
Computes the a-number of the partial Q-node nodePtr.
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112
virtual bool Bubble(SListPure< PQLeafKey< T, whaInfo *, Y > *> &leafKeys)
The function Bubble() is an overloaded function of the base template class PQTree.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
virtual PQNodeType type() const =0
Returns the variable PQInternalNode::m_type in the derived class PQLeaf and PQInternalNode.
virtual void emptyAllPertinentNodes()
Does a clean up after a reduction.
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.