|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
47 #include <type_traits>
53 template<
typename TCost,
class Enable =
void>
54 class MaximalPlanarSubgraphSimple { };
66 template<
typename TCost>
67 class 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);
120 for (
edge e : heuDelEdges) {
123 for (
edge e : heuDelEdges) {
141 template<
typename TCost>
142 class 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];
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);
249 if (pCost !=
nullptr) {
251 heuDelEdges.quicksort(cmp);
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];
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
The namespace for all OGDF objects.
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
Interface for planar subgraph algorithms.
Includes declaration of graph class.
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic)
Constructor with user given heuristic that is executed before extending the solution to maximality.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
PlanarSubgraphModule< TCost > & m_heuristic
user given heuristic
MaximalPlanarSubgraphSimple(PlanarSubgraphModule< TCost > &heuristic, double randomness=0.0, unsigned int runs=1)
Constructor.
Declaration of extended graph algorithms.
MaximalPlanarSubgraphSimple()
Constructor.
virtual ~MaximalPlanarSubgraphSimple()
Destructor.
Copies of graphs supporting edge splitting.
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
Declaration and Implementation of class PlanarSubgraphEmpty. Heuristic: We obtain a planar subgraph b...
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
static void copy(const T &from, T &to)
@ Error
Computation was aborted due to an error.
Declaration of interface for planar subgraph algorithms.
Decralation of GraphElement and GraphList classes.
MaximalPlanarSubgraphSimple()
Constructor.
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Declaration of graph copy classes.
Data type for general directed graphs (adjacency list representation).
double m_randomness
randomness of the process: use 0 to compute everything based on the costs, use 1 for completely rando...
edge firstEdge() const
Returns the first edge in the list of all edges.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
unsigned int m_runs
number of runs when algorithms is randomized
void updateMax(T &max, const T &newValue)
Stores the maximum of max and newValue in max.
Basic declarations, included by all source files.
virtual ~MaximalPlanarSubgraphSimple()
Desctructor.
TCost weightOfList(const List< edge > &list, const EdgeArray< TCost > &weights)
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
Dummy implementation for maximum planar subgraph that returns an empty graph.
Class for the representation of edges.
Declaration of doubly linked lists and iterators.
int size() const
Returns the number of elements in the list.
Declares base class for all module types.
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.
std::default_random_engine m_randomGenerator
random generator to use with std::uniform_real_distribution
virtual MaximalPlanarSubgraphSimple * clone() const override
Clone method.
ReturnType
The return type of a module.
bool m_deleteHeuristic
flag to store we have to delete a self created heuristic
Declarations for Comparer objects.
Compare elements based on a single comparable attribute.
void setSeed(unsigned seed)
set seed of std::default_random_engine generator to use when randomness > 0
iterator pushBack(const E &x)
Adds element x at the end of the list.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
void clear()
Removes all elements from the list.