Added saving of completed tasks

This commit is contained in:
2018-04-26 12:36:53 +03:00
parent 3ef983ed17
commit 48e918f500

View File

@@ -24,6 +24,7 @@ using namespace std;
const CellType CUR_BASE = 3; const CellType CUR_BASE = 3;
const int ARGS_COUNT = 2; const int ARGS_COUNT = 2;
const string CLASSES_FILENAME = "classes.txt";
struct FunctionTask { struct FunctionTask {
bool is_finished; bool is_finished;
@@ -81,6 +82,16 @@ void write_function_class(ofstream &f_out, Iterable begin, Iterable end) {
f_out << *begin << " "; f_out << *begin << " ";
f_out << endl; f_out << endl;
} }
template <class ClassesContainer>
void append_classes(const ClassesContainer& classes) {
std::ofstream f_out(CLASSES_FILENAME.c_str(), ios_base::app);
for (const auto& func_class: classes) {
write_function_class(f_out, func_class.begin(), func_class.end());
}
f_out.close();
}
/* /*
template <int BASE> template <int BASE>
void get_permutations(vector<array<int, BASE>> &permutations) { void get_permutations(vector<array<int, BASE>> &permutations) {
@@ -450,7 +461,10 @@ void process_task_lists() {
if ( is_bad_class(task.current, bad_functions) ) { if ( is_bad_class(task.current, bad_functions) ) {
//cout << "bad class" << endl; //cout << "bad class" << endl;
++completed_tasks; ++completed_tasks;
print_progress(completed_tasks, total_possible_functions); if ( print_progress(completed_tasks, total_possible_functions) ) {
append_classes(shared_function_classes);
shared_function_classes.clear();
}
} else { } else {
task_mutex.lock(); task_mutex.lock();
++tasks_to_extend; ++tasks_to_extend;
@@ -461,12 +475,17 @@ void process_task_lists() {
} else { } else {
//cout << "task finished, appending" << endl; //cout << "task finished, appending" << endl;
++completed_tasks; ++completed_tasks;
print_progress(completed_tasks, total_possible_functions); if ( print_progress(completed_tasks, total_possible_functions) ) {
append_classes(shared_function_classes);
shared_function_classes.clear();
}
sort(task.current.begin(), task.current.end()); 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;
for (auto it = shared_function_classes.begin(); it != shared_function_classes.end(); ++it) {
is_need_append = !is_bad_class(task.current, bad_functions);
/*for (auto it = shared_function_classes.begin(); it != shared_function_classes.end(); ++it) {
if ( func_class.size() < it->size() ) { if ( func_class.size() < it->size() ) {
if (includes( if (includes(
it->begin(), it->begin(),
@@ -492,7 +511,7 @@ void process_task_lists() {
break; break;
} }
} }
} }*/
if ( is_need_append ) { if ( is_need_append ) {
shared_function_classes.push_back(func_class); shared_function_classes.push_back(func_class);
for (auto&& func: func_class) for (auto&& func: func_class)
@@ -574,6 +593,10 @@ int main() {
vector< thread > thread_pool; vector< thread > thread_pool;
thread task_processer(process_task_lists); thread task_processer(process_task_lists);
// удалим старый контент
std::ofstream f_out("classes.txt");
f_out.close();
for (int i = 0; i < THREADS_COUNT - 1; ++i) for (int i = 0; i < THREADS_COUNT - 1; ++i)
thread_pool.push_back(thread(do_work)); thread_pool.push_back(thread(do_work));
@@ -661,10 +684,6 @@ int main() {
new_vector_classes.push_back(*it); new_vector_classes.push_back(*it);
swap(new_vector_classes, vector_classes); swap(new_vector_classes, vector_classes);
}*/ }*/
std::ofstream f_out("classes.txt"); append_classes(vector_classes);
for (const auto& func_class: vector_classes) {
write_function_class(f_out, func_class.begin(), func_class.end());
}
f_out.close();
return 0; return 0;
} }