| 14 | using namespace dlib; |
| 15 | |
| 16 | int main () |
| 17 | { |
| 18 | // Let's imagine you need to assign N people to N jobs. Additionally, each person will make |
| 19 | // your company a certain amount of money at each job, but each person has different skills |
| 20 | // so they are better at some jobs and worse at others. You would like to find the best way |
| 21 | // to assign people to these jobs. In particular, you would like to maximize the amount of |
| 22 | // money the group makes as a whole. This is an example of an assignment problem and is |
| 23 | // what is solved by the max_cost_assignment() routine. |
| 24 | // |
| 25 | // So in this example, let's imagine we have 3 people and 3 jobs. We represent the amount of |
| 26 | // money each person will produce at each job with a cost matrix. Each row corresponds to a |
| 27 | // person and each column corresponds to a job. So for example, below we are saying that |
| 28 | // person 0 will make $1 at job 0, $2 at job 1, and $6 at job 2. |
| 29 | matrix<int> cost(3,3); |
| 30 | cost = 1, 2, 6, |
| 31 | 5, 3, 6, |
| 32 | 4, 5, 0; |
| 33 | |
| 34 | // To find out the best assignment of people to jobs we just need to call this function. |
| 35 | std::vector<long> assignment = max_cost_assignment(cost); |
| 36 | |
| 37 | // This prints optimal assignments: [2, 0, 1] which indicates that we should assign |
| 38 | // the person from the first row of the cost matrix to job 2, the middle row person to |
| 39 | // job 0, and the bottom row person to job 1. |
| 40 | for (unsigned int i = 0; i < assignment.size(); i++) |
| 41 | cout << assignment[i] << std::endl; |
| 42 | |
| 43 | // This prints optimal cost: 16.0 |
| 44 | // which is correct since our optimal assignment is 6+5+5. |
| 45 | cout << "optimal cost: " << assignment_cost(cost, assignment) << endl; |
| 46 | } |
| 47 |
nothing calls this directly
no test coverage detected