Current function state stored in vector
This commit is contained in:
34
main.cpp
34
main.cpp
@@ -26,9 +26,9 @@ const CellType CUR_BASE = 3;
|
|||||||
const int ARGS_COUNT = 2;
|
const int ARGS_COUNT = 2;
|
||||||
|
|
||||||
struct FunctionTask {
|
struct FunctionTask {
|
||||||
set<FiniteFunction<CUR_BASE>> current;
|
vector<FiniteFunction<CUR_BASE>> current;
|
||||||
bool is_finished;
|
|
||||||
int current_max_coeff;
|
int current_max_coeff;
|
||||||
|
bool is_finished;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t BASE>
|
template <size_t BASE>
|
||||||
@@ -268,13 +268,13 @@ set<FiniteFunction<BASE>> generate_function_class(FiniteFunction<BASE> base_func
|
|||||||
// Вторым результатом возвращает true, если вычисления закончились успешно
|
// Вторым результатом возвращает true, если вычисления закончились успешно
|
||||||
// и false, если прервались по достижению max_size
|
// и false, если прервались по достижению max_size
|
||||||
template <CellType BASE>
|
template <CellType BASE>
|
||||||
pair<set<FiniteFunction<BASE>>, bool> extend_function_class(
|
pair<vector<FiniteFunction<BASE>>, bool> extend_function_class(
|
||||||
const set<FiniteFunction<BASE>>& base_class,
|
const vector<FiniteFunction<BASE>>& base_class,
|
||||||
size_t max_size
|
size_t max_size
|
||||||
) {
|
) {
|
||||||
if ( base_class.size() >= max_size )
|
if ( base_class.size() >= max_size )
|
||||||
return make_pair(
|
return make_pair(
|
||||||
set<FiniteFunction<BASE>>(base_class.begin(), base_class.end()),
|
vector<FiniteFunction<BASE>>(base_class.begin(), base_class.end()),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -322,14 +322,15 @@ pair<set<FiniteFunction<BASE>>, bool> extend_function_class(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return make_pair(
|
return make_pair(
|
||||||
set<FiniteFunction<BASE>>(func_class.begin(), func_class.end()),
|
vector<FiniteFunction<BASE>>(func_class.begin(), func_class.end()),
|
||||||
is_finished
|
is_finished
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <class Iterable>
|
||||||
bool is_bad_class(
|
bool is_bad_class(
|
||||||
set<FiniteFunction<CUR_BASE>> func_class,
|
const Iterable& func_class,
|
||||||
const set<FiniteFunction<CUR_BASE>>& bad_funcs
|
const set<FiniteFunction<CUR_BASE>>& bad_funcs
|
||||||
) {
|
) {
|
||||||
for (auto&& func: func_class)
|
for (auto&& func: func_class)
|
||||||
@@ -401,6 +402,9 @@ void process_task_lists() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
task_mutex.lock();
|
task_mutex.lock();
|
||||||
|
if ( task_list.size() != 0 )
|
||||||
|
cout << "IMPOSSIBLE task_list.size!!" << endl;
|
||||||
|
task_list.clear();
|
||||||
task_list.shrink_to_fit();
|
task_list.shrink_to_fit();
|
||||||
task_mutex.unlock();
|
task_mutex.unlock();
|
||||||
|
|
||||||
@@ -412,6 +416,11 @@ void process_task_lists() {
|
|||||||
processed_task_mutex.unlock();
|
processed_task_mutex.unlock();
|
||||||
|
|
||||||
cout << "sorting finished of "<< local_processed_tasks.size() << endl;
|
cout << "sorting finished of "<< local_processed_tasks.size() << endl;
|
||||||
|
size_t total_funcs = 0;
|
||||||
|
for (auto&& task: local_processed_tasks)
|
||||||
|
total_funcs += task.current.size();
|
||||||
|
cout << "estimated size: "
|
||||||
|
<< sizeof(FunctionTask) * total_funcs / 1024 / 1024 << " MB" << endl;
|
||||||
// Обеспечим увеличение размеров, чтобы не было проблем со включением одного
|
// Обеспечим увеличение размеров, чтобы не было проблем со включением одного
|
||||||
// в другое
|
// в другое
|
||||||
sort(
|
sort(
|
||||||
@@ -440,6 +449,7 @@ void process_task_lists() {
|
|||||||
//cout << "task finished, appending" << endl;
|
//cout << "task finished, appending" << endl;
|
||||||
++completed_tasks;
|
++completed_tasks;
|
||||||
print_progress(completed_tasks, total_possible_functions);
|
print_progress(completed_tasks, total_possible_functions);
|
||||||
|
sort(task.current.begin(), task.current.end());
|
||||||
auto func_class = task.current;
|
auto func_class = task.current;
|
||||||
bool is_need_append = true;
|
bool is_need_append = true;
|
||||||
vector<decltype(shared_function_classes)::iterator> functions_to_remove;
|
vector<decltype(shared_function_classes)::iterator> functions_to_remove;
|
||||||
@@ -471,7 +481,10 @@ void process_task_lists() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( is_need_append ) {
|
if ( is_need_append ) {
|
||||||
shared_function_classes.push_back(func_class);
|
shared_function_classes.push_back(set<FiniteFunction<CUR_BASE>>(
|
||||||
|
func_class.begin(),
|
||||||
|
func_class.end()
|
||||||
|
));
|
||||||
for (auto&& func: func_class)
|
for (auto&& func: func_class)
|
||||||
bad_functions.insert(func);
|
bad_functions.insert(func);
|
||||||
}
|
}
|
||||||
@@ -490,6 +503,7 @@ void process_task_lists() {
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
cout << sizeof(FiniteFunction<CUR_BASE>) << " " << sizeof(FunctionTask) << endl;
|
||||||
auto FiniteFunctionHasher = [](const FiniteFunction<CUR_BASE> &f) -> uint32_t {
|
auto FiniteFunctionHasher = [](const FiniteFunction<CUR_BASE> &f) -> uint32_t {
|
||||||
return f.get_hash();
|
return f.get_hash();
|
||||||
};
|
};
|
||||||
@@ -518,14 +532,14 @@ int main() {
|
|||||||
|
|
||||||
FiniteFunction<CUR_BASE> identical_x(string("000 111 222"));
|
FiniteFunction<CUR_BASE> identical_x(string("000 111 222"));
|
||||||
FiniteFunction<CUR_BASE> identical_y(string("012 012 012"));
|
FiniteFunction<CUR_BASE> identical_y(string("012 012 012"));
|
||||||
|
|
||||||
allowed_functions.erase(identical_x);
|
allowed_functions.erase(identical_x);
|
||||||
allowed_functions.erase(identical_y);
|
allowed_functions.erase(identical_y);
|
||||||
|
|
||||||
completed_tasks = 0;
|
completed_tasks = 0;
|
||||||
for (auto&& func: allowed_functions) {
|
for (auto&& func: allowed_functions) {
|
||||||
FunctionTask task;
|
FunctionTask task;
|
||||||
task.current.insert(func);
|
task.current = {func};
|
||||||
task.is_finished = false;
|
task.is_finished = false;
|
||||||
task.current_max_coeff = 1;
|
task.current_max_coeff = 1;
|
||||||
task_list.push_back(task);
|
task_list.push_back(task);
|
||||||
|
|||||||
Reference in New Issue
Block a user