| 15 | |
| 16 | template <typename EXP> |
| 17 | typename EXP::type assignment_cost ( |
| 18 | const matrix_exp<EXP>& cost, |
| 19 | const std::vector<long>& assignment |
| 20 | ) |
| 21 | { |
| 22 | DLIB_ASSERT(cost.nr() == cost.nc(), |
| 23 | "\t type assignment_cost(cost,assignment)" |
| 24 | << "\n\t cost.nr(): " << cost.nr() |
| 25 | << "\n\t cost.nc(): " << cost.nc() |
| 26 | ); |
| 27 | #ifdef ENABLE_ASSERTS |
| 28 | // can't call max on an empty vector. So put an if here to guard against it. |
| 29 | if (assignment.size() > 0) |
| 30 | { |
| 31 | DLIB_ASSERT(0 <= min(mat(assignment)) && max(mat(assignment)) < cost.nr(), |
| 32 | "\t type assignment_cost(cost,assignment)" |
| 33 | << "\n\t cost.nr(): " << cost.nr() |
| 34 | << "\n\t cost.nc(): " << cost.nc() |
| 35 | << "\n\t min(assignment): " << min(mat(assignment)) |
| 36 | << "\n\t max(assignment): " << max(mat(assignment)) |
| 37 | ); |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | typename EXP::type temp = 0; |
| 42 | for (unsigned long i = 0; i < assignment.size(); ++i) |
| 43 | { |
| 44 | temp += cost(i, assignment[i]); |
| 45 | } |
| 46 | return temp; |
| 47 | } |
| 48 | |
| 49 | // ---------------------------------------------------------------------------------------- |
| 50 | |