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/Graph.h>
38 
39 namespace ogdf {
40 namespace matching_blossom {
41 
42 template<class TWeight>
43 class AuxGraph;
44 
48 template<class TWeight>
49 class BlossomVHelper : public BlossomHelper<TWeight> {
52 
54  template<class E>
56  if (!pq.empty()) {
57  return pq.topElement();
58  }
59  return nullptr;
60  }
61 
62 protected:
64 
65 public:
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  }
86  m_auxGraph->reset();
87  currentIteration = 0;
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::matching_blossom::BlossomHelper::m_eps
EpsilonTest m_eps
The epsilon test used for floating point comparisons.
Definition: BlossomHelper.h:85
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:81
ogdf::matching_blossom::BlossomHelper::m_y
NodeArray< TWeight > m_y
Definition: BlossomHelper.h:70
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:116
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:129
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:93
ogdf::matching_blossom::BlossomVHelper::currentIteration
long currentIteration
The current iteration of the algorithm.
Definition: BlossomVHelper.h:70
ogdf::matching_blossom::BlossomHelper
Helper class for the blossom matching algorithms.
Definition: AlternatingTree.h:52
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:63
ogdf::matching_blossom::BlossomVHelper::BlossomVHelper
BlossomVHelper(bool greedyInit)
Construct a new Blossom V Helper object.
Definition: BlossomVHelper.h:77
ogdf::PriorityQueue::empty
bool empty() const
Checks whether the queue is empty.
Definition: PriorityQueue.h:211
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::pq_internal::PrioritizedQueue::topElement
const E & topElement() const
Returns the topmost element in the queue.
Definition: PriorityQueue.h:286
ogdf::matching_blossom::BlossomVHelper::realValue
TWeight realValue(node v)
Returns the realY of v.
Definition: BlossomVHelper.h:108
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:55
utils.h
Utility functions and classes regarding map access and iteration.
ogdf::matching_blossom::AuxGraph
Definition: AuxGraph.h:215
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
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:99
ogdf::matching_blossom::BlossomPQ
A custom priority queue for the blossom algorithm, based on the PrioritizedMapQueue....
Definition: PQ.h:51
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:401
ogdf::matching_blossom::BlossomVHelper::realValue
TWeight realValue(edge e)
Returns the realReducedWeight of e.
Definition: BlossomVHelper.h:105
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::matching_blossom::BlossomVHelper::isZeroCostNode
bool isZeroCostNode(node v)
Checks if the realValue of b is zero.
Definition: BlossomVHelper.h:111