6 * $Date: 2012-07-15 22:39:24 +0200 (So, 15. Jul 2012) $
7 ***************************************************************/
10 * \brief Implementation of class MaximumPlanarSubgraph
12 * \author Karsten Klein
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
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
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.
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 ***************************************************************/
45 #include <ogdf/planarity/MaximumPlanarSubgraph.h>
46 #include <ogdf/cluster/MaximumCPlanarSubgraph.h>
47 #include <ogdf/basic/extended_graph_alg.h>
48 #include <ogdf/basic/simple_graph_alg.h>
52 Module::ReturnType
MaximumPlanarSubgraph::doCall(
54 const List
<edge
> &preferedEdges
,
56 const EdgeArray
<int> *pCost
,
57 bool preferredImplyPlanar
)
59 if (G
.numberOfEdges() < 9)
62 //if the graph is planar, we don't have to do anything
68 MaximumCPlanarSubgraph mc
;
69 List
<nodePair
> addEdges
;
74 NodeArray
<node
> tableNodes(G
,0);
75 EdgeArray
<edge
> tableEdges(G
,0);
76 NodeArray
<bool> mark(G
,0);
78 EdgeArray
<int> componentID(G
);
80 // Determine biconnected components
81 int bcCount
= biconnectedComponents(G
,componentID
);
83 // Determine edges per biconnected component
84 Array
<SList
<edge
> > blockEdges(0,bcCount
-1);
89 blockEdges
[componentID
[e
]].pushFront(e
);
92 // Determine nodes per biconnected component.
93 Array
<SList
<node
> > blockNodes(0,bcCount
-1);
95 for (i
= 0; i
< bcCount
; i
++)
97 SListIterator
<edge
> it
;
98 for (it
= blockEdges
[i
].begin(); it
.valid(); ++it
)
101 if (!mark
[e
->source()])
103 blockNodes
[i
].pushBack(e
->source());
104 mark
[e
->source()] = true;
106 if (!mark
[e
->target()])
108 blockNodes
[i
].pushBack(e
->target());
109 mark
[e
->target()] = true;
112 SListIterator
<node
> itn
;
113 for (itn
= blockNodes
[i
].begin(); itn
.valid(); ++itn
)
118 // Perform computation for every biconnected component
123 mr
= mc
.call(CG
, delEdges
, addEdges
);
129 for (i
= 0; i
< bcCount
; i
++)
133 SListIterator
<node
> itn
;
134 for (itn
= blockNodes
[i
].begin(); itn
.valid(); ++ itn
)
137 node w
= C
.newNode();
142 SListIterator
<edge
> it
;
143 for (it
= blockEdges
[i
].begin(); it
.valid(); ++it
)
146 edge f
= C
.newEdge(tableNodes
[e
->source()],tableNodes
[e
->target()]);
150 // Construct a translation table for the edges.
151 // Necessary, since edges are deleted in a new graph
152 // that represents the current biconnected component
153 // of the original graph.
154 EdgeArray
<edge
> backTableEdges(C
,0);
155 for (it
= blockEdges
[i
].begin(); it
.valid(); ++it
)
156 backTableEdges
[tableEdges
[*it
]] = *it
;
158 // The deleted edges of the biconnected component
159 List
<edge
> delEdgesOfBC
;
162 mr
= mc
.call(CG
, delEdgesOfBC
, addEdges
);
163 // Abort if no optimal solution found, i.e., feasible is also not allowed
164 if (mr
!= retOptimal
)
167 // Get the original edges that are deleted and
168 // put them on the list delEdges.
169 while (!delEdgesOfBC
.empty())
170 delEdges
.pushBack(backTableEdges
[delEdgesOfBC
.popFrontRet()]);
177 } //end namespace ogdf