Incorrect way to skip too big classess
This commit is contained in:
42
main.cpp
42
main.cpp
@@ -26,9 +26,8 @@ const CellType CUR_BASE = 3;
|
||||
const int ARGS_COUNT = 2;
|
||||
|
||||
struct FunctionTask {
|
||||
vector<FiniteFunction<CUR_BASE>> current;
|
||||
int current_max_coeff;
|
||||
bool is_finished;
|
||||
vector<FiniteFunction<CUR_BASE>> current;
|
||||
};
|
||||
|
||||
template <size_t BASE>
|
||||
@@ -307,14 +306,14 @@ pair<vector<FiniteFunction<BASE>>, bool> extend_function_class(
|
||||
new_funcs.insert(f_left);
|
||||
}
|
||||
}
|
||||
new_funcs.erase(identical_x);
|
||||
new_funcs.erase(identical_y);
|
||||
if ( new_funcs.size() == last_size ) {
|
||||
is_finished = true;
|
||||
break;
|
||||
}
|
||||
|
||||
func_class.insert(new_funcs.begin(), new_funcs.end());
|
||||
func_class.erase(identical_x);
|
||||
func_class.erase(identical_y);
|
||||
last_size = new_funcs.size();
|
||||
|
||||
// слишком много насчитали -- выходим
|
||||
@@ -357,7 +356,7 @@ vector<FunctionTask> processed_task_list;
|
||||
mutex processed_task_mutex;
|
||||
|
||||
set<FiniteFunction<CUR_BASE>> bad_functions;
|
||||
|
||||
atomic<int> current_max_coeff;
|
||||
|
||||
void do_work() {
|
||||
std::chrono::milliseconds SLEEP_TIME(10);
|
||||
@@ -383,7 +382,7 @@ void do_work() {
|
||||
|
||||
tie(task.current, task.is_finished) = extend_function_class(
|
||||
task.current,
|
||||
get_math_coeff(task.current_max_coeff)
|
||||
get_math_coeff(current_max_coeff)
|
||||
);
|
||||
processed_task_mutex.lock();
|
||||
processed_task_list.push_back(task);
|
||||
@@ -398,6 +397,9 @@ void process_task_lists() {
|
||||
cout << "processing starts " << endl;
|
||||
|
||||
std::chrono::milliseconds SLEEP_TIME(10);
|
||||
|
||||
vector<FunctionTask> local_processed_tasks;
|
||||
|
||||
while ( completed_tasks < total_possible_functions ) {
|
||||
if ( tasks_to_extend ) {
|
||||
// подождём, пока не закончатся таски в очереди
|
||||
@@ -413,7 +415,8 @@ void process_task_lists() {
|
||||
|
||||
// опустошим выполненные таски
|
||||
processed_task_mutex.lock();
|
||||
vector<FunctionTask> local_processed_tasks = processed_task_list;
|
||||
for (auto && task: processed_task_list)
|
||||
local_processed_tasks.push_back(task);
|
||||
processed_task_list.clear();
|
||||
processed_task_list.shrink_to_fit();
|
||||
processed_task_mutex.unlock();
|
||||
@@ -434,14 +437,21 @@ void process_task_lists() {
|
||||
}
|
||||
);
|
||||
|
||||
// сохраним, чем должен был равняться максимальный размер
|
||||
auto last_math_coeff = get_math_coeff(current_max_coeff);
|
||||
// а для всех новых увеличим его
|
||||
++current_max_coeff;
|
||||
|
||||
for ( auto&& task: local_processed_tasks ) {
|
||||
// если в каких-то больше, чем положено, то не трогаем их
|
||||
if ( task.current.size() > last_math_coeff)
|
||||
break;
|
||||
if ( !task.is_finished ) {
|
||||
if ( is_bad_class(task.current, bad_functions) ) {
|
||||
//cout << "bad class" << endl;
|
||||
++completed_tasks;
|
||||
print_progress(completed_tasks, total_possible_functions);
|
||||
} else {
|
||||
++task.current_max_coeff;
|
||||
task_mutex.lock();
|
||||
++tasks_to_extend;
|
||||
task_list.push_back(task);
|
||||
@@ -494,7 +504,16 @@ void process_task_lists() {
|
||||
}
|
||||
}
|
||||
}
|
||||
local_processed_tasks.clear();
|
||||
local_processed_tasks.erase(
|
||||
remove_if(
|
||||
local_processed_tasks.begin(),
|
||||
local_processed_tasks.end(),
|
||||
[last_math_coeff](const FunctionTask& task) {
|
||||
return task.current.size() <= last_math_coeff;
|
||||
}),
|
||||
local_processed_tasks.end()
|
||||
);
|
||||
local_processed_tasks.shrink_to_fit();
|
||||
|
||||
// Поспим, чтобы не работать слишком часто
|
||||
std::this_thread::sleep_for(SLEEP_TIME);
|
||||
@@ -534,16 +553,17 @@ int main() {
|
||||
|
||||
FiniteFunction<CUR_BASE> identical_x(string("000 111 222"));
|
||||
FiniteFunction<CUR_BASE> identical_y(string("012 012 012"));
|
||||
|
||||
cout << identical_x.get_hash() << endl;
|
||||
cout << identical_y.get_hash() << endl;
|
||||
allowed_functions.erase(identical_x);
|
||||
allowed_functions.erase(identical_y);
|
||||
|
||||
completed_tasks = 0;
|
||||
current_max_coeff = 1;
|
||||
for (auto&& func: allowed_functions) {
|
||||
FunctionTask task;
|
||||
task.current = {func};
|
||||
task.is_finished = false;
|
||||
task.current_max_coeff = 1;
|
||||
task_list.push_back(task);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user