|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
45 #include <unordered_map>
46 #include <unordered_set>
51 template<
class TWeight>
56 namespace matching_blossom {
58 template<
class TWeight>
80 std::unordered_set<node> potentialIntersections = {e->
source(), e->
target()};
84 for (
node& n : nodes) {
87 if (potentialIntersections.find(n) != potentialIntersections.end()) {
90 potentialIntersections.insert(n);
119 while (start !=
end) {
126 if (oldNode == e->
source()) {
127 m_helper.graph().moveSource(e, newNode);
129 m_helper.graph().moveTarget(e, newNode);
200 std::vector<edge> stack;
202 for (
auto it = stack.rbegin(); it != stack.rend(); ++it) {
211 m_helper.addToMatching(startingEdge);
223 std::unordered_map<node, edge> edgeMap;
224 std::unordered_map<node, std::vector<edge>> selfLoops;
225 node matchingNode =
nullptr, backNode =
nullptr;
229 if (matchingEdge !=
nullptr && !cycle->
contains(matchingEdge->
opposite(u))) {
230 matchingNode = matchingEdge->
opposite(u);
243 for (
edge e : edges) {
244 node v = e->opposite(u);
246 auto it = edgeMap.find(v);
247 bool firstEdge = it == edgeMap.end();
248 bool betterEdge = firstEdge
250 m_helper.getRealReducedWeight(it->second));
252 edge selfLoop = betterEdge ? it->second : e;
254 selfLoops[loopNode].push_back(selfLoop);
266 std::unordered_map<node, edge> selfLoopMap;
269 for (
edge e : selfLoops[u]) {
270 node v = e->opposite(u);
271 edge bestEdge = edgeMap[v];
280 _selfLoops.push_back(std::make_tuple(e, even));
294 for (
auto entry : edgeMap) {
295 node v = entry.first;
296 edge e = entry.second;
302 m_evenNodes[newNode] = backNode ? edgeMap[backNode] :
nullptr;
304 m_helper.addToMatching(edgeMap[matchingNode]);
313 auto cycle = pseudonode->
cycle;
318 for (
edge e : refEdges) {
326 while (!refEdges.empty()) {
327 edge refEdge = refEdges.popFrontRet();
329 refEdges.pushBack(e);
331 std::tie(source, target) =
m_helper.getBaseNodes(e);
334 if (currentSource == graphNode) {
353 for (
node u : cycle->nodes()) {
356 for (
edge e : inEdges) {
366 node startCycleNode = cycle->startNode();
371 startCycleNode =
m_helper.reprChild(origStart);
376 node origEnd =
m_helper.getBaseNode(matchingEdge, graphNode);
379 m_helper.addToMatching(matchingEdge);
381 size_t startNodeEdgeIndex, endNodeEdgeIndex;
382 std::tie(startNodeEdgeIndex, endNodeEdgeIndex) = cycle->indexOf(startCycleNode, endCycleNode);
389 auto edges = cycle->edgeOrder();
390 bool moveForward = (endNodeEdgeIndex - startNodeEdgeIndex) % 2
391 == (startNodeEdgeIndex < endNodeEdgeIndex);
392 node currentNode = endCycleNode;
393 for (
size_t i = 0; i < edges.size() - 1; ++i) {
394 int index = endNodeEdgeIndex;
398 index += edges.size() - i;
400 edge e = edges[index % edges.size()];
404 if (currentNode != startCycleNode) {
410 currentNode = e->
opposite(currentNode);
415 m_helper.removePseudonode(pseudonode);
The namespace for all OGDF objects.
Dummy class for scoped iteration of a std::unordered_map.
Helper class representing a pseudonode in the Blossom algorithm.
void augmentMatching(edge startingEdge)
Augment the matching along the path from startingEdge to the root. startingEdge must be incident to a...
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Includes declaration of graph class.
ReferenceEdges referenceEdges
The ReferenceEdges for self loops of this pseudonode.
void addEdge(edge e)
Use this method to add edges in cycle order.
Helper structure representing a pseudonode in the Blossom algorithm.
Cycle * getCycle(edge cycleEdge)
Return the odd-length cycle which is closed in this tree with cycleEdge.
BlossomHelper< TWeight > & m_helper
Reference to the helper class.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
std::unordered_map< node, edge > m_evenNodes
All even nodes, mapped to their respective back edge in the tree (or nullptr for the root).
void reset(node root=nullptr)
Reset the tree with new the new root. If root is nullptr, the tree will be invalid.
EpsilonTest m_eps
Epsilon test for floating point numbers.
std::function< void(edge, bool)> IteratorCallback
Type of callback function when iterating the tree.
Helper class for the blossom matching algorithms.
const std::unordered_set< node > & nodes()
node commonNode(edge e)
Finds the common node between e and the tree. If both nodes are in the tree, only the source node is ...
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
edge evenBackEdge(node v)
Utility class representing a cycle in the Blossom algorithm.
node m_root
The root of the tree. May be empty to signalize an invalid tree which needs to be rebuild.
void addReference(edge ref, edge selfLoop, Pseudonode *other)
Add a self loop selfLoop which was removed because of the reference edge ref and pointed previously t...
void grow(node u, edge e, edge f)
Grow the tree by adding e and f.
KeyIteratorContainer< node, edge > evenNodes
Cycle * cycle
The odd-length cycle that this pseudonode represents.
std::unordered_set< edge > & selfLoops(edge ref)
KeyIteratorContainer< node, edge > oddNodes
node source() const
Returns the source node of the edge.
V * tryGetPointerFromMap(const std::unordered_map< K, V * > &map, const K &key)
Return the pointer belonging to key key int the given map map, or nullptr if key does not exist.
node graphNode
The node in the graph that this pseudonode is linked to.
AlternatingTree(BlossomHelper< TWeight > &helper, node root=nullptr)
void adjEdges(EDGELIST &edgeList) const
Returns a list with all edges incident to this node.
Basic declarations, included by all source files.
void iterateTree(node start, node end, IteratorCallback callback)
Iterate the tree from start to end. callback is executed for each edge on the path....
void removeFromOther(edge selfLoop)
Remove the given selfLoop from the reference edges of the other pseudonode.
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
bool contains(node v)
Whether the cycle contains the node v or not.
Utility functions and classes regarding map access and iteration.
node findCycleStartNode(edge e)
Find the node where the paths from both endpoints of e to the root first meet.
void moveEdge(edge e, node oldNode, node newNode)
Exchange the end node oldNode of edge e in graph graph for node newNode.
node opposite(node v) const
Returns the adjacent node different from v.
Class for the representation of edges.
Declaration of doubly linked lists and iterators.
const Graph * graphOf() const
Returns the graph containing this node (debug only).
node target() const
Returns the target node of the edge.
Pseudonode * shrink(Cycle *cycle, std::vector< std::tuple< edge, bool >> &_selfLoops)
Shrink the cycle in this tree and return the generated pseudonode.
std::unordered_map< node, edge > m_oddNodes
All odd nodes, mapped to their respective back edge in the tree.
Class for the representation of nodes.
node getNextEvenNode(node v, IteratorCallback callback=nullptr)
Return the next even node in root direction. v must be even. callback is executed for both edges on t...
void expand(Pseudonode *pseudonode)
Expand the given pseudonode in this tree.