No class extending if size of it more than needed

This commit is contained in:
2018-04-26 01:17:15 +03:00
parent d36ad583c6
commit c95aa1edd5

View File

@@ -272,6 +272,12 @@ pair<set<FiniteFunction<BASE>>, bool> extend_function_class(
const set<FiniteFunction<BASE>>& base_class,
size_t max_size
) {
if ( base_class.size() >= max_size )
return make_pair(
set<FiniteFunction<BASE>>(base_class.begin(), base_class.end()),
false
);
FiniteFunction<CUR_BASE> identical_x(string("000 111 222"));
FiniteFunction<CUR_BASE> identical_y(string("012 012 012"));
auto FiniteFunctionHasher = [](const FiniteFunction<BASE> &f) -> uint32_t {
@@ -335,7 +341,7 @@ bool is_bad_class(
size_t total_possible_functions;
atomic<long> completed_tasks;
atomic<long> tasks_to_extend; // количество тасков, которые не обработаны
list< set<FiniteFunction<CUR_BASE>> > shared_function_classes;
mutex shared_functions_mutex;
@@ -375,10 +381,10 @@ void do_work() {
task.current,
get_math_coeff(task.current_max_coeff)
);
//cout << "k=" << task.current_max_coeff << endl;
processed_task_mutex.lock();
processed_task_list.push_back(task);
processed_task_mutex.unlock();
--tasks_to_extend;
}
}
@@ -389,13 +395,34 @@ void process_task_lists() {
std::chrono::milliseconds SLEEP_TIME(10);
while ( completed_tasks < total_possible_functions ) {
if ( tasks_to_extend ) {
// подождём, пока не закончатся таски в очереди
std::this_thread::sleep_for(SLEEP_TIME);
continue;
}
task_mutex.lock();
task_list.shrink_to_fit();
task_mutex.unlock();
// опустошим выполненные таски
processed_task_mutex.lock();
vector<FunctionTask> local_processed_task_list = processed_task_list;
vector<FunctionTask> local_processed_tasks = processed_task_list;
processed_task_list.clear();
processed_task_list.shrink_to_fit();
processed_task_mutex.unlock();
for ( auto&& task: local_processed_task_list ) {
cout << "sorting finished of "<< local_processed_tasks.size() << endl;
// Обеспечим увеличение размеров, чтобы не было проблем со включением одного
// в другое
sort(
local_processed_tasks.begin(),
local_processed_tasks.end(),
[](const FunctionTask& a, const FunctionTask& b) {
return a.current.size() < b.current.size();
}
);
for ( auto&& task: local_processed_tasks ) {
if ( !task.is_finished ) {
if ( is_bad_class(task.current, bad_functions) ) {
//cout << "bad class" << endl;
@@ -404,6 +431,7 @@ void process_task_lists() {
} else {
++task.current_max_coeff;
task_mutex.lock();
++tasks_to_extend;
task_list.push_back(task);
task_mutex.unlock();
}
@@ -453,7 +481,7 @@ void process_task_lists() {
}
}
}
local_processed_task_list.clear();
local_processed_tasks.clear();
// Поспим, чтобы не работать слишком часто
std::this_thread::sleep_for(SLEEP_TIME);
@@ -506,7 +534,7 @@ int main() {
cout << "Total funcs in list " << task_list.size() << " functions" << endl;
total_possible_functions = task_list.size();
tasks_to_extend = task_list.size();
vector< thread > thread_pool;
thread task_processer(process_task_lists);