Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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