-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcandidate_list.cpp
123 lines (98 loc) · 3.21 KB
/
candidate_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "candidate_list.h"
candidate_lists::list_t candidate_lists::empty_list = candidate_lists::list_t();
/**
* @brief prints the current candidate list's type (PLmloop_CL, etc.)
* used for debugging
*/
void candidate_lists::print_type() const {
switch (type_) {
case P_PLmloop0:
printf("PLmloop_CL");
break;
case P_PfromL:
printf("PfromL_CL");
break;
case P_PRmloop0:
printf("PRmloop_CL");
break;
case P_PfromR:
printf("PfromR_CL");
break;
case P_PMmloop0:
printf("PMmloop_CL");
break;
case P_PfromM:
printf("PfromM_CL");
break;
case P_POmloop0:
printf("POmloop_CL");
break;
case P_PfromO:
printf("PfromO_CL");
break;
}
}
/**
* @brief push candidate with information w, i, to front of CL
*/
void candidate_lists::push_candidate(const Index4D &x, int w) {
// std::cerr << "candidate_lists::push_candidate(" << x << ", " << w << ")"
// << " " << index3D(x.j(),x.k(),x.l()) << std::endl;
assert( w >= std::numeric_limits<energy_t>::min()
&& w <= std::numeric_limits<energy_t>::max() );
assert( x.i() >= std::numeric_limits<index_t>::min()
&& x.i() <= std::numeric_limits<index_t>::max() );
cls_[x.j()][index(x.k(),x.l())].push_sorted(x.i(), w);
}
/**
* Find candidate in candidate list CL
* @returns on failure returns nullptr, else candidate
*/
int
candidate_lists::find_candidate(int i, int j, int k, int l) const {
const auto it = cls_[j].find(index(k,l));
if (it == cls_[j].end()) {
return INF;
}
const auto it2 = it->second.find(i);
if (it2 == it->second.end()) {
return INF;
}
return it2->second;
}
/** @brief adds number of candidates or empty candidate lists to candidates/empty_lists
* used in print_CL_sizes
*/
void candidate_lists::get_CL_size(int &candidates, int &capacity) const {
for (const auto &x : cls_ ){
for (const auto &cl : x ){
candidates += cl.second.size();
capacity += cl.second.capacity();
}
}
}
/**
* @brief prints information on a single candidate list
*/
void candidate_lists::print_CL_size() const {
int candidates = 0, capacity = 0;
get_CL_size(candidates, capacity);
printf("\n");
print_type();
printf("\n");
// printf("Max num lists: %ld, ", n_*(n_+1)*(n_+2)/6);
// printf("Max num candidates: %ld\n", n_*(n_+1)*(n_+2)/6*(n_+3)/4);
int num_lists=0;
for(const auto &x:cls_)
num_lists+=x.size();
printf("Num lists: %d\n",num_lists);
// printf("Num empty lists: %d\n", empty_lists);
printf("Num candidates: %d\n", candidates);
printf("Avg cands per list: %f\n", (float)candidates/num_lists);
// int p_size = sizeof(void *); // size of a pointer
// int empty_space = empty_lists*p_size;
// printf("List space: %ld, Empty list space: %d \n",cls_.size()*p_size, empty_space);
int c_size = sizeof(candidate);
printf("Total candidate space: %d\n", candidates*c_size );
printf("Size: %d, Capacity: %d\n", candidates, capacity);
}