53template<
typename TCost,
class Enable =
void>
54class MaximalPlanarSubgraphSimple { };
66template<
typename TCost>
67class MaximalPlanarSubgraphSimple<TCost, typename
std::enable_if<std::is_integral<TCost>::value>::type>
79 : m_heuristic(heuristic), m_deleteHeuristic(false) { }
83 if (m_deleteHeuristic) {
89 virtual MaximalPlanarSubgraphSimple*
clone()
const override {
90 auto result =
new MaximalPlanarSubgraphSimple(*(m_heuristic.clone()));
91 result->m_deleteHeuristic =
111 if (pCost ==
nullptr) {
112 result = m_heuristic.call(graph, preferredEdges, heuDelEdges, preferredImplyPlanar);
114 result = m_heuristic.call(graph, *pCost, preferredEdges, heuDelEdges,
115 preferredImplyPlanar);
118 if (Module::isSolution(result)) {
120 for (
edge e : heuDelEdges) {
123 for (
edge e : heuDelEdges) {
141template<
typename TCost>
142class MaximalPlanarSubgraphSimple<TCost, typename
std::enable_if<std::is_floating_point<TCost>::value>::type>
153 , m_deleteHeuristic(true)
155 , m_randomGenerator()
165 double randomness = 0.0,
unsigned int runs = 1)
166 : m_heuristic(heuristic)
167 , m_deleteHeuristic(false)
168 , m_randomness(randomness)
169 , m_randomGenerator()
176 if (m_deleteHeuristic) {
182 virtual MaximalPlanarSubgraphSimple*
clone()
const override {
183 auto result =
new MaximalPlanarSubgraphSimple(*(m_heuristic.clone()), m_randomness, m_runs);
184 result->m_deleteHeuristic =
193 void setSeed(
unsigned seed) { m_randomGenerator.seed(seed); }
217 for (
auto i = 0u; i < m_runs; i++) {
220 if (pCost ==
nullptr) {
221 result = m_heuristic.call(graph, preferredEdges, heuDelEdges, preferredImplyPlanar);
223 std::uniform_real_distribution<TCost> distribution(0.0, 1.0);
225 TCost maxCost = firstEdge ==
nullptr ? 0 : (*pCost)[firstEdge];
226 TCost minCost = firstEdge ==
nullptr ? 0 : (*pCost)[firstEdge];
228 Math::updateMax(maxCost, (*pCost)[e]);
229 Math::updateMin(minCost, (*pCost)[e]);
234 TCost normalized = 1;
235 if (maxCost > minCost) {
236 normalized = ((*pCost)[e] - minCost) / (maxCost - minCost);
239 normalizedCost[e] = (1.0 - m_randomness) * normalized
240 + m_randomness * distribution(m_randomGenerator);
242 result = m_heuristic.call(graph, normalizedCost, preferredEdges, heuDelEdges,
243 preferredImplyPlanar);
246 if (Module::isSolution(result)) {
249 if (pCost !=
nullptr) {
254 for (
edge e : heuDelEdges) {
258 delEdgesCurrentBest.
clear();
259 for (
edge e : heuDelEdges) {
268 if (pCost ==
nullptr) {
269 if (i == 0 || delEdgesCurrentBest.
size() < delEdges.
size()) {
272 for (
auto e : delEdgesCurrentBest) {
278 || weightOfList(delEdgesCurrentBest, normalizedCost)
279 < weightOfList(delEdges, normalizedCost)) {
282 for (
auto e : delEdgesCurrentBest) {
307 for (
auto e : list) {
308 result += weights[e];
Includes declaration of graph class.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Declares base class for all module types.
Declaration and Implementation of class PlanarSubgraphEmpty.
Declaration of interface for planar subgraph algorithms.
Basic declarations, included by all source files.
Class for the representation of edges.
Copies of graphs supporting edge splitting.
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
Data type for general directed graphs (adjacency list representation).
edge firstEdge() const
Returns the first edge in the list of all edges.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Doubly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
void clear()
Removes all elements from the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
void quicksort()
Sorts the list using Quicksort.
virtual ~MaximalPlanarSubgraphSimple()
Desctructor.
PlanarSubgraphModule< TCost > & m_heuristic
user given heuristic
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
MaximalPlanarSubgraphSimple()
Constructor.
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic)
Constructor with user given heuristic that is executed before extending the solution to maximality.
virtual Module::ReturnType doCall(const Graph &graph, const List< edge > &preferredEdges, List< edge > &delEdges, const EdgeArray< TCost > *pCost, bool preferredImplyPlanar) override
Computes the set of edges delEdges which have to be deleted to obtain the planar subgraph.
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic, double randomness=0.0, unsigned int runs=1)
Constructor.
TCost weightOfList(const List< edge > &list, const EdgeArray< TCost > &weights)
void setSeed(unsigned seed)
set seed of std::default_random_engine generator to use when randomness > 0
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
std::default_random_engine m_randomGenerator
random generator to use with std::uniform_real_distribution
unsigned int m_runs
number of runs when algorithms is randomized
virtual Module::ReturnType doCall(const Graph &graph, const List< edge > &preferredEdges, List< edge > &delEdges, const EdgeArray< TCost > *pCost, bool preferredImplyPlanar) override
Computes the set of edges delEdges which have to be deleted to obtain the planar subgraph.
virtual ~MaximalPlanarSubgraphSimple()
Destructor.
PlanarSubgraphModule< TCost > & m_heuristic
user given heuristic
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
double m_randomness
randomness of the process: use 0 to compute everything based on the costs, use 1 for completely rando...
MaximalPlanarSubgraphSimple()
Constructor.
ReturnType
The return type of a module.
Dummy implementation for maximum planar subgraph that returns an empty graph.
Interface for planar subgraph algorithms.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Declarations for Comparer objects.
Declaration of extended graph algorithms.
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
The namespace for all OGDF objects.
Compare elements based on a single comparable attribute.