Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:36

0001 /* This software is distributed under the GNU Lesser General Public License */
0002 //==========================================================================
0003 //
0004 //   embedding.h
0005 //
0006 //==========================================================================
0007 // $Id: embedding.h,v 1.20 2003/06/11 11:28:21 raitner Exp $
0008 
0009 #ifndef __EMBEDDING__H
0010 #define __EMBEDDING__H
0011 
0012 #include <GTL/GTL.h>
0013 #include <GTL/graph.h>
0014 #include <GTL/st_number.h>
0015 #include <GTL/symlist.h>
0016 
0017 __GTL_BEGIN_NAMESPACE
0018 
0019 /**
0020  * @brief Ordered adjacency lists as a result of planarity testing.
0021  *
0022  * It is known that if a graph is planar the adjacency list of every node
0023  * can be ordered in such a way that it reflects the order the adjacent
0024  * edges will have in a planar drawing around the node. Although the tested
0025  * graph might have been directed the planar embedding one gets will always
0026  * correspond to the underlying undirected graph, i.e. an edge from @c n1 to
0027  * @c n2 will occurr in both adjacency lists.
0028  */
0029 class GTL_EXTERN planar_embedding 
0030 {
0031 public:
0032     /**
0033      * @internal
0034      */
0035     typedef symlist<edge> adj_list;
0036 
0037     /**
0038      * @internal
0039      */
0040     typedef symlist<edge>::iterator iterator;
0041 private:
0042     /**
0043      * @internal
0044      * Creates an empty planar embedding not related to any graph.
0045      * @note At the moment planar embedding are thought as an output of
0046      * planarity testing, this why they can't be constructed from scratch. 
0047      */
0048     planar_embedding() : G(0)
0049     {
0050     }
0051 public:
0052     /**
0053      * 
0054      * Make this object a copy of @p em.
0055      *
0056      * @param em planar embedding
0057      */
0058     planar_embedding(const planar_embedding& em);
0059 
0060     /**
0061      * 
0062      * Destructor.
0063      */
0064     virtual ~planar_embedding()
0065     {
0066     }
0067 
0068     /**
0069      * 
0070      * Assigns @p em to this object. All former information in this object
0071      * will be deleted.
0072      *
0073      * @param em 
0074      *
0075      * @return reference to this object
0076      */
0077     planar_embedding& operator=(const planar_embedding& em); 
0078 private:
0079     /**
0080      * @internal
0081      * Initializes adjacency lists.
0082      * 
0083      * @param G graph 
0084      */
0085     void init(graph& G);
0086 
0087     /**
0088      * @internal
0089      * Turns adjacency list of node @p n.
0090      *
0091      * @param n node.
0092      */
0093     void turn(node n);
0094 
0095     /**
0096      * @internal
0097      * Insert edge @p e at the end of adjacency list of @p n.
0098      *
0099      * @param n node 
0100      * @param e edge to be inserted
0101      *
0102      * @return iterator to position of insertion
0103      */
0104     iterator push_back(node n, edge e);
0105 
0106     /**
0107      * @internal
0108      * Insert edge @p e at the beginning of adjacency list of @p n.
0109      *
0110      * @param n node
0111      * @param e edge to be inserted
0112      *
0113      * @return iterator to position of insertion
0114      */
0115     iterator push_front(node n, edge e);
0116 
0117     /**
0118      * @internal
0119      * Insert selfloop @p e.
0120      *
0121      * @param @p e selfloop 
0122      */
0123     void insert_selfloop (edge e);
0124 
0125     /**
0126      * @internal
0127      * Returns position of edge @p e in adjacency list of node @p n.
0128      *
0129      * @param n node
0130      * @param e adjacent edge
0131      *
0132      * @return position of @p e
0133      */
0134     iterator& pos (node, edge);
0135 public:
0136     /**
0137      * 
0138      * Returns reference to ordered adjacency list of node @p n.
0139      *
0140      * @param n node
0141      *
0142      * @return ordered adjacency list
0143      */
0144     adj_list& adjacency(node n)
0145     {
0146     return adj[n];
0147     }
0148 
0149     /**
0150      * 
0151      * Returns reference to ordered adjacency list of node @p n.
0152      *
0153      * @param n node
0154      *
0155      * @return ordered adjacency list
0156      */
0157     const adj_list& adjacency(node n) const
0158     {
0159     return adj[n];
0160     }
0161 
0162     /**
0163      * 
0164      * Start iteration through adjacency list of node @p n.
0165      *
0166      * @param n node
0167      *
0168      * @return start iterator
0169      */
0170     iterator adj_edges_begin(node n)
0171     {
0172     return adj[n].begin();
0173     } 
0174 
0175     /**
0176      * 
0177      * End of iteration through adjacency list of node @p n.
0178      *
0179      * @param @p n node
0180      *
0181      * @return one-past the end iterator
0182      */
0183     iterator adj_edges_end(node n)
0184     {
0185     return adj[n].end();
0186     }
0187 
0188     /**
0189      * 
0190      * Returns the cyclic successor of edge @p e in the adjacency list of
0191      * node @p n.
0192      *
0193      * @param n node
0194      * @param e edge adjacent to @p n
0195      *
0196      * @return edge following @p e in adjacency of @p n
0197      */
0198     edge cyclic_next(node n, edge e);
0199 
0200     /**
0201      * 
0202      * Returns the cyclic predecessor of edge @p e in the adjacency list of
0203      * node @p n.
0204      *
0205      * @param n node
0206      * @param e edge adjacent to @p n
0207      *
0208      * @return edge preceding @p e in adjacency of @p n
0209      */
0210     edge cyclic_prev(node n, edge e);
0211 
0212 
0213     /**
0214      * 
0215      * Writes embedding with st-numbers as given by @p st to @p os.
0216      *
0217      * @param os output stream
0218      *
0219      * @param st st-numbers
0220      */
0221     void write_st(ostream& os, st_number& st);
0222 
0223     /**
0224      * 
0225      * Returns list of selfloops contained in the graph. These will not
0226      * occur in the adjacency lists.
0227      *
0228      * @retval list of selfloops
0229      */
0230     list<edge>& selfloops()
0231     {
0232     return self;
0233     }
0234 
0235     /**
0236      * 
0237      * Returns list of selfloops contained in the graph. These will not
0238      * occur in the adjacency lists.
0239      *
0240      * @retval list of selfloops
0241      */
0242     const list<edge>& selfloops() const
0243     {
0244     return self;
0245     }
0246 
0247     /**
0248      * 
0249      * Returns list of multiple edges contained in the graph. These are
0250      * edges for which there is already another edge connecting the same
0251      * endpoints is contained in the adjacency lists. Please note that the
0252      * notion "connecting" is meant in an undirected sense. These edges will
0253      * not occur it the adjacency lists.
0254      *
0255      * @retval list of multiple edges
0256      */
0257     list<edge>& multiple_edges()
0258     {
0259     return multi;
0260     }
0261 
0262     /**
0263      * 
0264      * Returns list of multiple edges contained in the graph. These are
0265      * edges for which there is already another edge connecting the same
0266      * endpoints is contained in the adjacency lists. Please note that the
0267      * notion "connecting" is meant in an undirected sense. These edges will
0268      * not occur it the adjacency lists.
0269      *
0270      * @retval list of multiple edges
0271      */
0272     const list<edge>& multiple_edges() const
0273     {
0274     return multi;
0275     }
0276 
0277     /**
0278      * 
0279      * Used for debugging only. Checks whether this is a correct planar 
0280      * embedding by checking the faces of the graph, i.e. at any node
0281      * starting with an arbitrary adjacent edge and advancing along @c
0282      * cyclic_next the start node must be met through the edge given by @c
0283      * cyclic_prev of the edge we started with. 
0284      *
0285      * @retval true iff embedding is correct
0286      */
0287     bool check();
0288 
0289     /**
0290      * @internal
0291      */
0292     friend class planarity;
0293 
0294     /**
0295      * @internal
0296      */
0297     friend class pq_tree;
0298 
0299     /**
0300      * @internal
0301      */
0302     GTL_EXTERN friend ostream& operator<< (ostream&, planar_embedding&);
0303 private:
0304     /**
0305      * @internal
0306      * Graph.
0307      */
0308     graph* G;
0309 
0310     /**
0311      * @internal
0312      * Adjacency lists.
0313      */
0314     node_map<adj_list> adj;
0315 
0316     /**
0317      * @internal
0318      * Positions of edges in its source's adjacency list.
0319      */
0320     edge_map<adj_list::iterator> s_pos;
0321 
0322     /**
0323      * @internal
0324      * Positions of edges in its target's adjacency list.
0325      */
0326     edge_map<adj_list::iterator> t_pos;
0327 
0328     /**
0329      * @internal
0330      * Selfloops.
0331      */
0332     list<edge> self;
0333 
0334     /**
0335      * @internal
0336      * Multiple edges.
0337      */
0338     list<edge> multi;
0339 };
0340 
0341 
0342 // class face
0343 // {    
0344 // public:
0345 //     face (planar_embedding& em, node n, edge e) : embed (em),
0346 //  start (n), first (e) { }
0347 //     virtual ~face () { }
0348 
0349 // private:    
0350 //     planar_embedding& embed;
0351 //     node start;
0352 //     edge first;
0353 
0354 //     friend class planar_embedding;
0355 // };
0356 
0357 // struct _face_iterator
0358 // {
0359 
0360 
0361 //     face& _face;
0362 // };
0363 
0364 __GTL_END_NAMESPACE
0365 
0366 #endif
0367 
0368 //--------------------------------------------------------------------------
0369 //   end of file
0370 //--------------------------------------------------------------------------