# C++ Reference: class BlossomGraph

Note: This documentation is automatically generated.

Class containing the main data structure used by the Blossom algorithm.At the core is the original undirected graph. During the algorithm execution we might collapse nodes into so-called Blossoms. A Blossom is a cycle of external nodes (which can be blossom nodes) of odd length (>= 3). The edges of the cycle are called blossom-forming eges and will always be tight (i.e. have a slack of zero). Once a Blossom is created, its nodes become "internal" and are basically considered merged into the blossom node for the rest of the algorithm (except if we later re-expand the blossom).

Moreover, external nodes of the graph will have 3 possible types ([+], [-] and free [0]). Free nodes will always be matched together in pairs. Nodes of type [+] and [-] are arranged in a forest of alternating [+]/[-] disjoint trees. Each unmatched node is the root of a tree, and of type [+]. Nodes [-] will always have exactly one child to witch they are matched. [+] nodes can have any number of [-] children, to which they are not matched. All the edges of the trees will always be tight. Some examples below, double edges are used for matched nodes:

A matched pair of free nodes: [0] === [0]

A possible rooted tree: [+] -- [-] ==== [+] \ [-] ==== [+] ---- [-] === [+] \ [-] === [+]

A single unmatched node is also a tree: [+]

TODO(user): For now this class does not maintain a second graph of edges between the trees nor does it maintains priority queue of edges.

TODO(user): For now we use CHECKs in many places to facilitate development. Switch them to DCHECKs for speed once the code is more stable.

Method | |
---|---|

`AddEdge` | Return type: Arguments: Same comment as MinCostPerfectMatching::AddEdgeWithCost() applies. |

`Augment` | Return type: Arguments: Merges two tree and augment the number of matched nodes by 1. This is the only functions that change the current matching. |

`BlossomGraph` | Return type: Arguments: Creates a BlossomGraph on the given number of nodes. |

`ComputeMaxCommonTreeDualDeltaAndResetPrimalEdgeQueue` | Return type: Computes the maximum possible delta for UpdateAllTrees() that keeps the dual feasibility. Dual update approach (2) from the paper. This also fills primal_update_edge_queue_. |

`DebugCheckNoPossiblePrimalUpdates` | Return type: Checks that there is no possible primal update in the current configuration. |

`DebugDualsAreFeasible` | Return type: Tests that the dual values are currently feasible. This should ALWAYS be the case. |

`DebugEdgeIsTightAndExternal` | Return type: Arguments: Returns true iff this is an external edge with a slack of zero. An external edge is an edge between two external nodes. |

`DebugString` | Return type: |

`DebugUpdateNodeDual` | Return type: Arguments: In debug mode, we maintain the real slack of each edges and the real dual of each node via this function. Both Slack() and Dual() checks in debug mode that the value computed is the correct one. |

`DEFINE_INT_TYPE` | Arguments: Typed index used by this class. |

`DEFINE_INT_TYPE` | Arguments: |

`DEFINE_INT_TYPE` | Arguments: |

`DisplayStats` | Return type: Display to VLOG(1) some statistic about the solve. |

`Dual` | Return type: Arguments: Returns the dual value of the given node (which might be a pseudo-node). |

`DualObjective` | Return type: Returns the current dual objective which is always a valid lower-bound on the min-cost matching. Note that this is capped to kint64max in case of overflow. Because all of our cost are positive, this starts at zero. |

`EdgeDebugString` | Return type: Arguments: |

`Expand` | Return type: Arguments: Expands a Blossom into its component. |

`ExpandAllBlossoms` | Return type: This must be called at the end of the algorithm to recover the matching. |

`GetEdge` | Return type: Arguments: Getters to access node/edges from outside the class. Only used in tests. |

`GetNode` | Return type: Arguments: |

`Grow` | Return type: Arguments: Adds to the tree of tail the free matched pair(head, Match(head)). The edge is only used in DCHECKs. We duplicate tail/head because the order matter here. |

`Initialize` | Return type: Heuristic to start with a dual-feasible solution and some matched edges. To be called once all edges are added. Returns false if the problem is detected to be INFEASIBLE. |

`Match` | Return type: Arguments: Returns the node matched to the given one, or n if this node is not currently matched. |

`NodeDebugString` | Return type: Arguments: Display information for debugging. |

`NodeIsMatched` | Return type: Arguments: Returns true iff this node is matched and is thus not a tree root. This cannot live in the Node class because we need to know the NodeIndex. |

`NumMatched` | Return type: Returns the current number of matched nodes. |

`PrimalUpdates` | Return type: Enters a loop that perform one of Grow()/Augment()/Shrink()/Expand() until a fixed point is reached. |

`Shrink` | Return type: Arguments: Creates a Blossom using the given [+] -- [+] edge between two nodes of the same tree. |

`Slack` | Return type: Arguments: Return the "slack" of the given edge. |

`UpdateAllTrees` | Return type: Arguments: Applies the same dual delta to all trees. Dual update approach (2) from the paper. |