void FileSource::findFiles(fs::path dir, std::list<fs::path>& paths, std::string extn) { std::list<std::list<fs::path>> branch_paths; if (fs::exists(dir) && fs::is_directory(dir)) { boost::thread_group threads; fs::directory_iterator end_itr; for(fs::directory_iterator itr(dir); itr != end_itr; ++itr) { if (fs::is_regular_file(itr->status())) { if (itr->path().extension() == extn) { //cout<<itr->path()<<endl; paths.push_back(itr->path()); } } else if (fs::is_directory(itr->status())) { std::list<fs::path> leaf; branch_paths.push_back(leaf); threads.create_thread(boost::bind(&FileSource::findFiles, this, itr->path(), boost::ref(branch_paths.back()), extn)); } } threads.join_all(); if (branch_paths.size()) { for(auto& path : branch_paths) paths.merge(path); } } }
void Map::child_merge(std::list<Entity *> &pull_) { if (level == MAX_LEVEL) { if (!pull.empty()) { pull_.merge(pull); count = 0; } return; } if (!pull.empty()) { pull_.merge(pull); count = 0; } NW->child_merge(pull); NE->child_merge(pull); SW->child_merge(pull); SE->child_merge(pull); }
void MatchPool::Proc(std::list<MatchRes> &resList) { std::map<int, MatchPool*>::iterator itr; for (itr = s_pools.begin(); itr != s_pools.end(); ++itr) { std::list<MatchRes> tmpList;; if (itr->second->tick(tmpList)) { resList.merge(tmpList); } } }
bool addDepends(std::list<IDownload*>& dls) { std::list<IDownload*>::iterator it; for (it = dls.begin(); it != dls.end(); ++it) { if ((*it)->depend.empty()) { continue; } std::list<std::string>::iterator stit; for (stit = (*it)->depend.begin(); stit != (*it)->depend.end(); ++stit) { std::list<IDownload*> depends; const std::string& depend = (*stit); search(DL_ANY, CAT_ANY, depend.c_str(), depends); LOG_INFO("Adding depend %s", depend.c_str()); dls.merge(depends); } } return true; }
//LABELSETTING long int runLabelSetting(std::vector<Box*> &vectorBox, Data &data, std::list<Solution> & allSolution) { std::vector<Box*>::iterator itVector; for (itVector = vectorBox.begin(); itVector != vectorBox.end(); ++itVector) { LabelSetting m(*(*itVector)); m.compute(); allSolution.merge(m.nodes_[m.getRank() - 1].labels_); } filterListSolution(allSolution); if (Argument::mode_export) { ToFile::saveYN(allSolution, data); } return (long int) allSolution.size(); }
// Multi-objective genetic algorithm long int runMOGA(std::vector<Box*> &vectorBox, Data &data, std::list<Solution> & allSolution) { std::vector<Box*>::iterator itVector; FILE * pipe_fp = 0; // Gnuplot pipe int object_id = 0; // OPEN GNUPLOT (interactive mode) if (Argument::interactive) { if ( ( pipe_fp = popen("gnuplot", "w") ) != 0 ) { int num_obj = (*vectorBox.begin())->getNbObjective(); std::vector<double> minZ( num_obj, std::numeric_limits<double>::infinity() ), maxZ( num_obj, -std::numeric_limits<double>::infinity() ); for (itVector = vectorBox.begin(); itVector != vectorBox.end(); ++itVector) { for ( int k = 0; k < (*(*itVector)).getNbObjective(); ++k ) { minZ[k] = std::min( (*(*itVector)).getMinZ( k ), minZ[k] ); maxZ[k] = std::max( (*(*itVector)).getMaxZ( k ), maxZ[k] ); } } fputs( "set nokey\n", pipe_fp ); fputs( "set xlabel \"$z_1$\"\n", pipe_fp ); fputs( "set ylabel \"$z_2$\"\n", pipe_fp ); fprintf( pipe_fp, "set xrange [%f:%f]\n", minZ[0], maxZ[0] ); fprintf( pipe_fp, "set yrange [%f:%f]\n", minZ[1], maxZ[1] ); } else { std::cerr << "Error: gnuplot pipe failed" << std::endl; } } // Apply MOGA on each box for (itVector = vectorBox.begin(); itVector != vectorBox.end(); ++itVector) { // Draw the box associated if ( pipe_fp ) { ++object_id; fprintf( pipe_fp, "set object %d rectangle from %f,%f to %f,%f fillstyle empty\n", object_id, (*(*itVector)).getMinZ(0), (*(*itVector)).getMinZ(1), (*(*itVector)).getMaxZ(0), (*(*itVector)).getMaxZ(1) ); } MOGA m(*(*itVector), Argument::num_individuals, Argument::num_generations, Argument::Pc, Argument::Pm); m.pipe_fp_ = pipe_fp; m.compute(); allSolution.merge(m.solutions_); } // CLOSE GNUPLOT if ( pipe_fp ) { pclose(pipe_fp); } // FILTERING DOMINATED SOLUTIONS for ( std::list<Solution>::iterator it1 = allSolution.begin(); it1 != allSolution.end(); ++it1 ) { for ( std::list<Solution>::iterator it2 = it1; it2 != allSolution.end(); ++it2 ) { bool dominates = true, dominated = true; for (int k = 0; k < (*it1).getNbObjective() && (dominates || dominated); ++k) { if ( !( (*it1).getObj( k ) < (*it2).getObj( k ) ) ) dominates = false; if ( !( (*it2).getObj( k ) < (*it1).getObj( k ) ) ) dominated = false; } if ( dominates ) { it2 = allSolution.erase( it2 ); --it2; } if ( dominated ) { it1 = allSolution.erase( it1 ); --it1; break; } } } if (Argument::mode_export) { ToFile::saveYN(allSolution, data); } return (long int) allSolution.size(); }