int main(int argc, char *argv[]) { std::ifstream ifs("../bin/searched_book.bin"); const size_t fileSize = static_cast<size_t>(ifs.seekg(0, std::ios::end).tellg()); ifs.seekg(0, std::ios::beg); // ストリームのポインタを一番前に戻して、これから先で使いやすいようにする if (fileSize % sizeof(BookEntry) != 0) { std::cout << "arere?" << std::endl; return 0; } std::vector<BookEntry> vec(fileSize/sizeof(BookEntry)); ifs.read(reinterpret_cast<char*>(&vec[0]), fileSize); std::ifstream ifs2("../bin/tai_doukaku_book.bin"); const size_t fileSize2 = static_cast<size_t>(ifs2.seekg(0, std::ios::end).tellg()); ifs2.seekg(0, std::ios::beg); // ストリームのポインタを一番前に戻して、これから先で使いやすいようにする std::vector<BookEntry> vec2(fileSize2/sizeof(BookEntry)); ifs2.read(reinterpret_cast<char*>(&vec2[0]), fileSize2); for (auto& elem : vec2) { for (auto& ref : vec) { if (elem.key == ref.key && elem.fromToPro == ref.fromToPro) { elem.score = ref.score; break; } } } std::ofstream ofs("book.bin", std::ios::binary); ofs.write(reinterpret_cast<char*>(&vec2[0]), fileSize2); }
// A helper function which compares a content of two files bool compareFiles( const std::string & fileName1, const std::string & fileName2 ) { ifstream ifs1( fileName1.c_str() ), ifs2( fileName2.c_str() ); return NcbiStreamCompare(ifs1, ifs2); }
void writefile::backUpFile(string fileTobackUp){ string backUp= "backup"; backUp.append(fileTobackUp); //backupTest8 string pathFileToBackUp = createNewFile(fileTobackUp); //../FSQL/Test8 string pathbackUpFile = createNewBackUp(backUp);// ../FSQL/backupTest8 ofstream newfile (pathbackUpFile.c_str() , ios::trunc); newfile.close(); std::ifstream ifs(pathFileToBackUp.c_str(), std::ios::binary); std::ofstream ofs(pathbackUpFile.c_str(), std::ios::binary); ofs << ifs.rdbuf(); ifs.close(); ofs.close(); pathFileToBackUp.append("Columns"); pathbackUpFile.append("Columns"); ofstream newfile2 (pathbackUpFile.c_str() , ios::trunc); newfile2.close(); std::ifstream ifs2(pathFileToBackUp.c_str(), std::ios::binary); std::ofstream ofs2(pathbackUpFile.c_str(), std::ios::binary); ofs2 << ifs2.rdbuf(); ifs2.close(); ofs2.close(); }
/** * @brief writefile::restoreFile * @param fileToRestore */ void writefile::restoreFile(string fileToRestore){ string backUp= "backup"; backUp.append(fileToRestore); string pathFileToRestore = createNewBackUp(backUp); string pathRestoredFile = createNewFile(fileToRestore); ofstream newfile (pathRestoredFile.c_str() , ios::trunc); newfile.close(); std::ifstream ifs(pathFileToRestore.c_str(), std::ios::binary); std::ofstream ofs(pathRestoredFile.c_str(), std::ios::binary); ofs << ifs.rdbuf(); ifs.close(); ofs.close(); pathFileToRestore.append("Columns"); pathRestoredFile.append("Columns"); ofstream newfile2 (pathRestoredFile.c_str() , ios::trunc); newfile2.close(); std::ifstream ifs2(pathFileToRestore.c_str(), std::ios::binary); std::ofstream ofs2(pathRestoredFile.c_str(), std::ios::binary); ofs2 << ifs2.rdbuf(); ifs2.close(); ofs2.close(); }
void FilesGrouper::mergeSortedFiles(string fs1, string fs2, string output_file) { ofstream merged_file(output_file); string s1, s2; ifstream ifs1(fs1); ifstream ifs2(fs2); getline(ifs1, s1); getline(ifs2, s2); while (ifs1.good() && ifs2.good()) { if (s1 < s2) { merged_file << s1; getline(ifs1, s1); } else { merged_file << s2; getline(ifs2, s2); } merged_file << "\n"; } // finish off the remaining of each file and appending the previously read file name if (ifs1.good()) { merged_file << s1 << "\n"; while (getline(ifs1, s1)) merged_file << s1 << "\n"; } else { merged_file << s2 << "\n"; while (getline(ifs2, s2)) merged_file << s2 << "\n"; } merged_file.close(); }
void read_file(std::string input1,std::string input2,std::string input3){ std::ifstream ifs1(input1.c_str()); std::ifstream ifs2(input2.c_str()); std::ifstream ifs3(input3.c_str()); float label1; ifs1 >> input1; ifs1 >> label1; ifs1 >> label1; ifs2 >> input2; ifs2 >> label1; ifs2 >> label1; ifs3 >> input3; ifs3 >> label1; ifs3 >> label1; int num=0; int pos[3]={0}; int neg[3]={0}; int other; float label2,label3; while(!ifs1.eof()){ ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; if(label1 < OTHER && label2 < OTHER && label3 <OTHER) other++; if(label1>label2){ if(label1>label3) pos[0]++; else pos[2]++; } else if(label1<label2){ if(label2>label3) pos[1]++; else pos[2]++; } ifs1 >> label1; ifs2 >> label2; ifs3 >> label3; num++; } for(int i=1;i<=3;i++){ std::cout << i << ":" << (float)pos[i-1]/num*100 << " "; } std::cout << other << ":" <<(float)other/num*100 << " "; std::cout << "\n"; }
void Vocabulary::loadPretrainedVector(const std::string& file){ std::ifstream ifs1(file.c_str()); std::ifstream ifs2((file+".score").c_str()); assert(ifs1 && ifs2); for (std::string line; std::getline(ifs1, line); ){ std::vector<std::string> res; boost::split(res, line, boost::is_space()); std::unordered_map<std::string, int>::iterator it = this->nounIndices.find(res[0]); if (it != this->nounIndices.end()){ for (int i = 0; i < this->wordDim; ++i){ this->nounVector.coeffRef(i, it->second) = atof(res[i+1].c_str()); } } it = this->contextIndices.find(res[0]); if (it != this->contextIndices.end()){ for (int i = 0; i < this->wordDim; ++i){ this->contextVector.coeffRef(i, it->second) = atof(res[i+1].c_str()); } } } for (std::string line; std::getline(ifs2, line); ){ std::vector<std::string> res; boost::split(res, line, boost::is_space()); std::unordered_map<std::string, int>::iterator it = this->contextIndices.find(res[0]); if (it != this->contextIndices.end()){ for (int i = 0; i < this->wordDim; ++i){ this->scoreVector.coeffRef(i, it->second) = atof(res[i+1].c_str()); } } } }
void FilesGrouper::addFilesToSort(istream &ifs, bool l_entered) { if (l_entered) cout << "Enter all files to be merged into one file, when finished, enter 'q':\n"; string filename; ofstream ofs(new_file); ofstream ofsEnteredFiles(listed_files); while (getline(ifs, filename)) { if (l_entered && filename == "q") break; if (filename != "") { ofs << filename << "\n"; ofsEnteredFiles << (filename + "_copy") << "\n"; } } ofs.close(); ofsEnteredFiles.close(); // Iterate through the file and parse ifstream ifs2(new_file); ofs.open(current_file); // purpose is not to overwrite main file containing list of files to merge while (getline(ifs2, filename)) { if (sortFile(filename)) { ofs << filename; if (duplicate_original_file) ofs << "_copy"; ofs << "\n"; } } // Update all the subfiles generated presorted files thus no need to sort file for (int i = 0; i < subfile_count; ++i) { ofs << ("sub_file_" + to_string(i)) << "\n"; } ofs.close(); }
int main(int argc, char* argv[]) { std::string filename1, filename2; po::options_description hidden("Hidden options"); hidden.add_options() ("input-file1", po::value<std::string>(&filename1), "The first collection of persistence diagrams") ("input-file2", po::value<std::string>(&filename2), "The second collection of persistence diagrams"); po::positional_options_description p; p.add("input-file1", 1); p.add("input-file2", 2); po::options_description all; all.add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). options(all).positional(p).run(), vm); po::notify(vm); if (!vm.count("input-file1") || !vm.count("input-file2")) { std::cout << "Usage: " << argv[0] << " input-file1 input-file2" << std::endl; std::cout << hidden << std::endl; return 1; } std::ifstream ifs1(filename1.c_str()), ifs2(filename2.c_str()); boost::archive::binary_iarchive ia1(ifs1), ia2(ifs2); std::map<Dimension, PDgm> dgms1, dgms2; ia1 >> dgms1; ia2 >> dgms2; std::cout << "Distance between dimension 0: " << bottleneck_distance(dgms1[0], dgms2[0]) << std::endl; std::cout << "Distance between dimension 1: " << bottleneck_distance(dgms1[1], dgms2[1]) << std::endl; std::cout << "Distance between dimension 2: " << bottleneck_distance(dgms1[2], dgms2[2]) << std::endl; }
int main(int argc, char *argv[]){ if( argc != 3 ){ std::cout<<"provide filename with the blob"<<std::endl; return 0; } // L1TriggerKeyStage1 deserializedObject; l1t::CaloParams deserializedObject1, deserializedObject2; std::ifstream ifs(argv[1], std::ios::in | std::ios::binary); cond::serialization::InputArchive ia(ifs); std::cout << "Deserializing " << typeid(l1t::CaloParams).name() << " ..." << std::endl; ia >> deserializedObject1; std::ifstream ifs2(argv[2], std::ios::in | std::ios::binary); cond::serialization::InputArchive ia2(ifs2); std::cout << "Deserializing " << typeid(l1t::CaloParams).name() << " ..." << std::endl; ia2 >> deserializedObject2; return 0; }
void XMLScannerTest::run() { //create a dummy map with a fakie f*****g modulewhateverinfo.... std::vector<std::pair<std::string, std::string> > outs(1); std::vector<std::pair<std::string, std::string> > ins(0); std::pair<std::string, std::string> outpair("typ_string", "String"); outs[0] = outpair; //Xpm dummy(dummyXpm, strlen(dummyXpm)+1); ModuleInfo* mi = new ModuleInfo("mod_stringModule", "String", ins, outs, true); std::vector<std::pair<std::string, std::string> > outs2(0); std::vector<std::pair<std::string, std::string> > ins2(1); std::pair<std::string, std::string> inpair("typ_framebuffer", "Bild"); ins2[0] = inpair; ModuleInfo* mi2 = new ModuleInfo("mod_glOutputModule", "GLoutput" , ins, outs, false); std::vector<std::pair<std::string, std::string> > outs3(1); std::vector<std::pair<std::string, std::string> > ins3(3); std::pair<std::string, std::string> inpair2("typ_number","Zahl"); ins3[0] = inpair2; ins3[1] = inpair2; ins3[2] = inpair; outs3[0] = inpair; ModuleInfo* mi3 = new ModuleInfo("mod_tunnelModule", "Tunnel" , ins, outs, false); std::map<int, ModuleInfo*> mi_map; mi_map[0] = mi; mi_map[1] = mi2; mi_map[2] = mi3; //create storage room for the listener std::map<std::string, int> infos; std::map<std::string, std::pair<int,int> > nodes; std::map<int, std::string> nodeIDs; std::map<std::string, std::pair<int,int> > controls; std::map<int, std::string> controlIDs; std::map<std::pair<int,int>, std::pair<int,int> > conns; std::map<std::pair<int,int>, std::pair<int,int> > ctrlconns; //create an xmlListener with that dummyinfo XMLTokenListener horcher(mi_map, infos, nodes, nodeIDs, controls, controlIDs, conns, ctrlconns); XMLFileScanner gucker(horcher); std::ifstream ifs("testCorrect.graph"); if(ifs==0) std::cout<<"File not found \n"; std::string testTextCorrect; char tmp; while(ifs.get(tmp)) { testTextCorrect += tmp; } gucker.scan(testTextCorrect); //eine datei ohne <model> //std::cout<<"Processing incorrect file 1...\n"; std::ifstream ifs1("testInCorrect1.graph"); if(ifs1==0) std::cout<<"File not found \n"; std::string testTextInCorrect1; while(ifs.get(tmp)) { testTextInCorrect1 += tmp; } try { gucker.scan(testTextInCorrect1); } catch(std::runtime_error err) { //if(err.what() != "This is no Ge-Phex Graph file...go f**k your dog!!!") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } //eine datei ohne </model>, ja, ich weiss, kreativ... //std::cout<<"Processing incorrect file 2...\n"; std::ifstream ifs2("testInCorrect2.graph"); if(ifs2==0) std::cout<<"File not found \n"; std::string testTextInCorrect2; while(ifs2.get(tmp)) { testTextInCorrect2 += tmp; } try { gucker.scan(testTextInCorrect2); } catch(std::runtime_error err) { //if(err.what() != "File has a wrong finishing tag...wrong format") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } //eine datei mit fehlender node section //std::cout<<"Processing incorrect file 3...\n"; std::ifstream ifs3("testInCorrect3.graph"); if(ifs3==0) std::cout<<"File not found \n"; std::string testTextInCorrect3; while(ifs3.get(tmp)) { testTextInCorrect3 += tmp; } try { gucker.scan(testTextInCorrect3); } catch(std::runtime_error err) { //if(err.what() != "File has wrong format...section nodes") // throw std::runtime_error(err.what()); //std::cout<<err.what()<<std::endl; } }
bool Read3DDataTest::ReadAndCompare( const std::string& dcmInputNameEnd, const std::string& vtkFileNameEnd, const TYPE& inputType ) const { try { // Working directory of the test const std::string dcmInputName = std::string(CISTIB_TOOLKIT_FOLDER) + dcmInputNameEnd; const std::string vtkFileName = std::string(CISTIB_TOOLKIT_FOLDER) + vtkFileNameEnd; // Check if the vtk file exists std::ifstream ifs2( vtkFileName.c_str() ); TSM_ASSERT( "The input VTK file does not exist.", !ifs2.fail() ); if( ifs2.fail() ) return false; ifs2.close(); // read input vtkSmartPointer<vtkImageData> vtkDicomImage; switch( inputType ) { case FILE: { // Check if the dicom file exists std::ifstream ifs1( dcmInputName.c_str() ); TSM_ASSERT( "The input DICOM file does not exist.", !ifs1.fail() ); if( ifs1.fail() ) return false; ifs1.close(); // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadVtkImageFromFile< unsigned short, 3 >( dcmInputName.c_str(), true ); } break; case FOLDER: { // Check if the folder exists if ( !boost::filesystem::exists( dcmInputName ) ) return false; // create list of files std::vector< std::string > dcmFileNames; boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end for( boost::filesystem::directory_iterator itr( dcmInputName ); itr != end_itr; ++itr ) { if( is_regular_file(itr->status()) && itr->leaf() != "DICOMDIR") { dcmFileNames.push_back( dcmInputName + "/" + itr->leaf() ); } } // sort the files alphabetically std::sort(dcmFileNames.begin(), dcmFileNames.end()); // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( dcmFileNames, true ); } break; case DICOMDIR: { // Data set dcmAPI::DataSet::Pointer dcmData = dcmAPI::DataSet::New(); // scan the current working folder for dicom files dcmAPI::DataSetReader::Pointer reader = dcmAPI::DataSetReader::New( ); reader->SetDataSet( dcmData ); reader->ReadDicomDir( dcmInputName ); // Patient const dcmAPI::Patient::Pointer patient = dcmData->GetPatient( dcmData->GetPatientIds()->at(0) ); // Study const dcmAPI::Study::Pointer study = patient->Study( patient->StudyIds()->at(0) ); // Serie const dcmAPI::Series::Pointer series = study->Series( study->SeriesIds()->at(0) ); // TimePoint const dcmAPI::TimePoint::Pointer timePoint = series->TimePoint( series->TimePointIds()->at(0) ); // Slice const dcmAPI::SliceIdVectorPtr sliceIdVector = timePoint->SliceIds(); std::vector< std::string > dcmFileNames; for( unsigned int i=0; i < sliceIdVector->size(); ++i) { const dcmAPI::Slice::Pointer slice = timePoint->Slice(sliceIdVector->at(i)); const std::string filePath = slice->GetTagAsText(dcmAPI::tags::SliceFilePath); dcmFileNames.push_back( filePath ); } // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( dcmFileNames, true ); } break; default: { TS_FAIL("Read3DDataTest::ReadAndCompare failed: unknwown case."); return false; } } // Read using BaseLib vtkSmartPointer<vtkImageData> vtkImage = blImageUtils::LoadImageFromFileAsVTK( vtkFileName.c_str() ); // Compare image content return blImageUtils::CompareImages( vtkDicomImage, vtkImage, 1e-5 ); } catch(...) { TS_FAIL("Read3DDataTest::ReadAndCompare failed: thrown exception."); return false; } }
static bool eval(int argc, char **argv) { static const MeCab::Option long_options[] = { { "level", 'l', "0 -1", "STR", "set level of evaluations" }, { "output", 'o', 0, "FILE", "set the output file name" }, { "version", 'v', 0, 0, "show the version and exit" }, { "help", 'h', 0, 0, "show this help and exit." }, { 0, 0, 0, 0 } }; MeCab::Param param; param.open(argc, argv, long_options); if (!param.open(argc, argv, long_options)) { std::cout << param.what() << "\n\n" << COPYRIGHT << "\ntry '--help' for more information." << std::endl; return -1; } if (!param.help_version()) return 0; const std::vector<std::string> &files = param.rest_args(); if (files.size() < 2) { std::cout << "Usage: " << param.program_name() << " output answer" << std::endl; return -1; } std::string output = param.get<std::string>("output"); if (output.empty()) output = "-"; MeCab::ostream_wrapper ofs(output.c_str()); CHECK_DIE(*ofs) << "no such file or directory: " << output; const std::string system = files[0]; const std::string answer = files[1]; const std::string level_str = param.get<std::string>("level"); std::ifstream ifs1(files[0].c_str()); std::ifstream ifs2(files[1].c_str()); CHECK_DIE(ifs1) << "no such file or directory: " << files[0].c_str(); CHECK_DIE(ifs2) << "no such file or directory: " << files[0].c_str(); CHECK_DIE(!level_str.empty()) << "level_str is NULL"; std::vector<int> level; parseLevel(level_str.c_str(), &level); CHECK_DIE(level.size()) << "level_str is empty: " << level_str; std::vector<size_t> result_tbl(level.size()); std::fill(result_tbl.begin(), result_tbl.end(), 0); size_t prec = 0; size_t recall = 0; std::vector<std::vector<std::string> > r1; std::vector<std::vector<std::string> > r2; while (true) { if (!read(&ifs1, &r1, level) || !read(&ifs2, &r2, level)) break; size_t i1 = 0; size_t i2 = 0; size_t p1 = 0; size_t p2 = 0; while (i1 < r1.size() && i2 < r2.size()) { if (p1 == p2) { for (size_t i = 0; i < result_tbl.size(); ++i) { if (r1[i1][i] == r2[i2][i]) { result_tbl[i]++; } } p1 += r1[i1][0].size(); p2 += r2[i2][0].size(); ++i1; ++i2; ++prec; ++recall; } else if (p1 < p2) { p1 += r1[i1][0].size(); ++i1; ++prec; } else { p2 += r2[i2][0].size(); ++i2; ++recall; } } while (i1 < r1.size()) { ++prec; ++i1; } while (i2 < r2.size()) { ++recall; ++i2; } } *ofs << " precision recall F" << std::endl; for (size_t i = 0; i < result_tbl.size(); ++i) { if (level[i] == -1) { *ofs << "LEVEL ALL: "; } else { *ofs << "LEVEL " << level[i] << ": "; } printeval(&*ofs, result_tbl[i], prec, recall); } return true; }
int main() { constants_wrapper cfg; cfg.show(); InitRNG RNG; RNG.seed(cfg.SEED); int a(0); if (!a) std::cout << "TRUEEEEE!!!" << std::endl; std::cout << std::endl << std::endl; std::cout << "X_MIN = " << cfg.X_MIN << std::endl; std::cout << "X_MAX = " << cfg.X_MAX << std::endl; std::cout << "Y_MIN = " << cfg.Y_MIN << std::endl; std::cout << "Y_MAX = " << cfg.Y_MAX << std::endl; std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl; std::cout << "FOOD_POINT_DISTRIBUTION = " << cfg.FOOD_POINT_DISTRIBUTION << std::endl; chromo beauty_d(beauty_default); chromo dim_d(dim_default); chromo athlet_d(athlet_default); chromo karma_d(karma_default); chromo attracted_d(attracted_default); chromo charm_d(charm_default); DNA dna1(charm_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d); DNA dna2(attracted_d, beauty_d, dim_d, athlet_d, karma_d, attracted_d); //dna2.set_chromo(c1,5); if (dna1 == dna2) { std::cout << "TRUE1" << std::endl; } else { std::cout << "qualche problema" << std::endl; }; being conf_being(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0); conf_being.configure(cfg); being b1(dna1, 0, cfg.starting_energy, true, 1.0, 2.0, 0, 0); //b1.show(); being b2(dna2, 0, 100, true, 2.0, 2.0, 0, 0); food_point fp2(4.1, 4.2, cfg.default_nutrival); food_point fp3(1.1, 2.2, cfg.default_nutrival); point_2d p1(1,1); point_2d p2(2,2); // create and open a character archive for output std::ofstream ofs("./points.txt"); // save data to archive { boost::archive::text_oarchive oa(ofs); // write class instance to archive oa << p1; oa << p2; oa << beauty_d; oa << dna1; oa << b1; // archive and stream closed when destructors are called } // ... some time later restore the class instance to its orginal state point_2d p1new; point_2d p2new; chromo new_beauty; DNA dna1new; being b1new; { // create and open an archive for input std::ifstream ifs("./points.txt"); boost::archive::text_iarchive ia(ifs); // read class state from archive ia >> p1new; ia >> p2new; ia >> new_beauty; ia >> dna1new; ia >> b1new; // archive and stream closed when destructors are called } std::cout << "P1new = "; p1new.show_point(); std::cout << std::endl; std::cout << "P2new = "; p2new.show_point(); std::cout << std::endl; std::cout << "new beauty = " << new_beauty << std::endl; std::cout << "newdna1 = " << dna1new << std::endl; if (dna1 == dna1new) std::cout << "TRUE!" << std::endl; std::cout << "B1NEW = " << std::endl << b1new << std::endl; world myworld(cfg.N_BEINGS,cfg.N_FOOD_POINT_AT_START); myworld.name("MyWorld"); std::cout << "World name = " << myworld.name() << std::endl; //myworld.add(b1); //myworld.add(b2); //myworld.add(fp2); //myworld.add(fp3); //myworld.stats(); //myworld.advance_one_generation(); //myworld.stats(); // myworld.load("DATA/200.txt"); // myworld.stats(); // myworld.evolve(1); // myworld.stats(); std::vector<int> iv; iv.reserve(10); for (int i=0; i<10; ++i) iv.push_back(i); std::vector<int>::iterator iv_end = iv.end(); for (std::vector<int>::iterator it = iv.begin(); it!=iv_end; ++it) { std::cout << *it << std::endl; iv.push_back(11); } if (cfg.BEINGS_START_DISTRIBUTION == "UNIFORM") { std::uniform_real_distribution<float> beings_distribution_x(cfg.X_MIN , cfg.X_MAX); std::uniform_real_distribution<float> beings_distribution_y(cfg.Y_MIN , cfg.Y_MAX); for (int i = 0; i < cfg.N_BEINGS; ++i) { b1.set_x(beings_distribution_x(RNG.generator)); b1.set_y(beings_distribution_y(RNG.generator)); myworld.add(b1) ; }; }; std::cout << "READ_FOOD_FROM_FILE = " << cfg.READ_FOOD_FROM_FILE << std::endl; if (!cfg.READ_FOOD_FROM_FILE) { std::cout << "Creating food point from scratch" << std::endl; if (cfg.FOOD_POINT_DISTRIBUTION == "UNIFORM") { std::uniform_real_distribution<float> food_distribution_x(cfg.X_MIN , cfg.X_MAX); std::uniform_real_distribution<float> food_distribution_y(cfg.Y_MIN , cfg.Y_MAX); for (int i = 0; i < cfg.N_FOOD_POINT_AT_START; ++i) { food_point fpx( food_distribution_x(RNG.generator) , food_distribution_y(RNG.generator) , cfg.default_nutrival ); myworld.add(fpx) ; } } } else { std::cout << "Reading food points from file = " << cfg.food_file << std::endl; // create and open an archive for input std::ifstream ifs2(cfg.food_file); boost::archive::text_iarchive ia(ifs2); food_point newfp; // read class state from archive for (int i=0; i<cfg.N_FOOD_POINT_AT_START; ++i) { ia >> newfp; myworld.add(newfp); } }; myworld.stats(); //return 0; std::chrono::time_point<std::chrono::high_resolution_clock> start, end; start = std::chrono::high_resolution_clock::now(); myworld.evolve(cfg.ITER_NUMBER); end = std::chrono::high_resolution_clock::now(); cfg.save("myworld.cfg"); std::cout << "World evolved in = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms." << std::endl; /* // create and open a character archive for output std::ofstream ofs2("./world.txt"); // save data to archive { boost::archive::text_oarchive oa(ofs2); // write class instance to archive oa << myworld; // archive and stream closed when destructors are called } world newworld(1000,1000); { // create and open an archive for input std::ifstream ifs2("./world.txt"); boost::archive::text_iarchive ia(ifs2); // read class state from archive ia >> newworld; // archive and stream closed when destructors are called } newworld.stats(); */ return 0; };
int test_main(int /* argc */, char * /* argv */[]) { std::locale old_loc; std::locale * utf8_locale = boost::archive::add_facet( old_loc, new boost::archive::detail::utf8_codecvt_facet ); typedef char utf8_t; typedef test_data<sizeof(wchar_t)> td; // Send our test UTF-8 data to file { std::ofstream ofs; ofs.open("test.dat", std::ios::binary); std::copy( td::utf8_encoding, #if ! defined(__BORLANDC__) // borland 5.60 complains about this td::utf8_encoding + sizeof(td::utf8_encoding) / sizeof(unsigned char), #else // so use this instead td::utf8_encoding + 12, #endif boost::archive::iterators::ostream_iterator<utf8_t>(ofs) ); } // Read the test data back in, converting to UCS-4 on the way in std::vector<wchar_t> from_file; { std::wifstream ifs; ifs.imbue(*utf8_locale); ifs.open("test.dat"); wchar_t item = 0; // note can't use normal vector from iterator constructor because // dinkumware doesn't have it. for(;;) { item = ifs.get(); if(item == WEOF) break; //ifs >> item; //if(ifs.eof()) // break; from_file.push_back(item); } } // compare the data read back in with the orginal #if ! defined(__BORLANDC__) // borland 5.60 complains about this BOOST_CHECK(from_file.size() == sizeof(td::wchar_encoding)/sizeof(wchar_t)); #else // so use this instead BOOST_CHECK(from_file.size() == 6); #endif BOOST_CHECK(std::equal(from_file.begin(), from_file.end(), td::wchar_encoding)); // Send the UCS4_data back out, converting to UTF-8 { std::wofstream ofs; ofs.imbue(*utf8_locale); ofs.open("test2.dat"); std::copy( from_file.begin(), from_file.end(), boost::archive::iterators::ostream_iterator<wchar_t>(ofs) ); } // Make sure that both files are the same { typedef boost::archive::iterators::istream_iterator<utf8_t> is_iter; is_iter end_iter; std::ifstream ifs1("test.dat"); is_iter it1(ifs1); std::vector<utf8_t> data1; std::copy(it1, end_iter, std::back_inserter(data1)); std::ifstream ifs2("test2.dat"); is_iter it2(ifs2); std::vector<utf8_t> data2; std::copy(it2, end_iter, std::back_inserter(data2)); BOOST_CHECK(data1 == data2); } // some libraries have trouble that only shows up with longer strings wchar_t * test3_data = L"\ <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\ <!DOCTYPE boost_serialization>\ <boost_serialization signature=\"serialization::archive\" version=\"3\">\ <a class_id=\"0\" tracking_level=\"0\">\ <b>1</b>\ <f>96953204</f>\ <g>177129195</g>\ <l>1</l>\ <m>5627</m>\ <n>23010</n>\ <o>7419</o>\ <p>16212</p>\ <q>4086</q>\ <r>2749</r>\ <c>-33</c>\ <s>124</s>\ <t>28</t>\ <u>32225</u>\ <v>17543</v>\ <w>0.84431422</w>\ <x>1.0170664757130923</x>\ <y>tjbx</y>\ <z>cuwjentqpkejp</z>\ </a>\ </boost_serialization>\ "; // Send the UCS4_data back out, converting to UTF-8 std::size_t l = std::wcslen(test3_data); { std::wofstream ofs; ofs.imbue(*utf8_locale); ofs.open("test3.dat"); std::copy( test3_data, test3_data + l, boost::archive::iterators::ostream_iterator<wchar_t>(ofs) ); } // Make sure that both files are the same { std::wifstream ifs; ifs.imbue(*utf8_locale); ifs.open("test3.dat"); BOOST_CHECK( std::equal( test3_data, test3_data + l, boost::archive::iterators::istream_iterator<wchar_t>(ifs) ) ); } delete utf8_locale; return EXIT_SUCCESS; }
int main(int argc, char ** argv){ // check input if(argc < 3){ std::cout << "Usage: difference <file1.g2o> <file2.g2o>" << std::endl; return 0; } init(); // allocate the optimizers g2o::SparseOptimizer * optimizer1 = new g2o::SparseOptimizer(); g2o::SparseOptimizer * optimizer2 = new g2o::SparseOptimizer(); SlamLinearSolver* linearSolver = new SlamLinearSolver(); linearSolver->setBlockOrdering(false); SlamBlockSolver* blockSolver = new SlamBlockSolver(linearSolver); g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton(blockSolver); optimizer1->setAlgorithm(solver); optimizer2->setAlgorithm(solver); // load the graphs std::ifstream ifs1(argv[1]); std::ifstream ifs2(argv[2]); if(!ifs1){ std::cout << "Cannot open file " << argv[1] << std::endl; return 1; } if(!ifs2){ std::cout << "Cannot open file " << argv[2] << std::endl; return 1; } if(!optimizer1->load(ifs1)){ std::cout << "Error loading graph #1" << std::endl; return 2; } if(!optimizer2->load(ifs2)){ std::cout << "Error loading graph #2" << std::endl; return 2; } std::cout << "graph #1:"; std::cout << "\tLoaded " << optimizer1->vertices().size() << " vertices" << std::endl; std::cout << "\tLoaded " << optimizer1->edges().size() << " edges" << std::endl; std::cout << "graph #2:"; std::cout << "\tLoaded " << optimizer1->vertices().size() << " vertices" << std::endl; std::cout << "\tLoaded " << optimizer1->edges().size() << " edges" << std::endl; g2o::HyperGraph::VertexIDMap map1 = optimizer1->vertices(); g2o::HyperGraph::VertexIDMap map2 = optimizer2->vertices(); // safety checks std::cout << "safety checks..."; if(optimizer1->vertices().size() != optimizer2->vertices().size()){ std::cout << "!!! the two graphs don't have the same number of vertices !!!" << std::endl; return 3; } for(g2o::HyperGraph::VertexIDMap::iterator it=map1.begin(); it!=map1.end(); it++){ g2o::OptimizableGraph::Vertex * v1 = (g2o::OptimizableGraph::Vertex *) it->second; int dim = v1->minimalEstimateDimension(); if(dim!=3 & dim!=2){ std::cerr << "Vertex #" << v1->id() << " has strange dimension: " << dim << std::endl; return 4; } // get the corresponding vertex in the other graph g2o::OptimizableGraph::Vertex * v2 = (g2o::OptimizableGraph::Vertex *) map2[v1->id()]; assert(v2->id() == v1->id()); if(v2->minimalEstimateDimension() != dim){ std::cerr << "ERROR: vertex " << v2->id() << " has different dimension in the two graphs" << std::endl; return 5; } } std::cout << "done" << std::endl; std::vector<g2o::OptimizableGraph::Vertex*> vertices; for(g2o::HyperGraph::VertexIDMap::iterator it=map1.begin(); it!=map1.end(); it++){ vertices.push_back((g2o::OptimizableGraph::Vertex *)it->second); } std::cout << "vertices vector filled" << std::endl; bool visited[vertices.size()]; for(unsigned int i=0; i<vertices.size(); i++){ visited[i] = false; } thread_struct t_struct; t_struct.map1 = &map1; t_struct.map2 = &map2; t_struct.vertices = &vertices; t_struct.visited = visited; pthread_t threads[_num_threads + 1]; for(unsigned int i=0; i<_num_threads; i++){ pthread_create(threads+i, NULL, launch_analyze, &t_struct); } visualizer_struct v_struct; v_struct.visited = visited; v_struct.size = vertices.size(); pthread_create(threads+_num_threads, NULL, launch_visualize, &v_struct); std::cout << "threads launched" << std::endl; for(unsigned int i=0; i<_num_threads+1; i++){ pthread_join(threads[i], NULL); } std::cout << "minimum error = " << _best_error; }
bool CharProperty::compile(const char *cfile, const char *ufile, const char *ofile) { scoped_fixed_array<char, BUF_SIZE> line; scoped_fixed_array<char *, 512> col; size_t id = 0; std::vector<Range> range; std::map<std::string, CharInfo> category; std::vector<std::string> category_ary; std::ifstream ifs(WPATH(cfile)); std::istringstream iss(CHAR_PROPERTY_DEF_DEFAULT); std::istream *is = &ifs; if (!ifs) { std::cerr << cfile << " is not found. minimum setting is used" << std::endl; is = &iss; } while (is->getline(line.get(), line.size())) { if (std::strlen(line.get()) == 0 || line[0] == '#') { continue; } const size_t size = tokenize2(line.get(), "\t ", col.get(), col.size()); CHECK_DIE(size >= 2) << "format error: " << line.get(); // 0xFFFF..0xFFFF hoge hoge hgoe # if (std::strncmp(col[0], "0x", 2) == 0) { std::string low = col[0]; std::string high; size_t pos = low.find(".."); if (pos != std::string::npos) { high = low.substr(pos + 2, low.size() - pos - 2); low = low.substr(0, pos); } else { high = low; } Range r; r.low = atohex(low.c_str()); r.high = atohex(high.c_str()); CHECK_DIE(r.low >= 0 && r.low < 0xffff && r.high >= 0 && r.high < 0xffff && r.low <= r.high) << "range error: low=" << r.low << " high=" << r.high; for (size_t i = 1; i < size; ++i) { if (col[i][0] == '#') { break; // skip comments } CHECK_DIE(category.find(std::string(col[i])) != category.end()) << "category [" << col[i] << "] is undefined"; r.c.push_back(col[i]); } range.push_back(r); } else { CHECK_DIE(size >= 4) << "format error: " << line.get(); std::string key = col[0]; CHECK_DIE(category.find(key) == category.end()) << "category " << key << " is already defined"; CharInfo c; std::memset(&c, 0, sizeof(c)); c.invoke = std::atoi(col[1]); c.group = std::atoi(col[2]); c.length = std::atoi(col[3]); c.default_type = id++; category.insert(std::pair<std::string, CharInfo>(key, c)); category_ary.push_back(key); } } CHECK_DIE(category.size() < 18) << "too many categories(>= 18)"; CHECK_DIE(category.find("DEFAULT") != category.end()) << "category [DEFAULT] is undefined"; CHECK_DIE(category.find("SPACE") != category.end()) << "category [SPACE] is undefined"; std::istringstream iss2(UNK_DEF_DEFAULT); std::ifstream ifs2(WPATH(ufile)); std::istream *is2 = &ifs2; if (!ifs2) { std::cerr << ufile << " is not found. minimum setting is used." << std::endl; is2 = &iss2; } std::set<std::string> unk; while (is2->getline(line.get(), line.size())) { const size_t n = tokenizeCSV(line.get(), col.get(), 2); CHECK_DIE(n >= 1) << "format error: " << line.get(); const std::string key = col[0]; CHECK_DIE(category.find(key) != category.end()) << "category [" << key << "] is undefined in " << cfile; unk.insert(key); } for (std::map<std::string, CharInfo>::const_iterator it = category.begin(); it != category.end(); ++it) { CHECK_DIE(unk.find(it->first) != unk.end()) << "category [" << it->first << "] is undefined in " << ufile; } std::vector<CharInfo> table(0xffff); { std::vector<std::string> tmp; tmp.push_back("DEFAULT"); const CharInfo c = encode(tmp, &category); std::fill(table.begin(), table.end(), c); } for (std::vector<Range>::const_iterator it = range.begin(); it != range.end(); ++it) { const CharInfo c = encode(it->c, &category); for (int i = it->low; i <= it->high; ++i) { table[i] = c; } } // output binary table { std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out); CHECK_DIE(ofs) << "permission denied: " << ofile; unsigned int size = static_cast<unsigned int>(category.size()); ofs.write(reinterpret_cast<const char*>(&size), sizeof(size)); for (std::vector<std::string>::const_iterator it = category_ary.begin(); it != category_ary.end(); ++it) { char buf[32]; std::fill(buf, buf + sizeof(buf), '\0'); std::strncpy(buf, it->c_str(), sizeof(buf) - 1); ofs.write(reinterpret_cast<const char*>(buf), sizeof(buf)); } ofs.write(reinterpret_cast<const char*>(&table[0]), sizeof(CharInfo) * table.size()); ofs.close(); } return true; }
int main() { ColoredGraph<GraphVertex,TriColor> gr; set<GraphVertex,less<GraphVertex> > groupsall, filesall,functionsall; set<GraphVertex,less<GraphVertex> > groupssome, filessome,functionssome,S; set<GraphVertex,less<GraphVertex> > groupsnot, filesnot,functionsnot; ifstream ifs1("groups.txt"); ifstream ifs2("files.txt"); ifstream ifs3("files.txt"); ifstream ifs4("choices.txt"); cerr << "reading groups"; readDoubleColumnGraph(ifs1,groupsall,gr,true); cerr << ", files"; readDoubleColumnGraph(ifs2,filesall,gr,true); cerr << ", functions\n"; readDoubleColumnGraph(ifs3,functionsall,gr,false); readSingleColumn(ifs4,gr); #if 1 ifstream ifs5("depends.txt"); list<list<string> > dbllist; readMultiColumns(ifs5,dbllist); #endif bool todo = true; while(todo) { todo = false; gr.ColorChildComponents(TriColor::s_one,TriColor::s_two); list<GraphVertex> L(gr.getColored(TriColor::s_two)); copy(L.begin(),L.end(),inserter(S,S.begin())); #if 1 todo = addElements(gr,TriColor::s_one,S,dbllist); cerr << "addelements give " << todo << '\n'; #endif }; cerr << "Here is the set after the loop:\n"; printset(cerr,S,","); set_intersection(S.begin(),S.end(),groupsall.begin(),groupsall.end(), inserter(groupssome,groupssome.begin())); set_intersection(S.begin(),S.end(),filesall.begin(),filesall.end(), inserter(filessome,filessome.begin())); set_intersection(functionsall.begin(),functionsall.end(),S.begin(),S.end(), inserter(functionssome,functionssome.begin())); set_difference(groupsall.begin(),groupsall.end(),S.begin(),S.end(), inserter(groupsnot,groupsnot.begin())); set_difference(filesall.begin(),filesall.end(),S.begin(),S.end(), inserter(filesnot,filesnot.begin())); set_difference(functionsall.begin(),functionsall.end(),S.begin(),S.end(), inserter(functionsnot,functionsnot.begin())); cerr << "all groups:\n"; printset(cerr,groupsall,", "); cerr << "\nall files:\n"; printset(cerr,filesall,", "); cerr << "\nall functions:\n"; printset(cerr,functionsall,", "); cerr << "\n\n\n"; cerr << "groups (not):\n"; printset(cerr,groupsnot,", "); cerr << "\nfiles (not):\n"; printset(cerr,filesnot,", "); cerr << "\nfunctions(not):\n"; printset(cerr,functionsnot,", "); cerr << "\n\n\n"; cerr << "groups:\n"; printset(cerr,groupssome,", "); cerr << "\nfiles:\n"; printset(cerr,filessome,", "); cerr << "\nfunctions:\n"; printset(cerr,functionssome,", "); cerr << "Staring creation of the file Makefile.mark\n"; ofstream ofs("Makefile.mark"); ofs << "p9clist = "; printset(ofs,filessome,".o \\\n",".o \n"); ofs.close(); cerr << "Ended creation of the file Makefile.mark\n"; cerr << "Staring creation of the file Makefile.cp\n"; ofstream ofs2("Makefile.cp"); ofs2 << "cp "; printset(ofs2,filessome,".[hc]pp copyplace/ \n cp ",".[hc]pp copyplace/ \n"); ofs2.close(); cerr << "Ended creation of the file Makefile.cp\n"; };