Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
BlossomVHelper.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
38
39namespace ogdf {
40namespace matching_blossom {
41
42template<class TWeight>
43class AuxGraph;
44
48template<class TWeight>
49class BlossomVHelper : public BlossomHelper<TWeight> {
50 using BlossomHelper<TWeight>::m_y;
51 using BlossomHelper<TWeight>::m_eps;
52
54 template<class E>
56 if (!pq.empty()) {
57 return pq.topElement();
58 }
59 return nullptr;
60 }
61
62protected:
64
65public:
66 using BlossomHelper<TWeight>::c;
67 using BlossomHelper<TWeight>::isZero;
68
71
77 BlossomVHelper(bool greedyInit) : BlossomHelper<TWeight>(greedyInit) { }
78
80 template<class WeightContainer>
81 bool init(const Graph& graph, const WeightContainer& weights, AuxGraph<TWeight>* auxGraph) {
82 m_auxGraph = auxGraph;
83 if (!BlossomHelper<TWeight>::init(graph, weights)) {
84 return false;
85 }
88 return true;
89 }
90
93 TWeight getRealReducedWeight(edge e) override {
94 return c(e) - realY(e->source()) - realY(e->target());
95 }
96
99 TWeight realY(node v) {
100 auto auxNode = m_auxGraph->treeAuxNode(v);
101 return m_y[v] + (auxNode ? auxNode->delta(v) : 0);
102 }
103
105 TWeight realValue(edge e) { return getRealReducedWeight(e); }
106
108 TWeight realValue(node v) { return realY(v); }
109
111 bool isZeroCostNode(node v) { return isZero(realY(v)); }
112
115 template<class E>
117 if (!pq.empty()) {
118 E el = pq.topElement();
119 if (isZero(realValue(el))) {
120 return el;
121 }
122 }
123 return nullptr;
124 }
125
128 template<class E>
130 auto el = getTopElement(pq);
131 if (el == nullptr) {
132 return infinity<TWeight>();
133 } else {
134 return realValue(el);
135 }
136 }
137};
138
139}
140}
Utility class for the Blossom algorithm, providiing access to all important data structures.
Includes declaration of graph class.
An extension of the standard priority queue with additional features.
Class for the representation of edges.
Definition Graph_d.h:364
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Class for the representation of nodes.
Definition Graph_d.h:241
bool empty() const
Checks whether the queue is empty.
void reset()
Rebuilds the auxiliary graph from the current graph.
Definition AuxGraph.h:273
Helper class for the blossom matching algorithms.
TWeight & c(edge e)
Returns the base edge weight of e.
EpsilonTest m_eps
The epsilon test used for floating point comparisons.
bool isZero(TWeight x)
Helper function to determine whether a floating point value is 0.
A custom priority queue for the blossom algorithm, based on the PrioritizedMapQueue....
Definition PQ.h:53
Helper class for the blossom matching algorithms.
long currentIteration
The current iteration of the algorithm.
bool init(const Graph &graph, const WeightContainer &weights, AuxGraph< TWeight > *auxGraph)
Initialize the helper with the given data.
TWeight getRealReducedWeight(edge e) override
Gets the actual reduced weight of the edge, taking into account the delta of the corresponding trees.
BlossomVHelper(bool greedyInit)
Construct a new Blossom V Helper object.
E getTopEligibleElement(BlossomPQ< E, TWeight > &pq)
Checks if the top element of the given pq has realValue == 0 and returns it, if possible.
bool isZeroCostNode(node v)
Checks if the realValue of b is zero.
TWeight realValue(edge e)
Returns the realReducedWeight of e.
TWeight getRealTopPriority(BlossomPQ< E, TWeight > &pq)
Returns the real value (realReducedWeight or realY) of the top element in the priority queue,...
TWeight realValue(node v)
Returns the realY of v.
E getTopElement(BlossomPQ< E, TWeight > &pq)
Helper function to get the top element of any priority queue.
TWeight realY(node v)
Returns the actual y value of the node, taking into account the delta of the corresponding tree.
const E & topElement() const
Returns the topmost element in the queue.
Utility functions and classes regarding map access and iteration.
The namespace for all OGDF objects.