static Errcode do_sep_tool() { Errcode err; Sep_cb sep; USHORT flags; if (!pti_input()) return(Success); clear_struct(&sep); if((err = gather_ctable(&sep)) >= 0) { if(from_menu) { if(vs.multi) { flags = AUTO_UNZOOM; if(vl.ink->needs & INK_NEEDS_CEL) flags |= AUTO_USESCEL; } else flags = 0; err = go_autodraw(sep1,&sep,flags); } else { sep1(&sep); err = save_redo_sep(&sep.p); } } free_ctable(&sep); return(err); }
Errcode do_sep_redo(Sep_p *sep) { Sep_cb scb; Errcode err; clear_struct(&scb); scb.p = *sep; if ((err = get_abs_ctable(&scb)) >= Success) { sep1(&scb); } free_ctable(&scb); return(err); }
static std::vector<mm::mastermind_t::remote_t> parse_remotes(const std::string &remotes) { typedef boost::char_separator<char> separator_t; typedef boost::tokenizer<separator_t> tokenizer_t; std::vector<mm::mastermind_t::remote_t> result; separator_t sep1(","); tokenizer_t tok1(remotes, sep1); separator_t sep2(":"); for (auto it = tok1.begin(), end = tok1.end(); it != end; ++it) { tokenizer_t tok2(*it, sep2); auto jt = tok2.begin(); if (tok2.end() == jt) { throw std::runtime_error("remotes are malformed"); } auto host = *jt++; uint16_t port = 10053; if (tok2.end() != jt) { port = boost::lexical_cast<uint16_t>(*jt++); } if (tok2.end() != jt) { throw std::runtime_error("remotes are malformed"); } result.emplace_back(std::make_pair(std::move(host), port)); } return result; }
int main(int argc, char** argv) { std::string top20_name; std::string verified_query_name; if (argc != 3){ LOG(INFO) << "score.bin top20.txt valid_image.txt"; return -1; } else{ top20_name = argv[1]; verified_query_name = argv[2]; } std::ifstream fr(top20_name.c_str()); std::string stringLine; std::vector<std::vector<std::string> > top20_Mat; while (!fr.eof()){ std::getline(fr, stringLine); boost::char_separator<char> sep(";"); boost::tokenizer<boost::char_separator<char> > tok(stringLine, sep); std::vector<std::string> tmp_ver_line; boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin(); std::string first_name = *beg; boost::char_separator<char> sep1(","); boost::tokenizer<boost::char_separator<char> > tok1(first_name, sep1); boost::tokenizer<boost::char_separator<char> >::iterator beg1 = tok1.begin(); tmp_ver_line.push_back(*beg1); beg1++; tmp_ver_line.push_back(*beg1); beg++; tmp_ver_line.push_back(*beg1); for (; beg != tok.end(); ++beg) { tmp_ver_line.push_back(*beg); } top20_Mat.push_back(tmp_ver_line); } fr.close(); std::ifstream fr_ver(verified_query_name.c_str()); std::vector<std::vector<std::string> > verify_Mat; while (!fr_ver.eof()){ std::getline(fr_ver, stringLine); boost::char_separator<char> sep(";"); boost::tokenizer<boost::char_separator<char> > tok(stringLine, sep); std::vector<std::string> tmp_ver_line; boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin(); std::string first_name = *beg; boost::char_separator<char> sep1(","); boost::tokenizer<boost::char_separator<char> > tok1(first_name, sep1); boost::tokenizer<boost::char_separator<char> >::iterator beg1 = tok1.begin(); tmp_ver_line.push_back(*beg1); beg1++; tmp_ver_line.push_back(*beg1); beg++; for (; beg != tok.end(); ++beg) { tmp_ver_line.push_back(*beg); } verify_Mat.push_back(tmp_ver_line); } fr_ver.close(); const int num = top20_Mat.size(); const int ver_num = verify_Mat.size(); double score = 0.; for (size_t i = 0; i < num; ++i){ std::string imageName = top20_Mat[i][0]; double tmp_score = 0.; size_t j; for (j = 0; j < ver_num; ++j){ if (verify_Mat[j][0] == imageName) break; } int count = 1; if (j < ver_num) { for (size_t m = 1; m < top20_Mat[i].size(); ++m) { std::string tmpName = top20_Mat[i][m]; size_t n; for (n = 1; n < verify_Mat[j].size(); ++n){ if (tmpName == verify_Mat[j][n]) break; } if (n < verify_Mat[j].size()){ count++; tmp_score += (count / static_cast<double>(m)); } } } tmp_score /= 20.; score += tmp_score; } score /= num; LOG(INFO) << "MAP20 score: " << score; LOG(INFO) << "map20 computing finished!"; }
string Lsystem::parse_lsystem(char const* filename, int iteration) { //Falls Datei noch nicht geparsed if(lsystem_.empty() == true){ //Datei einlesen file_iterator<> first = load(filename); file_iterator<> last = first.make_end(); typedef char char_t; typedef file_iterator <char_t> iterator_t; string input(first, last); // std::cout << "Eingabe:" << "\n" << input << "\n" << std::endl; lsystem_grammer lsys; //Parsevorgang parse_info<iterator_t> pi = parse(first, last, lsys, space_p); if (pi.hit) { if (pi.full) { std::cout << "LSystem: file reading successfully" << std::endl; std::cout << "LSystem: " << pi.length << "characters read" << std::endl; std::cout << "LSystem: parsing ..." << std::endl; // std::cout << "Vektor:" << gl_lsys_file.size() << "\n" << std::endl; //Eingabe splitten typedef boost::tokenizer<boost::char_separator<char> > tokenizer; //Axiom //string s1 = get_axiom(); //boost::char_separator<char> sep1(": "); //tokenizer tok(s1, sep1); //tokenizer::iterator it = tok.begin(); //string start = *(++it); boost::char_separator<char> sep1(": "); string start = get_axiom(); std::string ret; //Produkion(en) vector<string> s2 = get_production(); // int last_pos = 0; int left = 1; //Zufallszahlen bis 100 // srand(j * time(0)); //int prob = rand() % 100 + 1; // std::cout << "ZZ:" << prob << std::endl; // std::cout<<s2.size()<<std::endl; std::map<int, string> mapProbToProd; int zaehler=0; for (int i = 0; i < s2.size(); i++) { int position; tokenizer tok2(s2[i], sep1); tokenizer::iterator it = tok2.begin(); string temp = *(++it); //Alles nach dem Doppelpunkt boost::char_separator<char> sep2("="); tokenizer tok3(temp, sep2); tokenizer::iterator it2 = tok3.begin(); string temp1 = *(it2); //Alles vor dem Gleichheitszeichen string temp2 = *(++it2); //Alles nach dem Gleichheitszeichen if (temp2.find(",") == string::npos) { //DOL stochastic_ = false; //Ersetzung boost::replace_all(start, temp1, temp2); lsystem_.push_back(start); lsystem_.push_back(start); //DOL mit meherere Produktionen existieren } else if (temp2.find(",") != string::npos) { //stochastische L-Systeme stochastic_ = true; boost::char_separator<char> sep3(","); tokenizer tok4(temp2, sep3); tokenizer::iterator it3 = tok4.begin(); string sto = *(it3); //Alles vor Komma (Wahrscheinlichkeit) string temp3 = *(++it3); //Alles nach Komma (Regel) int cur_pos = atof(sto.data()) * 100; //aktuelle Wahrscheinlichkeit int right = last_pos + cur_pos; //Bereich rechts for(int k = 0; k < cur_pos ; ++k ) { mapProbToProd.insert ( std::pair<int, string>(zaehler,temp3)); ++zaehler; } // } } for (int j = 1; j <= iteration * 2; j++) { std::string result; // result.reserve(14*start.size()); for(int i = 0 ; i < start.size() ; ++i) { srand(i*time(0)); int k = rand() % 100; if(start[i]=='F') result += mapProbToProd[k]; else result += start[i]; } lsystem_.push_back(result); start=result; } std::cout << "LSystem: parsing finished\n\n"; //} if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(s2.size()) * iteration - 1] << std::endl; return lsystem_[(s2.size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } else { std::cout << "LSystem: ERROR parsing data partially" << std::endl; std::cout << "LSystem: ERROR " << pi.length << "characters parsed \n\n" << std::endl; } } else std::cout << "LSystem: ERROR parsing failed; stopped at '" << pi.stop << "'\n\n" << std::endl; } //erneutes Parsen verhindern else if(iteration <= lsystem_.size()) { if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(get_production().size()) * iteration - 1] << std::endl; return lsystem_[(get_production().size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } //Vektor vergrößern else if(iteration > lsystem_.size()){ erase_old(); parse_lsystem(filename, iteration); if (stochastic_ == false) { // std::cout << "Ergebnis: " << lsystem_[(get_production().size()) * iteration - 1] << std::endl; return lsystem_[(get_production().size() * iteration - 1)]; } else if (stochastic_ == true) { // std::cout << "Ergebnis: " << lsystem_[iteration - 1] << std::endl; return lsystem_[iteration - 1]; } } return std::string(); }