Corrected some errors

This commit is contained in:
Wojciech Politarczyk 2017-02-08 12:05:23 +01:00
parent 816e2eef59
commit b215778186
No known key found for this signature in database
GPG Key ID: DA54546CA5F66507
2 changed files with 45 additions and 30 deletions

74
kk.cpp
View File

@ -95,7 +95,7 @@ std::string periodicity_test = "Przytycki";
int period = 5; int period = 5;
knot_diagram kd; knot_diagram kd;
bool reduced = 0; bool reduced = 0;
std::string in_file_name = "/home/wojtek/ownCloud/Lokalny/khovanov-homology-computation/homflypt_test/to_test_kh.txt"; std::string in_file_name = "/home/wojtek/ownCloud/Lokalny/khovanov-homology-computation/both.txt";
class hg_grading_mapper class hg_grading_mapper
{ {
@ -334,18 +334,20 @@ int compute_s_inv(knot_diagram& kd) {
return qmin + 1; return qmin + 1;
} }
inline std::string parse_data_from_file(const std::string& data) { std::pair<std::string, int> parse_data_from_file(const std::string& data) {
auto p_start = data.find(":") + 2; auto knot_name_stop = data.find(" ");
auto p_stop = data.find("]"); auto p2 = data.find("=") + 2;
return data.substr(p_start, p_stop - p_start); std::string knot_name = data.substr(0, knot_name_stop);
int period = std::stoi(data.substr(knot_name_stop + 3));
return make_pair(knot_name, period);
} }
std::string perform_computations(const std::string& knot_name) { std::string perform_computations(const std::string& knot_name,
knot_diagram kd,
std::vector<int> periods) {
std::ostringstream res; std::ostringstream res;
knot_diagram kd = parse_knot(knot_name.c_str());
kd.marked_edge = 1;
Kh_periodicity_checker Kh_pc(kd, knot_name); Kh_periodicity_checker Kh_pc(kd, knot_name);
for(auto p: primes_list) { for(auto p: periods) {
res << "Kh criterion: " << Kh_pc(p) << std::endl; res << "Kh criterion: " << Kh_pc(p) << std::endl;
} }
return res.str(); return res.str();
@ -366,31 +368,45 @@ void check_periodicity(std::string out_file) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
unsigned num_threads = std::min(max_threads, std::thread::hardware_concurrency()); unsigned num_threads = std::min(max_threads, std::thread::hardware_concurrency());
std::string line; unsigned i = 0;
std::string previous_knot; std::string line, previous_knot;
knot_diagram kd_temp;
std::vector<std::future<std::string>> v_future(num_threads); std::vector<std::future<std::string>> v_future(num_threads);
bool stop = false; std::vector<int> periods;
while(!stop) { while(std::getline(in_file, line)) {
unsigned i = 0; if(line == "") continue;
while(i < num_threads) { std::string knot_name;
if(!in_file.eof()) { int period;
std::getline(in_file, line); tie(knot_name, period) = parse_data_from_file(line);
std::string knot_name = parse_data_from_file(line); if(knot_name == previous_knot) {
if(knot_name == previous_knot) auto p = find(primes_list.begin(), primes_list.end(), period);
continue; if(p != primes_list.end()) {
else { periods.push_back(period);
v_future[i] = std::async(std::launch::async, perform_computations, knot_name);
++i;
std::cerr << "Checking " << knot_name << "\n";
previous_knot = knot_name;
}
} }
else { else {
stop = true; std::cerr << "Period " << period << " cannot be checked..." << "\n";
break;
} }
} }
for(auto& v_f : v_future) else {
if(i == num_threads) {
for(auto& v_f : v_future)
std::cout << v_f.get();
i = 0;
}
if(previous_knot.size() > 0) {
std::cerr << "Checking " << previous_knot << "\n";
v_future[i] = std::async(perform_computations, previous_knot, kd_temp, periods);
++i;
periods.clear();
}
kd_temp = parse_knot(knot_name.c_str());
kd_temp.marked_edge = 1;
periods.push_back(period);
previous_knot = knot_name;
}
}
for(auto& v_f : v_future) {
if(v_f.valid())
std::cout << v_f.get(); std::cout << v_f.get();
} }
} }

View File

@ -1,4 +1,3 @@
class smoothing : public refcounted class smoothing : public refcounted
{ {
public: public: