|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
50 #include <unordered_map>
51 #include <unordered_set>
62 template<
typename TWeight>
85 std::unique_ptr<AlternatingTree<TWeight>>
m_tree;
87 #ifdef OGDF_HEAVY_DEBUG
88 void assertConsistency() {
113 if (v !=
m_tree->root()) {
134 long unsigned int hiddenNodes = 0;
135 for (
auto entry :
m_helper.pseudonodes()) {
136 auto pseudonode = entry.second;
137 hiddenNodes += pseudonode->cycle->nodes().size();
138 for (
node v : pseudonode->cycle->nodes()) {
143 == (
size_t)
m_helper.graph().numberOfNodes());
179 std::unordered_set<edge>& matching) {
180 return _doCall(G, weights, matching);
188 template<
class WeightContainer>
189 bool _doCall(
const Graph& G,
const WeightContainer& weights, std::unordered_set<edge>& matching) {
226 #ifdef OGDF_HEAVY_DEBUG
232 lout() <<
"new root: " <<
m_tree->root() << std::endl;
239 m_helper.getOriginalMatching(matching);
245 #ifdef OGDF_HEAVY_DEBUG
246 std::unordered_map<edge, TWeight> edgeWeights;
247 m_helper.getReducedEdgeWeights(edgeWeights);
251 #ifdef OGDF_HEAVY_DEBUG
252 m_helper.assertConsistentEdgeWeights(edgeWeights);
272 lout() <<
"augmented matching with " << adj->
theEdge() << std::endl;
290 if (matchingEdge && !
m_tree->contains(v)) {
292 lout() <<
"augmented tree with " << adj->
theEdge() << std::endl;
336 TWeight delta = infinity<TWeight>();
346 potentialChange *= 0.5;
347 }
else if (
m_tree->isOdd(v)) {
352 delta = std::min(delta, potentialChange);
358 delta = std::min(delta,
m_helper.y(v));
362 if (delta == infinity<TWeight>()) {
397 lout() <<
"dual change: " << delta << std::endl;
405 std::vector<std::tuple<edge, bool>> selfLoops;
414 for (
auto adj : u->adjEntries) {
415 edge e = adj->theEdge();
424 if (
m_helper.matching(newNode) ==
nullptr) {
427 lout() <<
"shrunk odd cycle of length " << cycle->
nodes().size() <<
" at " << cycleEdge
428 <<
" into pseudonode " << pseudonode->
graphNode << std::endl;
439 int pseudonodeIndex = graphNode->
index();
440 m_tree->expand(pseudonode);
445 for (
auto adj : u->adjEntries) {
446 edge e = adj->theEdge();
454 lout() <<
"expanded pseudonode " << pseudonodeIndex << std::endl;
void expand(Pseudonode *pseudonode)
Expand the pseudonode pseudonode.
bool primalChange()
Executes a primal change step.
The namespace for all OGDF objects.
Stores additional attributes of a graph (like layout information).
Declaration of class GraphAttributes which extends a Graph by additional attributes.
bool findMatching(std::unordered_set< edge > &matching)
Main function of the algorithm.
Helper class representing a pseudonode in the Blossom algorithm.
Includes declaration of graph class.
std::unordered_set< node > m_pseudonodes
All top-level pseudonodes.
Helper structure representing a pseudonode in the Blossom algorithm.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
std::unordered_set< node > m_unmatchedNodes
All nodes which are not part of the matching yet.
bool dualChange()
Executes a dual change step.
Functionality for temporarily hiding edges in constant time.
int index() const
Returns the (unique) node index.
void restoreNonEqualityEdges()
Helper function to restore all non-equality edges.
Declaration of interface for matching algorithms.
bool findMatchingAugmentation()
Finds and executes a matching augmentation, if possible.
const Graph & constGraph() const
Returns a reference to the associated graph.
Helper class for the blossom matching algorithms.
const std::unordered_set< node > & nodes()
std::unordered_set< edge > m_nonEqualityEdges
Set of all non-equality edges.
Utility class for the Blossom algorithm, providiing access to all important data structures.
Class for adjacency list elements.
std::unique_ptr< AlternatingTree< TWeight > > m_tree
The alternating tree.
Contains logging functionality.
BlossomHelper< TWeight > m_helper
Helper class to store the current state of the algorithm.
Utility class representing a cycle in the Blossom algorithm.
edge theEdge() const
Returns the edge associated with this adjacency entry.
void shrink(edge cycleEdge)
Shrink the odd cycle induced by the current tree together with cycleEdge.
Decralation of GraphElement and GraphList classes.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
bool doCall(const GraphAttributes &GA, std::unordered_set< edge > &matching)
Main call function for the algorithm with GraphAttrubtes as weight container.
Cycle * cycle
The odd-length cycle that this pseudonode represents.
Implementation of the Blossom-I algorithm by Edmonds (1965) for Minimum Weight Perfect Matching.
bool findShrinkableCycle()
Finds and shrinks an odd cycle, if possible.
Data type for general directed graphs (adjacency list representation).
std::unique_ptr< Graph::HiddenEdgeSet > m_nonEqualityEdgesHiddenSet
Pointer to the HiddenEdgeSet containing all non-equality edges.
node graphNode
The node in the graph that this pseudonode is linked to.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
bool findExpandablePseudonode()
Finds and expands an odd pseudonode, if possible.
bool _doCall(const Graph &G, const WeightContainer &weights, std::unordered_set< edge > &matching)
Helper for the main call function since abstract functions cannot be templated.
bool findTreeAugmentation()
Finds and executes a tree augmentation, if possible.
MatchingBlossom(bool greedyInit=true)
Construct a MatchingBlossom instance.
node getNewRoot()
Helper function to get a new root for the tree.
std::unordered_set< node > m_graphNodes
All nodes currently present in the graph.
Basic declarations, included by all source files.
Utility functions and classes regarding map access and iteration.
Implementation of an Alternating Tree helper structure for the Blossom algorithm.
Class for the representation of edges.
void hideNonEqualityEdges()
Helper function to hide all non-equality edges.
bool doCall(const Graph &G, const EdgeArray< TWeight > &weights, std::unordered_set< edge > &matching)
Main call function for the algorithm with an EdgeArray as weight container.
Class for the representation of nodes.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
std::ostream & lout(Level level=Level::Default, bool indent=true) const
stream for logging-output (local)