#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; vector< vector > split_by_classes(vector< vector > classes_vector, list filenames) { if(filenames.empty()) { // Base case return classes_vector; } string& current_file = filenames.back(); string current_file_2 = current_file; filenames.pop_back(); string polymake_input; string line_string; string bit_line_string; bool matched = false; for(int equiv_class = 0; equiv_class < classes_vector.size(); equiv_class++) { stringstream polymake_input_ss; polymake_input_ss << "polymake check_iso " << current_file_2 << " " << classes_vector[equiv_class][0] << " > check_iso.txt"; system(polymake_input_ss.str().c_str()); ifstream check_iso("check_iso.txt"); if ( !check_iso) { cout << "error opening check_iso.txt" << endl; } while( !check_iso.eof()) { getline(check_iso, line_string, '\n'); if (line_string.size() == 1) { bit_line_string = line_string; } } check_iso.close(); if(atoi(bit_line_string.c_str()) == 1) { //current_file is equivalent to existing classes_vector[equiv_class].push_back(current_file_2); matched = true; } } if(matched==false) { //curent_file equivalent to none. Construct new class vector new_class; new_class.push_back(current_file_2); classes_vector.push_back(new_class); } return split_by_classes(classes_vector, filenames); } int gcd(int a, int b) { int t; while (b != 0) { t = b; b = a % b; a = t; } return a; } void split_string(const string& long_string, char delimiter, vector& v) { string::size_type i=0; string::size_type j = long_string.find(delimiter); if (j == string::npos) { // Base case: v.push_back(long_string); } else { while (j != string::npos) { v.push_back(long_string.substr(i, j-i)); i = ++j; j = long_string.find(delimiter, j); if (j == string::npos) { v.push_back(long_string.substr(i, long_string.length())); } } } } void extract_from_polyfile(const string& filename, const string& header, vector& v) { string line_string; bool right_section; ifstream ipoly_file(filename.c_str()); //reading the second argument /* opens an ifstream object called inputFile to be read from input - this is our .poly file we'll be reading */ if(!ipoly_file.fail()) // Here is where we read the file contents { while(!ipoly_file.eof()) { getline(ipoly_file, line_string, '\n'); if(line_string.length()==0) { getline(ipoly_file, line_string, '\n'); if(line_string == header) { right_section = true; getline(ipoly_file,line_string, '\n'); //eats the header so we don't display it } else { right_section = false; } } if(right_section) { v.push_back(line_string); } } } } // Datetime stuff... ostream& formatDateTime(ostream& out, const tm& t, const char* fmt) { const time_put& dateWriter = use_facet >(out.getloc()); int n = strlen(fmt); if (dateWriter.put(out, out, ' ', &t, fmt, fmt + n).failed()) { throw runtime_error("failure to format datetime"); } return out; } string dateTimeToString(const tm& t, const char* format) { stringstream s; formatDateTime(s, t, format); return s.str(); } tm now() { time_t now = time(0); return *localtime(&now); } string current_time_string() { return dateTimeToString(now(), "%b %d, %Y %I:%M%p"); }