Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
hungarian.h
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// An O(n^4) implementation of the Kuhn-Munkres algorithm (a.k.a. the
15// Hungarian algorithm) for solving the assignment problem.
16// The assignment problem takes a set of agents, a set of tasks and a
17// cost associated with assigning each agent to each task and produces
18// an optimal (i.e., least cost) assignment of agents to tasks.
19// The code also enables computing a maximum assignment by changing the
20// input matrix.
21
22#ifndef OR_TOOLS_ALGORITHMS_HUNGARIAN_H_
23#define OR_TOOLS_ALGORITHMS_HUNGARIAN_H_
24
25#include <vector>
26
27#include "absl/container/flat_hash_map.h"
28#include "absl/types/span.h"
29
30namespace operations_research {
31
32// See IMPORTANT NOTE at the top of the file.
34 absl::Span<const std::vector<double>> cost,
35 absl::flat_hash_map<int, int>* direct_assignment,
36 absl::flat_hash_map<int, int>* reverse_assignment);
37
38// See IMPORTANT NOTE at the top of the file.
40 absl::Span<const std::vector<double>> cost,
41 absl::flat_hash_map<int, int>* direct_assignment,
42 absl::flat_hash_map<int, int>* reverse_assignment);
43
44} // namespace operations_research
45
46#endif // OR_TOOLS_ALGORITHMS_HUNGARIAN_H_
In SWIG mode, we don't want anything besides these top-level includes.
void MinimizeLinearAssignment(absl::Span< const std::vector< double > > cost, absl::flat_hash_map< int, int > *direct_assignment, absl::flat_hash_map< int, int > *reverse_assignment)
See IMPORTANT NOTE at the top of the file.
Definition hungarian.cc:655
void MaximizeLinearAssignment(absl::Span< const std::vector< double > > cost, absl::flat_hash_map< int, int > *direct_assignment, absl::flat_hash_map< int, int > *reverse_assignment)
See IMPORTANT NOTE at the top of the file.
Definition hungarian.cc:673