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

Function permutations

dlib/test/max_cost_assignment.cpp:27–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25// ----------------------------------------------------------------------------------------
26
27 std::vector<std::vector<long> > permutations (
28 matrix<long,1,0> vals
29 )
30 {
31 if (vals.size() == 0)
32 {
33 return std::vector<std::vector<long> >();
34 }
35 else if (vals.size() == 1)
36 {
37 return std::vector<std::vector<long> >(1,std::vector<long>(1,vals(0)));
38 }
39
40
41 std::vector<std::vector<long> > temp;
42
43
44 for (long i = 0; i < vals.size(); ++i)
45 {
46 const std::vector<std::vector<long> >& res = permutations(remove_col(vals,i));
47
48 for (unsigned long j = 0; j < res.size(); ++j)
49 {
50 temp.resize(temp.size()+1);
51 std::vector<long>& part = temp.back();
52 part.push_back(vals(i));
53 part.insert(part.end(), res[j].begin(), res[j].end());
54 }
55 }
56
57
58 return temp;
59 }
60
61// ----------------------------------------------------------------------------------------
62

Callers 1

Calls 8

remove_colFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
backMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected