MCPcopy Create free account
hub / github.com/davisking/dlib / assignment_cost

Function assignment_cost

dlib/optimization/max_cost_assignment.h:17–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 5

align_pointsFunction · 0.85
_assignment_costFunction · 0.85
test_hungarianMethod · 0.85
mainFunction · 0.85

Calls 6

minFunction · 0.50
matFunction · 0.50
maxFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
sizeMethod · 0.45

Tested by 2

test_hungarianMethod · 0.68