39 #include <type_traits> 45 template<
typename TCost,
class Enable =
void>
46 class MaximalPlanarSubgraphSimple {};
58 template<
typename TCost>
65 , m_deleteHeuristic(true) {}
72 : m_heuristic(heuristic)
73 , m_deleteHeuristic(false) { }
77 if(m_deleteHeuristic) {
83 virtual MaximalPlanarSubgraphSimple *
clone()
const override {
84 auto result =
new MaximalPlanarSubgraphSimple(*(m_heuristic.clone()));
85 result->m_deleteHeuristic =
true;
106 bool preferredImplyPlanar)
override 111 if(pCost ==
nullptr) {
112 result = m_heuristic.call(graph, preferredEdges, heuDelEdges, preferredImplyPlanar);
114 result = m_heuristic.call(graph, *pCost, preferredEdges, heuDelEdges, preferredImplyPlanar);
119 for (
edge e : heuDelEdges) {
122 for (
edge e : heuDelEdges) {
142 template<
typename TCost>
154 , m_deleteHeuristic(true)
156 , m_randomGenerator()
166 : m_heuristic(heuristic)
167 , m_deleteHeuristic(false)
168 , m_randomness(randomness)
169 , m_randomGenerator()
177 if(m_deleteHeuristic) {
183 virtual MaximalPlanarSubgraphSimple *
clone()
const override {
184 auto result =
new MaximalPlanarSubgraphSimple(*(m_heuristic.clone()), m_randomness, m_runs);
185 result->m_deleteHeuristic =
true;
194 m_randomGenerator.seed(seed);
215 bool preferredImplyPlanar)
override 226 for (
auto i=0u; i < m_runs; i++) {
230 if(pCost ==
nullptr) {
231 result = m_heuristic.call(graph, preferredEdges, heuDelEdges, preferredImplyPlanar);
233 std::uniform_real_distribution<TCost> distribution (0.0,1.0);
235 TCost maxCost = firstEdge ==
nullptr ? 0 : (*pCost)[firstEdge];
236 TCost minCost = firstEdge ==
nullptr ? 0 : (*pCost)[firstEdge];
244 TCost normalized = 1;
245 if (maxCost > minCost) {
246 normalized = ((*pCost)[e] - minCost) / (maxCost - minCost);
249 normalizedCost[e] = (1.0 - m_randomness)*normalized + m_randomness*distribution(m_randomGenerator);
251 result = m_heuristic.call(graph, normalizedCost, preferredEdges, heuDelEdges, preferredImplyPlanar);
257 if (pCost !=
nullptr) {
262 for (
edge e : heuDelEdges) {
266 delEdgesCurrentBest.
clear();
267 for (
edge e : heuDelEdges) {
276 if (pCost ==
nullptr) {
277 if (i == 0 || delEdgesCurrentBest.
size() < delEdges.
size()) {
280 for (
auto e: delEdgesCurrentBest) { delEdges.
pushBack(e); };
283 if (i == 0 || weightOfList(delEdgesCurrentBest,normalizedCost) < weightOfList(delEdges,normalizedCost)) {
286 for (
auto e: delEdgesCurrentBest) { delEdges.
pushBack(e); };
310 result += weights[e];
void clear()
Removes all elements from the list.
Computation was aborted due to an error.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
virtual ~MaximalPlanarSubgraphSimple()
Destructor.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
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.
PlanarSubgraphModule< TCost > & m_heuristic
user given heuristic
ReturnType
The return type of a module.
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic, double randomness=0.0, unsigned int runs=1)
Constructor.
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
virtual ~MaximalPlanarSubgraphSimple()
Desctructor.
void quicksort()
Sorts the list using Quicksort.
Interface for planar subgraph algorithms.
edge firstEdge() const
Returns the first edge in the list of all edges.
static void copy(const T &from, T &to)
TCost weightOfList(const List< edge > &list, const EdgeArray< TCost > &weights)
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
Class for the representation of edges.
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
Copies of graphs supporting edge splitting.
std::default_random_engine m_randomGenerator
random generator to use with std::uniform_real_distribution
void setSeed(unsigned seed)
set seed of std::default_random_engine generator to use when randomness > 0
Declaration and Implementation of class PlanarSubgraphEmpty.
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
MaximalPlanarSubgraphSimple()
Constructor.
double m_randomness
randomness of the process: use 0 to compute everything based on the costs, use 1 for completely rando...
int size() const
Returns the number of elements in the list.
Declaration of simple graph algorithms.
Implementation of disjoint sets data structures (union-find functionality).
PlanarSubgraphModule< TCost > & m_heuristic
user given heuristic
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
MaximalPlanarSubgraphSimple()
Constructor.
The namespace for all OGDF objects.
Declaration of extended graph algorithms.
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.
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic)
Constructor with user given heuristic that is executed before extending the solution to maximality...
Compare elements based on a single comparable attribute.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Dummy implementation for maximum planar subgraph that returns an empty graph.