26 #ifndef OR_TOOLS_GRAPH_PERFECT_MATCHING_H_ 27 #define OR_TOOLS_GRAPH_PERFECT_MATCHING_H_ 33 #include "absl/strings/str_cat.h" 34 #include "absl/strings/str_join.h" 62 void Reset(
int num_nodes);
104 DCHECK(optimal_solution_found_);
105 return optimal_cost_;
111 DCHECK(optimal_solution_found_);
112 return matches_[node];
115 DCHECK(optimal_solution_found_);
120 std::unique_ptr<BlossomGraph> graph_;
126 bool optimal_solution_found_ =
false;
127 int64_t optimal_cost_ = 0;
128 int64_t maximum_edge_cost_ = 0;
129 std::vector<int> matches_;
353 int NumMatched()
const {
return nodes_.size() - unmatched_nodes_.size(); }
409 void AppendNodePathToRoot(
NodeIndex n, std::vector<NodeIndex>* path)
const;
422 return root_blossom_node_[edge.tail];
425 return root_blossom_node_[edge.head];
432 return root_blossom_node_[edge.OtherEnd(node)];
449 const std::vector<NodeIndex>& SubNodes(
NodeIndex n);
452 bool is_initialized_ =
false;
467 std::vector<NodeIndex> subnodes_;
473 std::vector<NodeIndex> unmatched_nodes_;
476 std::vector<EdgeIndex> primal_update_edge_queue_;
477 std::vector<EdgeIndex> possible_shrink_;
482 std::vector<Edge*> tmp_all_tops_;
489 int64_t num_grows_ = 0;
490 int64_t num_augments_ = 0;
491 int64_t num_shrinks_ = 0;
492 int64_t num_expands_ = 0;
493 int64_t num_dual_updates_ = 0;
498 #endif // OR_TOOLS_GRAPH_PERFECT_MATCHING_H_
NodeIndex Match(NodeIndex n) const
const Edge & GetEdge(int e) const
std::vector< NodeIndex > saved_blossom
int Match(int node) const
bool operator>(const Edge &other) const
CostValue saved_pseudo_dual
CostValue Slack(const Edge &edge) const
CostValue ComputeMaxCommonTreeDualDeltaAndResetPrimalEdgeQueue()
void DebugCheckNoPossiblePrimalUpdates()
void AddEdge(NodeIndex tail, NodeIndex head, CostValue cost)
void UpdateAllTrees(CostValue delta)
std::string EdgeDebugString(EdgeIndex e) const
void DebugUpdateNodeDual(NodeIndex n, CostValue delta)
static const EdgeIndex kNoEdgeIndex
std::vector< NodeIndex > blossom
NodeIndex OtherEnd(NodeIndex n) const
CostValue Dual(const Node &node) const
std::string DebugString() const
bool DebugEdgeIsTightAndExternal(const Edge &edge) const
Edge(NodeIndex t, NodeIndex h, CostValue c)
int64_t OptimalCost() const
void AddEdgeWithCost(int tail, int head, int64_t cost)
ABSL_MUST_USE_RESULT Status Solve()
ABSL_MUST_USE_RESULT bool Initialize()
void Grow(EdgeIndex e, NodeIndex tail, NodeIndex head)
std::string NodeDebugString(NodeIndex n) const
DEFINE_INT_TYPE(NodeIndex, int)
void SetHeapIndex(int index)
CostValue tree_dual_delta
#define DCHECK(condition)
static const NodeIndex kNoNodeIndex
bool DebugDualsAreFeasible() const
#define DCHECK_EQ(val1, val2)
void Augment(EdgeIndex e)
const Node & GetNode(int n) const
BlossomGraph(int num_nodes)
Collection of objects used to extend the Constraint Solver library.
const std::vector< int > & Matches() const
bool NodeIsMatched(NodeIndex n) const
static const CostValue kMaxCostValue
void Expand(NodeIndex to_expand)
void DisplayStats() const
MinCostPerfectMatching(int num_nodes)
void Reset(int num_nodes)
CostValue DualObjective() const