47 cout <<
"=== Basic Assignment (4x4 workers-to-tasks) ===" <<
endl;
49 cout <<
"Cost matrix:" <<
endl;
50 cout <<
" Task0 Task1 Task2 Task3" <<
endl;
51 cout <<
"W0: 82 83 69 92" <<
endl;
52 cout <<
"W1: 77 37 49 92" <<
endl;
53 cout <<
"W2: 11 69 5 86" <<
endl;
54 cout <<
"W3: 8 9 98 23" <<
endl;
65 cout <<
"Assignments:" <<
endl;
66 for (
auto [
r, c] :
ha.get_assignments())
67 cout <<
" Worker " <<
r <<
" -> Task " << c <<
endl;
71 constexpr int costs[4][4] = {
77 cout <<
"Detailed:" <<
endl;
78 for (
auto [
r, c] :
ha.get_assignments())
79 cout <<
" Worker " <<
r <<
" -> Task " << c
93 cout <<
"=== Maximization (3x3 profit matrix) ===" <<
endl;
95 cout <<
"Profit matrix:" <<
endl;
96 cout <<
" Job0 Job1 Job2" <<
endl;
97 cout <<
"W0: 10 5 13" <<
endl;
98 cout <<
"W1: 3 9 18" <<
endl;
99 cout <<
"W2: 10 6 12" <<
endl;
104 int data[3][3] = {{10, 5, 13}, {3, 9, 18}, {10, 6, 12}};
105 for (
size_t i = 0; i < 3; ++i)
106 for (
size_t j = 0; j < 3; ++j)
107 mat(i, j) = data[i][j];
111 cout <<
"Maximum total profit: " << result.total_cost <<
endl;
112 cout <<
"Assignments:" <<
endl;
113 for (
auto [
r, c] : result.get_pairs())
114 cout <<
" Worker " <<
r <<
" -> Job " << c
115 <<
" (profit " << data[
r][c] <<
")" <<
endl;
128 cout <<
"=== Rectangular (3 workers, 5 tasks) ===" <<
endl;
130 cout <<
"Cost matrix:" <<
endl;
131 cout <<
" T0 T1 T2 T3 T4" <<
endl;
132 cout <<
"W0: 10 3 7 2 8" <<
endl;
133 cout <<
"W1: 5 9 1 6 4" <<
endl;
134 cout <<
"W2: 12 11 6 3 7" <<
endl;
146 for (
auto [
r, c] :
ha.get_assignments())
147 cout <<
" Worker " <<
r <<
" -> Task " << c <<
endl;
Hungarian (Munkres) algorithm for the assignment problem.
Dynamic matrix with sparse storage.
Hungarian (Munkres) algorithm for optimal assignment.
Cost_Type get_total_cost() const noexcept
Get the optimal total cost.
Hungarian_Result< Cost_Type > hungarian_max_assignment(const DynMatrix< Cost_Type > &cost)
Compute maximum-profit assignment (free function).
void example_rectangular()
Demonstrates rectangular assignment (3 workers, 5 tasks) using Hungarian_Assignment.
void example_basic_assignment()
Demonstrates a 4x4 workers-to-tasks assignment using Hungarian_Assignment.
void example_maximization()
Demonstrates maximizing total profit for a 3x3 profit matrix and prints the results.
int main()
Runs the three Hungarian algorithm example demonstrations.
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Dynamic matrix with lazy allocation.