Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

BlossomVHelper.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/EdgeArray.h>
35 #include <ogdf/basic/Graph.h>
40 
41 namespace ogdf {
42 namespace matching_blossom {
43 
44 template<class TWeight>
45 class AuxGraph;
46 
50 template<class TWeight>
51 class BlossomVHelper : public BlossomHelper<TWeight> {
54 
56  template<class E>
58  if (!pq.empty()) {
59  return pq.topElement();
60  }
61  return nullptr;
62  }
63 
64 protected:
66 
67 public:
70 
73 
79  BlossomVHelper(bool greedyInit) : BlossomHelper<TWeight>(greedyInit) { }
80 
82  template<class WeightContainer>
83  bool init(const Graph& graph, const WeightContainer& weights, AuxGraph<TWeight>* auxGraph) {
84  m_auxGraph = auxGraph;
85  if (!BlossomHelper<TWeight>::init(graph, weights)) {
86  return false;
87  }
88  m_auxGraph->reset();
89  currentIteration = 0;
90  return true;
91  }
92 
95  TWeight getRealReducedWeight(edge e) override {
96  return c(e) - realY(e->source()) - realY(e->target());
97  }
98 
101  TWeight realY(node v) {
102  auto auxNode = m_auxGraph->treeAuxNode(v);
103  return m_y[v] + (auxNode ? auxNode->delta(v) : 0);
104  }
105 
107  TWeight realValue(edge e) { return getRealReducedWeight(e); }
108 
110  TWeight realValue(node v) { return realY(v); }
111 
113  bool isZeroCostNode(node v) { return isZero(realY(v)); }
114 
117  template<class E>
119  if (!pq.empty()) {
120  E el = pq.topElement();
121  if (isZero(realValue(el))) {
122  return el;
123  }
124  }
125  return nullptr;
126  }
127 
130  template<class E>
132  auto el = getTopElement(pq);
133  if (el == nullptr) {
134  return infinity<TWeight>();
135  } else {
136  return realValue(el);
137  }
138  }
139 };
140 
141 }
142 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::matching_blossom::BlossomHelper::m_eps
EpsilonTest m_eps
The epsilon test used for floating point comparisons.
Definition: BlossomHelper.h:80
Graph.h
Includes declaration of graph class.
PQ.h
An extension of the standard priority queue with additional features.
ogdf::matching_blossom::BlossomVHelper::init
bool init(const Graph &graph, const WeightContainer &weights, AuxGraph< TWeight > *auxGraph)
Initialize the helper with the given data.
Definition: BlossomVHelper.h:83
ogdf::matching_blossom::BlossomHelper::m_y
NodeArray< TWeight > m_y
Definition: BlossomHelper.h:65
ogdf::matching_blossom::BlossomVHelper::getTopEligibleElement
E getTopEligibleElement(BlossomPQ< E, TWeight > &pq)
Checks if the top element of the given pq has realValue == 0 and returns it, if possible.
Definition: BlossomVHelper.h:118
ogdf::matching_blossom::BlossomVHelper::getRealTopPriority
TWeight getRealTopPriority(BlossomPQ< E, TWeight > &pq)
Returns the real value (realReducedWeight or realY) of the top element in the priority queue,...
Definition: BlossomVHelper.h:131
ogdf::matching_blossom::BlossomVHelper::getRealReducedWeight
TWeight getRealReducedWeight(edge e) override
Gets the actual reduced weight of the edge, taking into account the delta of the corresponding trees.
Definition: BlossomVHelper.h:95
ogdf::matching_blossom::BlossomVHelper::currentIteration
long currentIteration
The current iteration of the algorithm.
Definition: BlossomVHelper.h:72
ogdf::matching_blossom::BlossomHelper
Helper class for the blossom matching algorithms.
Definition: BlossomHelper.h:55
BlossomHelper.h
Utility class for the Blossom algorithm, providiing access to all important data structures.
ogdf::matching_blossom::BlossomVHelper::m_auxGraph
AuxGraph< TWeight > * m_auxGraph
Definition: BlossomVHelper.h:65
ogdf::matching_blossom::BlossomVHelper::BlossomVHelper
BlossomVHelper(bool greedyInit)
Construct a new Blossom V Helper object.
Definition: BlossomVHelper.h:79
ogdf::PriorityQueue::empty
bool empty() const
Checks whether the queue is empty.
Definition: PriorityQueue.h:209
EdgeArray.h
Declaration and implementation of EdgeArray class.
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:391
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::pq_internal::PrioritizedQueue::topElement
const E & topElement() const
Returns the topmost element in the queue.
Definition: PriorityQueue.h:284
ogdf::matching_blossom::BlossomVHelper::realValue
TWeight realValue(node v)
Returns the realY of v.
Definition: BlossomVHelper.h:110
ogdf::matching_blossom::BlossomVHelper::getTopElement
E getTopElement(BlossomPQ< E, TWeight > &pq)
Helper function to get the top element of any priority queue.
Definition: BlossomVHelper.h:57
utils.h
Utility functions and classes regarding map access and iteration.
ogdf::matching_blossom::AuxGraph
Definition: AuxGraph.h:218
AuxGraph.h
Implementation of the auxiliary graph as well as the edges and nodes of it for the Blossom V algorith...
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::matching_blossom::BlossomVHelper::realY
TWeight realY(node v)
Returns the actual y value of the node, taking into account the delta of the corresponding tree.
Definition: BlossomVHelper.h:101
ogdf::matching_blossom::BlossomPQ
A custom priority queue for the blossom algorithm, based on the PrioritizedMapQueue....
Definition: PQ.h:49
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:394
ogdf::matching_blossom::BlossomVHelper::realValue
TWeight realValue(edge e)
Returns the realReducedWeight of e.
Definition: BlossomVHelper.h:107
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::matching_blossom::BlossomVHelper::isZeroCostNode
bool isZeroCostNode(node v)
Checks if the realValue of b is zero.
Definition: BlossomVHelper.h:113