pq_node.h

00001 //==========================================================================
00002 //
00003 //   pq_node.h
00004 //
00005 //==========================================================================
00006 // $Id: pq_node.h,v 1.15 2003/04/03 11:48:26 raitner Exp $
00007 
00008 #ifndef PQ_NODE_H
00009 #define PQ_NODE_H
00010 
00011 #include <GTL/GTL.h>
00012 #include <GTL/symlist.h>
00013 #include <GTL/graph.h>
00014 
00015 #include <list>
00016 #include <iostream>
00017 
00018 __GTL_BEGIN_NAMESPACE
00019 
00020 class pq_tree;
00021 class p_node;
00022 class q_node; 
00023 class pq_leaf;
00024 class direction_indicator;
00025 
00029 class GTL_EXTERN pq_node 
00030 {
00031 protected:
00035     typedef symlist<pq_node*>::iterator iterator;
00036 
00040     enum PQ_KIND {P_NODE, Q_NODE, LEAF, DIR};
00041 
00045     enum PQ_MARK {UNMARKED, QUEUED, BLOCKED, UNBLOCKED};
00046 
00050     pq_node (node n_, int id_) :  pert_children(0),
00051                                   pert_leaves(0),
00052                                   mark (UNMARKED),
00053                                   n (n_),
00054                                   id (id_)
00055     {
00056     }
00057 
00061     virtual ~pq_node ();
00062 
00067     virtual PQ_KIND kind() const = 0;
00068 
00073     virtual void partial(iterator)
00074     {
00075     }
00076 
00081     virtual void full(iterator)
00082     {
00083     }
00084 
00089     virtual void write(ostream&, int) = 0;
00090 
00095     virtual void clear()
00096     {
00097         mark = UNMARKED;
00098         pert_leaves = 0;
00099         pert_children = 0;
00100     }
00101 
00102     // type-casts 
00103 
00108     virtual p_node* P() = 0;
00109 
00114     virtual q_node* Q() = 0;
00115 
00120     virtual direction_indicator* D() = 0;
00121 
00126     virtual pq_leaf* L() = 0;
00127 
00128     //
00129     // Data used in reductions
00130     //
00131 
00139     int pert_children;
00140 
00147     int pert_leaves;
00148 
00157     bool is_endmost;
00158 
00165     pq_node* father;
00166 
00179     PQ_MARK mark;
00180 
00185     symlist<pq_node*> sons;
00186 
00191     iterator pos;
00192 
00201     list<pq_node*>::iterator lpos;
00202 
00203     //
00204     // Application specific data (should become template parameter)
00205     //
00206 
00211     node n;
00212 
00216     int id;
00217 
00221     node up;
00222 
00226     int up_id;
00227 
00228     //
00229     // Friends
00230     //
00231 
00236     friend class q_node;
00237 
00242     friend class p_node;
00243 
00248     friend class pq_tree;
00249 
00254     friend class planarity;
00255 
00260     GTL_EXTERN friend ostream& operator<<(ostream&, const pq_tree&);
00261 };
00262 
00263 
00267 class GTL_EXTERN p_node : public pq_node 
00268 {
00269 private:
00273     p_node(node, int);
00274 
00278     p_node(node, int, symlist<pq_node*>&);
00279     
00280     //
00281     // pq_node interface
00282     // 
00283 
00287     void partial(iterator);
00288 
00292     void full(iterator);
00293 
00298     PQ_KIND kind () const 
00299     {
00300         return P_NODE;
00301     }
00302 
00307     void write (ostream&, int);
00308 
00312     void clear ();
00313 
00314     // type-casts
00315 
00320     p_node* P()
00321     {
00322         return this;
00323     }
00324 
00329     q_node* Q()
00330     {
00331         assert(false);
00332         return 0;
00333     }
00334 
00339     direction_indicator* D()
00340     {
00341         assert(false);
00342         return 0;
00343     }
00344 
00349     pq_leaf* L()
00350     {
00351         assert(false);
00352         return 0;
00353     }
00354 
00355     //
00356     // Additional
00357     //
00358 
00364     symlist<pq_node*> full_sons;
00365 
00371     symlist<pq_node*> partial_sons;
00372 
00377     int child_count;
00378 
00383     int partial_count;
00384 
00389     int full_count;
00390 
00391     //
00392     // Friends 
00393     //
00394 
00399     friend class planarity;
00400 
00405     friend class pq_tree;
00406 
00411     GTL_EXTERN friend ostream& operator<<(ostream&, const pq_tree&);
00412 };
00413 
00414 
00418 class GTL_EXTERN q_node : public pq_node 
00419 {
00420 private:
00424     q_node (node, int);
00425 
00426     //
00427     // pq_node interface
00428     // 
00429 
00433     void partial(iterator);
00434 
00438     void full(iterator);
00439 
00444     PQ_KIND kind() const
00445     {
00446         return Q_NODE;
00447     }
00448 
00453     void write(ostream&, int);
00454 
00458     void clear();
00459 
00460     // type-casts
00461 
00466     p_node* P()
00467     {
00468         assert (false);
00469         return 0;
00470     }
00471 
00476     q_node* Q()
00477     {
00478         return this;
00479     }
00480 
00485     direction_indicator* D()
00486     {
00487         assert (false);
00488         return 0;
00489     }
00490 
00495     pq_leaf* L()
00496     {
00497         assert (false);
00498         return 0;
00499     }
00500 
00501     //
00502     // Additional
00503     //
00504 
00510     void pertinent(iterator);
00511     
00518     q_node* merge (iterator);
00519     
00524     void turn (); 
00525 
00531     iterator pert_begin;    
00532 
00537     iterator pert_end;
00538 
00545     iterator partial_pos[3];
00546 
00554     bool pert_cons;
00555 
00560     int partial_count;
00561 
00566     int full_count;
00567     
00568     //
00569     // Friends 
00570     //
00571 
00576     friend class planarity;
00577 
00582     friend class pq_tree;
00583 };
00584 
00585 
00589 class GTL_EXTERN pq_leaf : public pq_node 
00590 {
00591 public:
00595     pq_leaf (int, int, edge, node);
00596 private:
00601     PQ_KIND kind() const
00602     {
00603         return LEAF;
00604     }
00605 
00610     void write (ostream&, int);
00611 
00612     // type-casts
00613 
00618     p_node* P()
00619     {
00620         assert(false);
00621         return 0;
00622     }
00623 
00628     q_node* Q()
00629     {
00630         assert(false);
00631         return 0;
00632     }
00633 
00638     direction_indicator* D()
00639     {
00640         assert(false);
00641         return 0;
00642     }
00643 
00648     pq_leaf* L()
00649     {
00650         return this;
00651     }
00652     
00653     //
00654     // Additional
00655     //
00656 
00660     int other_id;
00661 
00665     edge e;
00666 
00667     //
00668     // Friends 
00669     //
00670 
00675     friend class planarity;
00676 
00681     friend class pq_tree;
00682 };
00683 
00684 
00688 class GTL_EXTERN direction_indicator : public pq_node 
00689 {
00690 private:
00694     direction_indicator (node n_, int id_) : pq_node (n_, id_) { };
00695 
00696     //
00697     // pq_node interface
00698     // 
00699     
00704     PQ_KIND kind() const
00705     {
00706         return DIR;
00707     }
00708 
00713     void write (ostream& os, int);
00714 
00715     // type-casts 
00716 
00721     p_node* P()
00722     {
00723         assert(false);
00724         return 0;
00725     }
00726 
00731     q_node* Q()
00732     {
00733         assert(false);
00734         return 0;
00735     }
00736 
00741     direction_indicator* D()
00742     {
00743         return this;
00744     }
00745 
00750     pq_leaf* L()
00751     {
00752         assert(false);
00753         return 0;
00754     }
00755     
00756     //
00757     // Additional
00758     //
00759 
00763     bool direction;     
00764 
00765     //
00766     // Friends 
00767     //
00768 
00773     friend class planarity;
00774 
00779     friend class pq_tree;
00780 };
00781 
00782 __GTL_END_NAMESPACE
00783 
00784 #endif
00785 
00786 //--------------------------------------------------------------------------
00787 //   end of file
00788 //--------------------------------------------------------------------------