26#ifndef OR_TOOLS_GRAPH_PERFECT_MATCHING_H_
27#define OR_TOOLS_GRAPH_PERFECT_MATCHING_H_
33#include "absl/base/attributes.h"
34#include "absl/strings/str_cat.h"
35#include "absl/strings/str_join.h"
63 void Reset(
int num_nodes);
105 DCHECK(optimal_solution_found_);
106 return optimal_cost_;
112 DCHECK(optimal_solution_found_);
113 return matches_[node];
116 DCHECK(optimal_solution_found_);
121 std::unique_ptr<BlossomGraph> graph_;
127 bool optimal_solution_found_ =
false;
128 int64_t optimal_cost_ = 0;
129 int64_t maximum_edge_cost_ = 0;
130 std::vector<int> matches_;
410 void AppendNodePathToRoot(
NodeIndex n, std::vector<NodeIndex>* path)
const;
423 return root_blossom_node_[edge.tail];
426 return root_blossom_node_[edge.head];
433 return root_blossom_node_[edge.OtherEnd(node)];
450 const std::vector<NodeIndex>& SubNodes(
NodeIndex n);
453 bool is_initialized_ =
false;
468 std::vector<NodeIndex> subnodes_;
474 std::vector<NodeIndex> unmatched_nodes_;
477 std::vector<EdgeIndex> primal_update_edge_queue_;
478 std::vector<EdgeIndex> possible_shrink_;
483 std::vector<Edge*> tmp_all_tops_;
490 int64_t num_grows_ = 0;
491 int64_t num_augments_ = 0;
492 int64_t num_shrinks_ = 0;
493 int64_t num_expands_ = 0;
494 int64_t num_dual_updates_ = 0;
#define DCHECK(condition)
#define DCHECK_EQ(val1, val2)
bool DebugDualsAreFeasible() const
DEFINE_STRONG_INT_TYPE(CostValue, int64_t)
ABSL_MUST_USE_RESULT bool Initialize()
const Node & GetNode(int n) const
CostValue DualObjective() const
void Grow(EdgeIndex e, NodeIndex tail, NodeIndex head)
CostValue ComputeMaxCommonTreeDualDeltaAndResetPrimalEdgeQueue()
bool DebugEdgeIsTightAndExternal(const Edge &edge) const
static const CostValue kMaxCostValue
NodeIndex Match(NodeIndex n) const
void AddEdge(NodeIndex tail, NodeIndex head, CostValue cost)
const Edge & GetEdge(int e) const
bool NodeIsMatched(NodeIndex n) const
CostValue Slack(const Edge &edge) const
std::string NodeDebugString(NodeIndex n) const
std::string EdgeDebugString(EdgeIndex e) const
void DebugCheckNoPossiblePrimalUpdates()
std::string DebugString() const
void Augment(EdgeIndex e)
DEFINE_STRONG_INT_TYPE(NodeIndex, int)
CostValue Dual(const Node &node) const
static const EdgeIndex kNoEdgeIndex
static const NodeIndex kNoNodeIndex
void Expand(NodeIndex to_expand)
DEFINE_STRONG_INT_TYPE(EdgeIndex, int)
void UpdateAllTrees(CostValue delta)
void DisplayStats() const
void DebugUpdateNodeDual(NodeIndex n, CostValue delta)
BlossomGraph(int num_nodes)
ABSL_MUST_USE_RESULT Status Solve()
void AddEdgeWithCost(int tail, int head, int64_t cost)
int Match(int node) const
void Reset(int num_nodes)
const std::vector< int > & Matches() const
MinCostPerfectMatching(int num_nodes)
int64_t OptimalCost() const
Collection of objects used to extend the Constraint Solver library.
Edge(NodeIndex t, NodeIndex h, CostValue c)
bool operator>(const Edge &other) const
void SetHeapIndex(int index)
NodeIndex OtherEnd(NodeIndex n) const
CostValue tree_dual_delta
std::vector< NodeIndex > blossom
CostValue saved_pseudo_dual
std::vector< NodeIndex > saved_blossom