Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / planarity / PlanRepExpansion.h
blob340e1ede5ee9902b16c0a23e8cfb497278588600
1 /*
2 * $Revision: 2523 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Declaration of class PlanRepExpansion representing a
11 * planarized representation of the expansion of a graph.
13 * \author Carsten Gutwenger
15 * \par License:
16 * This file is part of the Open Graph Drawing Framework (OGDF).
18 * \par
19 * Copyright (C)<br>
20 * See README.txt in the root directory of the OGDF installation for details.
22 * \par
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * Version 2 or 3 as published by the Free Software Foundation;
26 * see the file LICENSE.txt included in the packaging of this file
27 * for details.
29 * \par
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * \par
36 * You should have received a copy of the GNU General Public
37 * License along with this program; if not, write to the Free
38 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 * Boston, MA 02110-1301, USA.
41 * \see http://www.gnu.org/copyleft/gpl.html
42 ***************************************************************/
45 #ifdef _MSC_VER
46 #pragma once
47 #endif
49 #ifndef OGDF_PLAN_REP_EXPANSION_H
50 #define OGDF_PLAN_REP_EXPANSION_H
53 #include <ogdf/basic/Graph.h>
54 #include <ogdf/basic/tuples.h>
55 #include <ogdf/basic/SList.h>
58 namespace ogdf {
61 class OGDF_EXPORT CombinatorialEmbedding;
62 class OGDF_EXPORT FaceSetPure;
63 class OGDF_EXPORT NodeSetPure;
66 /**
67 * \brief Planarized representations (of a connected component) of a graph.
69 * Maintains types of edges (generalization, association) and nodes,
70 * and the connected components of the graph.
72 class OGDF_EXPORT PlanRepExpansion : public Graph
74 public:
75 struct Crossing {
76 Crossing() { m_adj = 0; }
77 Crossing(adjEntry adj) { m_adj = adj; }
79 adjEntry m_adj;
80 SList<adjEntry> m_partitionLeft;
81 SList<adjEntry> m_partitionRight;
83 friend ostream &operator<<(ostream &os, const Crossing &c) {
84 os << "(" << c.m_adj << ")";
85 return os;
90 /**
91 * \brief Representation of a node split in a planarized expansion.
93 * Stores in particular the insertion path of the node split (just like the
94 * chain of an original edge).
96 class NodeSplit
98 public:
99 /**
100 * \brief Creates an empty node split.
102 NodeSplit() { }
105 * \brief Creates a node split and sets its iterator in the list of all node splits.
107 NodeSplit(ListIterator<NodeSplit> it) : m_nsIterator(it) { }
110 * \brief Returns the first node on the node split's insertion path.
112 node source() const { return m_path.front()->source(); }
115 * \brief Returns the last node on the node split's insertion path.
117 node target() const { return m_path.back ()->target(); }
119 List<edge> m_path; //!< The insertion path of the node split.
120 ListIterator<NodeSplit> m_nsIterator; //!< This node split's iterator in the list of all node splits.
123 //! Pointer to a node split.
124 typedef PlanRepExpansion::NodeSplit *nodeSplit;
128 * \brief Creates a planarized expansion of graph \a G.
130 * All nodes are allowed to be split.
132 PlanRepExpansion(const Graph& G);
135 * \brief Creates a planarized expansion of graph \a G with given splittable nodes.
137 * Only the node in \a splittableNodes are allowed to be split.
138 * @param G is the original graph of this planarized expansion.
139 * @param splittableNodes contains all the nodes in \a G that are splittable.
141 PlanRepExpansion(const Graph& G, const List<node> &splittableNodes);
143 ~PlanRepExpansion() {}
147 * @name Acess methods
149 //@{
151 //! Returns a reference to the original graph.
152 const Graph &original() const { return *m_pGraph; }
154 //! Returns the original node of \a v, or 0 if \a v is a dummy.
155 node original(node v) const { return m_vOrig[v]; }
157 //! Returns the list of copy nodes of \a vOrig.
158 const List<node> &expansion(node vOrig) const { return m_vCopy[vOrig]; }
160 //! Returns the first copy node of \a vOrig.
161 node copy(node vOrig) const { return m_vCopy[vOrig].front(); }
163 //! Returns the original edge of \ e, or 0 if \a e has none (e.g., \a e belongs to a node split).
164 edge originalEdge(edge e) const { return m_eOrig[e]; }
166 //! Returns the insertion path of edge \a eOrig.
167 const List<edge> &chain(edge eOrig) const { return m_eCopy[eOrig]; }
169 //! Returns the first edge in \a eOrig's insertion path.
170 edge copy(edge eOrig) const { return m_eCopy[eOrig].front(); }
172 //! Returns true iff \a v is splittable.
173 bool splittable(node v) const { return m_splittable[v]; }
175 //! Returns true iff \a vOrig is splittable.
176 bool splittableOrig(node vOrig) const { return m_splittableOrig[vOrig]; }
178 //! Returns the node split associated with \a e, or 0 if none (e.g., \a e belongs to an original edge).
179 NodeSplit *nodeSplitOf(edge e) const { return m_eNodeSplit[e]; }
181 //! Returns the number of node splits.
182 int numberOfNodeSplits() const { return m_nodeSplits.size(); }
183 int numberOfSplittedNodes() const;
185 //! Returns the list of node splits.
186 List<NodeSplit> &nodeSplits() { return m_nodeSplits; }
189 * \brief Sets the original edge and corresponding node split of \a e and returns the corresponding insertion path.
191 * @param e is an edge in the planarized expansion.
192 * @param eOrig is assigned the original edge of \a e (or 0 if none).
193 * @param ns is assigned the node split corresponding to \a e (or 0 if none).
194 * @return a reference to the insertion path containing \a e; this is either the insertion
195 * path of \a eOrig (if this is not 0), or of \a ns.
197 List<edge> &setOrigs(edge e, edge &eOrig, nodeSplit &ns);
199 ListConstIterator<edge> position(edge e) const { return m_eIterator[e]; }
201 bool isPseudoCrossing(node v) const;
203 //! Computes the number of crossings.
204 int computeNumberOfCrossings() const;
206 //@}
208 * @name Processing connected components
210 //@{
214 * \brief Returns the number of connected components in the original graph.
216 int numberOfCCs() const {
217 return m_nodesInCC.size();
221 * \brief Returns the index of the current connected component (-1 if not yet initialized).
223 int currentCC() const {
224 return m_currentCC;
228 * \brief Returns the list of (original) nodes in connected component \a i.
230 * Note that connected components are numbered 0,1,...
232 const List<node> &nodesInCC(int i) const {
233 return m_nodesInCC[i];
237 * \brief Returns the list of (original) nodes in the current connected component.
239 const List<node> &nodesInCC() const {
240 return m_nodesInCC[m_currentCC];
244 * \brief Initializes the planarized representation for connected component \a i.
246 * This initialization is always required. After performing this initialization,
247 * the planarized representation represents a copy of the <i>i</i>-th connected
248 * component of the original graph, where connected components are numbered
249 * 0,1,2,...
251 void initCC(int i);
254 //@}
256 * @name Update operations
258 //@{
260 edge split(edge e);
262 void unsplit(edge eIn, edge eOut);
264 //! Removes edge \a e from the planarized expansion.
265 void delCopy(edge e);
267 //! Embeds the planarized expansion; returns true iff it is planar.
268 bool embed();
270 void insertEdgePath(
271 edge eOrig,
272 nodeSplit ns,
273 node vStart,
274 node vEnd,
275 List<Crossing> &eip,
276 edge eSrc,
277 edge eTgt);
280 * \brief Inserts an edge or a node split according to insertion path \a crossedEdges.
282 * If \a eOrig is not 0, a new insertion path for \a eOrig is inserted; otherwise,
283 * a new insertion path for node split \a ns is inserted.
284 * @param eOrig is an original edge in the graph (or 0).
285 * @param ns is a node split in the planarized expansion.
286 * @param E is an embedding of the planarized expansion.
287 * @param crossedEdges defines the insertion path.
288 * \pre Not both \a eOrig and \a ns may be 0.
289 * \see GraphCopy::insertEdgePathEmbedded() for a specification of \a crossedEdges.
291 void insertEdgePathEmbedded(
292 edge eOrig,
293 nodeSplit ns,
294 CombinatorialEmbedding &E,
295 const List<Tuple2<adjEntry,adjEntry> > &crossedEdges);
298 * \brief Removes the insertion path of \a eOrig or \a ns.
300 * @param E is an embedding of the planarized expansion.
301 * @param eOrig is an original edge in the graph (or 0).
302 * @param ns is a node split in the planarized expansion.
303 * @param newFaces is assigned the set of new faces resulting from joining faces when removing edges.
304 * @param mergedNodes is assigned the set of nodes in the planarized expansion that resulted
305 * from merging (splittable) nodes.
306 * @param oldSrc is assigned the source node of the removed insertion path.
307 * @param oldTgt is assigned the target node of the removed insertion path.
308 * \pre Not both \a eOrig and \a ns may be 0.
310 void removeEdgePathEmbedded(
311 CombinatorialEmbedding &E,
312 edge eOrig,
313 nodeSplit ns,
314 FaceSetPure &newFaces,
315 NodeSetPure &mergedNodes,
316 node &oldSrc,
317 node &oldTgt);
320 * \brief Removes the insertion path of \a eOrig or \a ns.
322 * @param eOrig is an original edge in the graph (or 0).
323 * @param ns is a node split in the planarized expansion.
324 * @param oldSrc is assigned the source node of the removed insertion path.
325 * @param oldTgt is assigned the target node of the removed insertion path.
326 * \pre Not both \a eOrig and \a ns may be 0.
328 void removeEdgePath(
329 edge eOrig,
330 nodeSplit ns,
331 node &oldSrc,
332 node &oldTgt);
335 * \brief Removes an (unneccessary) node split consisting of a single edge.
337 * Nodes splits consisting of a single edge are superfluous and canbe removed
338 * by contracting the respective edge.
339 * @param ns is the node split to be removed.
340 * @param E is an embedding of the planarized expansion.
342 void contractSplit(nodeSplit ns, CombinatorialEmbedding &E);
345 * \brief Removes an (unneccessary) node split consisting of a single edge.
347 * Nodes splits consisting of a single edge are superfluous and canbe removed
348 * by contracting the respective edge.
349 * @param ns is the node split to be removed.
351 void contractSplit(nodeSplit ns);
354 * \brief Unsplits a superfluous expansion node of degree 2.
355 * @param u is a node in the planarized expansion which has degree 2 and is part of the
356 * expansion of an original node.
357 * @param eContract is the edge incident to \a u which is part of a node split; this edge
358 * gets contracted.
359 * @param eExpand is the edge incident to \a u which belongs to the insertion path
360 * that gets enlarged.
361 * @param E is an embedding of the planarized expansion.
363 edge unsplitExpandNode(
364 node u,
365 edge eContract,
366 edge eExpand,
367 CombinatorialEmbedding &E);
370 * \brief Unsplits a superfluous expansion node of degree 2.
371 * @param u is a node in the planarized expansion which has degree 2 and is part of the
372 * expansion of an original node.
373 * @param eContract is the edge incident to \a u which is part of a node split; this edge
374 * gets contracted.
375 * @param eExpand is the edge incident to \a u which belongs to the insertion path
376 * that gets enlarged.
378 edge unsplitExpandNode(
379 node u,
380 edge eContract,
381 edge eExpand);
384 * \brief Splits edge \a e and introduces a new node split starting at \a v.
386 * @param v is a node in the planarized expansion; the expansion of \a v's original
387 * node is enlarged.
388 * @param e is the edge to be split; the insertion path of \a e's original edge
389 * must start or end at \a v.
390 * @param E is an embedding of the planarized expansion.
391 * @return the newly created edge; the node resulting from splitting \a e is the
392 * target node of this edge.
394 edge enlargeSplit(node v, edge e, CombinatorialEmbedding &E);
397 * \brief Splits edge \a e and introduces a new node split starting at \a v.
399 * @param v is a node in the planarized expansion; the expansion of \a v's original
400 * node is enlarged.
401 * @param e is the edge to be split; the insertion path of \a e's original edge
402 * must start or end at \a v.
403 * @return the newly created edge; the node resulting from splitting \a e is the
404 * target node of this edge.
406 edge enlargeSplit(node v, edge e);
409 * \brief Introduces a new node split by splitting an exisiting node split.
411 * @param e is the edge to be split; the node split corresponding to \a e is split
412 * into two node splits.
413 * @param E is an embedding of the planarized expansion.
414 * @return the newly created edge; the node resulting from splitting \a e is the
415 * target node of this edge.
417 edge splitNodeSplit(edge e, CombinatorialEmbedding &E);
420 * \brief Introduces a new node split by splitting an exisiting node split.
422 * @param e is the edge to be split; the node split corresponding to \a e is split
423 * into two node splits.
424 * @return the newly created edge; the node resulting from splitting \a e is the
425 * target node of this edge.
427 edge splitNodeSplit(edge e);
430 * \brief Removes a self-loop \a e = (\a u,\a u).
432 * \a u must be a dummy node; hence, \a u has degree 2 node after removing \ e, and
433 * \a u is unsplit afterwards.
434 * @param e must be a self loop in the planarized expansion.
435 * @param E is an embedding of the planarized expansion.
437 void removeSelfLoop(edge e, CombinatorialEmbedding &E);
439 void removeSelfLoop(edge e);
442 * \brief Converts a dummy node \a u to a copy of an original node \a vOrig.
444 * This method is used if two copy nodes \a x and \a y of the same original node \a vOrig
445 * can be connected by converting a dummy node \a u into a copy node of \a vOrig, since an
446 * insertion path starting (or ending) at \a x crosses an insertion path starting (or
447 * ending) at \a y.
448 * @param u is a dummy node in the planarized expansion.
449 * @param vOrig is an original node.
450 * @param ns is a node split that can be reused for connecting \a x with \a u.
452 PlanRepExpansion::nodeSplit convertDummy(
453 node u,
454 node vOrig,
455 PlanRepExpansion::nodeSplit ns);
457 edge separateDummy(
458 adjEntry adj_1,
459 adjEntry adj_2,
460 node vStraight,
461 bool isSrc);
463 void resolvePseudoCrossing(node v);
465 //@}
467 * @name Miscelleaneous
469 //@{
472 * \brief Performs various consistency checks on the data structure.
474 bool consistencyCheck() const;
476 //@}
478 private:
479 void doInit(const Graph &G, const List<node> &splittableNodes);
480 void prepareNodeSplit(
481 const SList<adjEntry> &partitionLeft,
482 adjEntry &adjLeft,
483 adjEntry &adjRight);
485 const Graph *m_pGraph; //!< The original graph.
486 NodeArray<node> m_vOrig; //!< The corresponding node in the original graph.
487 EdgeArray<edge> m_eOrig; //!< The corresponding edge in the original graph.
488 EdgeArray<ListIterator<edge> > m_eIterator; //!< The position of copy edge in the list.
489 EdgeArray<List<edge> > m_eCopy; //!< The corresponding list of edges in the graph copy.
490 NodeArray<ListIterator<node> > m_vIterator; //!< The position of copy node in the list.
491 NodeArray<List<node> > m_vCopy; //!< The corresponding list of nodes in the graph copy.
493 NodeArray<bool> m_splittable;
494 NodeArray<bool> m_splittableOrig;
495 EdgeArray<NodeSplit *> m_eNodeSplit;
496 List<NodeSplit> m_nodeSplits;
498 int m_currentCC; //!< The index of the current component.
499 int m_numCC; //!< The number of components in the original graph.
501 Array<List<node> > m_nodesInCC; //!< The list of original nodes in each component.
502 EdgeArray<edge> m_eAuxCopy; // auxiliary
506 } // end namespace ogdf
509 #endif