Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / planarity / MMFixedEmbeddingInserter.h
blob29127ceedf212ba3110e2ccc9d3bf28cbbe6f21d
1 /*
2 * $Revision: 2583 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-12 01:02:21 +0200 (Do, 12. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief declaration of class MMFixedEmbeddingInserter
12 * \author Carsten Gutwenger
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
26 * for details.
28 * \par
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * \par
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #ifdef _MSC_VER
44 #pragma once
45 #endif
47 #ifndef OGDF_MM_FIXED_EMBEDDING_INSERTER_H
48 #define OGDF_MM_FIXED_EMBEDDING_INSERTER_H
52 #include <ogdf/module/MMEdgeInsertionModule.h>
53 #include <ogdf/basic/CombinatorialEmbedding.h>
54 #include <ogdf/basic/FaceArray.h>
55 #include <ogdf/basic/tuples.h>
59 namespace ogdf {
62 class OGDF_EXPORT FaceSetSimple;
63 class OGDF_EXPORT NodeSetPure;
64 class OGDF_EXPORT NodeSet;
67 //! Minor-monotone edge insertion with fixed embedding.
68 class OGDF_EXPORT MMFixedEmbeddingInserter : public MMEdgeInsertionModule
70 public:
71 //! Creates a minor-monotone fixed embedding inserter.
72 MMFixedEmbeddingInserter();
74 // destruction
75 virtual ~MMFixedEmbeddingInserter() { }
78 //! Sets the remove-reinsert option for postprocessing.
79 void removeReinsert(RemoveReinsertType rrOption) {
80 m_rrOption = rrOption;
83 //! Returns the current setting of the remove-reinsert option.
84 RemoveReinsertType removeReinsert() const {
85 return m_rrOption;
89 //! Sets the portion of most crossed edges used during postprocessing.
90 /**
91 * The value is only used if the remove-reinsert option is set to rrMostCrossed.
92 * The number of edges used in postprocessing is then
93 * number of edges * percentMostCrossed() / 100.
95 void percentMostCrossed(double percent) {
96 m_percentMostCrossed = percent;
99 //! Returns the current setting of the option percentMostCrossed.
100 double percentMostCrossed() const {
101 return m_percentMostCrossed;
105 private:
107 * \brief Implementation of algorithm call.
109 * @param PG is the input planarized expansion and will also receive the result.
110 * @param origEdges is the list of original edges (edges in the original graph
111 * of \a PG) that have to be inserted.
112 * @param forbiddenEdgeOrig points to an edge array indicating if an original edge is
113 * forbidden to be crossed.
115 ReturnType doCall(
116 PlanRepExpansion &PG,
117 const List<edge> &origEdges,
118 const EdgeArray<bool> *forbiddenEdgeOrig);
120 //! Constructs the search network (extended dual graph).
122 * @param PG is the planarized expansion.
123 * @param E is the corresponding embeddding.
125 void constructDual(
126 const PlanRepExpansion &PG,
127 const CombinatorialEmbedding &E);
129 //! Finds a shortest insertion path for an edge.
131 * @param PG is the planarized expansion.
132 * @param E is the corresponding embeddding.
133 * @param sources is the list of nodes in PG from where the path may start.
134 * @param targets is the list of nodes in PG where the path may end.
135 * @param crossed is assigned the insertion path. For each crossed edge or
136 * node, we have a pair (\a adj1,\a adj2) in the list; in case of a
137 * crossed edge, \a adj1 corresponds to the crossed edge and adj2
138 * is 0; in case of a crossed node, adj1 (adj2) is the first adjacency
139 * entry assigned to the left (right) node after the split. Additionally,
140 * the first and last element in the list specify, where the path
141 * leaves the source and enters the target node.
142 * @param forbiddenEdgeOrig points to an edge array indicating if an original edge is
143 * forbidden to be crossed.
145 void findShortestPath(
146 const PlanRepExpansion &PG,
147 const CombinatorialEmbedding &E,
148 const List<node> &sources,
149 const List<node> &targets,
150 List<Tuple2<adjEntry,adjEntry> > &crossed,
151 const EdgeArray<bool> *forbiddenEdgeOrig);
153 void prepareAnchorNode(
154 PlanRepExpansion &PG,
155 CombinatorialEmbedding &E,
156 adjEntry &adjStart,
157 node srcOrig);
159 void preprocessInsertionPath(
160 PlanRepExpansion &PG,
161 CombinatorialEmbedding &E,
162 node srcOrig,
163 node tgtOrig,
164 //PlanRepExpansion::nodeSplit ns,
165 List<Tuple2<adjEntry,adjEntry> > &crossed);
168 * \brief Inserts an edge according to a given insertion path and updates the search network.
170 * If an orignal edge \a eOrig is inserted, \a srcOrig and \a tgtOrig are \a eOrig's source
171 * and target node, and \a nodeSplit is 0. If a node split is inserted, then \a eOrig is 0,
172 * and \a srcOrig and \a tgtOrig refer to the same node (which corresponds to the \a nodeSplit).
174 * @param PG is the planarized expansion.
175 * @param E is the corresponding embeddding.
176 * @param eOrig is the original edge that has to be inserted.
177 * @param srcOrig is the original source node.
178 * @param tgtOrig is the original target node
179 * @param nodeSplit is the node split that has to be inserted.
180 * @param crossed is the insertion path as described with findShortestPath().
182 void insertEdge(
183 PlanRepExpansion &PG,
184 CombinatorialEmbedding &E,
185 edge eOrig,
186 node srcOrig,
187 node tgtOrig,
188 PlanRepExpansion::NodeSplit *nodeSplit,
189 List<Tuple2<adjEntry,adjEntry> > &crossed);
192 * \brief Removes the insertion path of an original edge or a node split and updates the search network.
194 * @param PG is the planarized expansion.
195 * @param E is the corresponding embeddding.
196 * @param eOrig is the original edge whose insertion path shall be removed.
197 * @param nodeSplit is the node split whose insertion path shall be removed.
198 * @param oldSrc is assigned the source node of the removed insertion path
199 * (might be changed during path removal!).
200 * @param oldTgt is assigned the target node of the removed insertion path
201 * (might be changed during path removal!).
203 void removeEdge(
204 PlanRepExpansion &PG,
205 CombinatorialEmbedding &E,
206 edge eOrig,
207 PlanRepExpansion::NodeSplit *nodeSplit,
208 node &oldSrc,
209 node &oldTgt);
212 * \brief Inserts dual edges between vertex node \a vDual and left face of \a adj.
214 * @param vDual is the dual node of \a adj's node.
215 * @param adj is an adjacency entry in the planarized expansion.
216 * @param E is the corresponding embeddding.
218 void insertDualEdge(node vDual, adjEntry adj, const CombinatorialEmbedding &E);
221 * \brief Inserts all dual edges incident to \a v's dual node.
223 * @param v is a node in the planarized expansion.
224 * @param E is the corresponding embeddding.
226 void insertDualEdges(node v, const CombinatorialEmbedding &E);
229 * \brief Removes a (redundant) node split consisting of a single edge.
231 * @param PG is the planarized expansion.
232 * @param E is the corresponding embeddding.
233 * @param nodeSplit is a node split whose insertion path consists of a single edge.
235 void contractSplit(
236 PlanRepExpansion &PG,
237 CombinatorialEmbedding &E,
238 PlanRepExpansion::NodeSplit *nodeSplit);
241 * \brief Reduces the insertion path of a node split at node \a u if required.
243 * The insertion path is reduced by unsplitting \a u if \a u has degree 2.
244 * @param PG is the planarized expansion.
245 * @param E is the corresponding embeddding.
246 * @param u is a node in the planarized expansion.
247 * @param nsCurrent is a node split which may not be contracted.
249 void contractSplitIfReq(
250 PlanRepExpansion &PG,
251 CombinatorialEmbedding &E,
252 node u,
253 const PlanRepExpansion::nodeSplit nsCurrent = 0);
256 * \brief Converts a dummy node to a copy of an original node.
258 void convertDummy(
259 PlanRepExpansion &PG,
260 CombinatorialEmbedding &E,
261 node u,
262 node vOrig,
263 PlanRepExpansion::nodeSplit ns);
266 * \brief Collects all anchor nodes (including dummies) of a node.
268 * @param v is the current node when traversing all copy nodes of an original node
269 * that are connected in a tree-wise manner.
270 * @param nodes is assigned the set of anchor nodes.
271 * @param nsParent is the parent node split.
272 * @param PG is the planarized expansion.
274 void collectAnchorNodes(
275 node v,
276 NodeSet &nodes,
277 const PlanRepExpansion::NodeSplit *nsParent,
278 const PlanRepExpansion &PG) const;
281 * \brief Returns all anchor nodes of \a vOrig in n\a nodes.
283 * @param vOrig is a node in the original graph.
284 * @param nodes ia assigned the set of anchor nodes.
285 * @param PG is the planarized expansion.
287 void anchorNodes(
288 node vOrig,
289 NodeSet &nodes,
290 const PlanRepExpansion &PG) const;
293 * \brief Finds the set of anchor nodes of \a src and \a tgt.
295 * @param src is a node in \a PG representing an original node.
296 * @param tgt is a node in \a PG representing an original node.
297 * @param sources ia assigned the set of anchor nodes of \a src's original node.
298 * @param targets ia assigned the set of anchor nodes of \a tgt's original node.
299 * @param PG is the planarized expansion.
301 void findSourcesAndTargets(
302 node src, node tgt,
303 NodeSet &sources,
304 NodeSet &targets,
305 const PlanRepExpansion &PG) const;
308 * \brief Returns a common dummy node in \a sources and \a targets, or 0 of no such node exists.
310 * @param sources is a set of anchor nodes.
311 * @param targets is a set of anchor nodes.
313 node commonDummy(
314 NodeSet &sources,
315 NodeSet &targets);
317 //! Performs several consistency checks on the seach network.
318 bool checkDualGraph(PlanRepExpansion &PG, const CombinatorialEmbedding &E) const;
320 bool checkSplitDeg(
321 PlanRepExpansion &PG);
323 bool origOfDualForbidden(
324 edge e,
325 const PlanRepExpansion &PG,
326 const EdgeArray<bool> *forbiddenEdgeOrig) const
328 if(forbiddenEdgeOrig == 0)
329 return false;
331 if(e->source() == m_vS || e->target() == m_vT)
332 return false;
334 if(m_primalNode[e->source()] != 0)
335 return false;
336 if(m_primalNode[e->target()] != 0)
337 return false;
339 adjEntry adj = m_primalAdj[e];
340 if(adj == 0) return false;
342 edge eOrig = PG.originalEdge(adj->theEdge());
343 if(eOrig != 0) {
344 //if((*forbiddenEdgeOrig)[eOrig] == true)
345 // cout << "forbidden: " << eOrig << ", dual: " << e << endl;
346 return (*forbiddenEdgeOrig)[eOrig];
347 } else return false;
350 void drawDual(
351 const PlanRepExpansion &PG,
352 const EdgeArray<bool> *forbiddenEdgeOrig);
354 RemoveReinsertType m_rrOption; //!< The remove-reinsert option.
355 double m_percentMostCrossed; //!< The percentMostCrossed option.
357 Graph m_dual; //!< The search network (extended dual graph).
358 FaceArray<node> m_dualOfFace; //!< The node in dual corresponding to face in primal.
359 NodeArray<node> m_dualOfNode; //!< The node in dual corresponding to node in primal.
360 NodeArray<node> m_primalNode; //!< The node in PG corresponding to dual node (0 if face).
361 EdgeArray<adjEntry> m_primalAdj; //!< The adjacency entry in primal graph corresponding to edge in dual.
362 AdjEntryArray<edge> m_dualEdge; //!< The dual edge corresponding to crossing the adjacency entry.
363 EdgeArray<int> m_dualCost; //!< The cost of an edge in the seach network.
365 node m_vS; //!< Represents the start node for the path search.
366 node m_vT; //!< Represents the end node for the path search.
367 int m_maxCost; //!< The maximal cost of an edge in the search network + 1.
369 FaceSetSimple *m_delFaces;
370 FaceSetPure *m_newFaces;
371 NodeSetPure *m_mergedNodes;
374 } // end namespace ogdf
376 #endif