Commit f949a9cf authored by Simon Gaul's avatar Simon Gaul

Rekursionen vereinfacht

Abbruchfälle außerhalb der Schleifen geprüft, Annahme dass num_parameters >= depth, im Projektrahmen natürlich dadurch garantiert, dass Rekursion (damit insbesondere Werte von depth) Implementierungsdetail und nicht Teil irgendwelcher Schnittstellen
parent 43854182
......@@ -55,15 +55,13 @@ void recursive_generate(tp_t* parameters, int num_parameters,
tp_t parameter = parameters[depth];
for (values[depth] = parameter.min; values[depth] <= parameter.max; ++values[depth]) {
if (check_constraint(parameter, values)) {
if (num_parameters == depth + 1) {
add_to_search_space(search_space, values, num_parameters);
}
else {
recursive_generate(parameters, num_parameters, search_space, values, depth + 1);
}
recursive_generate(parameters, num_parameters, search_space, values, depth + 1);
}
}
}
else {
add_to_search_space(search_space, values, num_parameters);
}
}
// recursively count the number of elements in the search space without storing the valid tuning parameters.
......@@ -76,22 +74,20 @@ void recursive_generate(tp_t* parameters, int num_parameters,
// to dynamically allocating space when generating the search space.
int recursive_search_space_size(tp_t* parameters, int num_parameters,
search_space_t* search_space, int* values, int depth) {
int size = 0;
if (num_parameters > depth) {
int size = 0;
tp_t parameter = parameters[depth];
for (values[depth] = parameter.min; values[depth] <= parameter.max; ++values[depth]) {
if (check_constraint(parameter, values)) {
if (num_parameters == depth + 1) {
++size;
}
else {
size += recursive_search_space_size(
parameters, num_parameters, search_space, values, depth + 1);
}
size += recursive_search_space_size(
parameters, num_parameters, search_space, values, depth + 1);
}
}
return size;
}
else {
return 1;
}
return size;
}
#define SEARCH_SPACE_MEM_SIZE recursive_search_space_size(parameters, num_parameters, search_space, values, 0) * sizeof(int*)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment