inline void lru_cache_cab::insert(const bucket* pbuck, const double & time) { assert(cache.size() + flow_table.size() <=_capacity); buffer_check.insert(std::make_pair(pbuck, time)); // insert bucket as rec cache.insert(container_T::value_type(pbuck, time)); // insert bucket for (auto iter = pbuck->related_rules.begin(); iter != pbuck->related_rules.end(); iter++) { // rule_down_count += 1; // controller does not know which rules are kept in OFswtich auto ins_rule_result = flow_table.insert(std::make_pair(*iter, 1)); if (!ins_rule_result.second) ++ins_rule_result.first->second; else ++rule_down_count; // controller knows which rules are kept in OFswitch } while(cache.size() + flow_table.size() > _capacity) // kick out { const bucket * to_kick_buck = cache.right.begin()->second; cache.right.erase(cache.right.begin()); buffer_check.erase(to_kick_buck); for (auto iter = to_kick_buck->related_rules.begin(); iter != to_kick_buck->related_rules.end(); ++iter) // dec flow occupy no. { --flow_table[*iter]; if (flow_table[*iter] == 0) flow_table.erase(*iter); } } }
static double score2(const boost::unordered_map<int, double> &m0, const boost::unordered_map<int, double> &m1) { int tmp = 0; auto i0 = m0.begin(); auto i1 = m1.begin(); while (i0 != m0.end() && i1 != m1.end()) { if (i0->first < i1->first) ++i0; else if (i0->first > i1->first) ++i1; else ++tmp, ++i0, ++i1; } return m0.size() + m1.size() - tmp; }
void IfcTreeWidget::slotObjectsSelected( boost::unordered_map<int, shared_ptr<IfcPPEntity> >& map ) { if( m_block_selection_signals ) { return; } if( map.size() < 1 ) { return; } // take the first object from map and highlight it shared_ptr<IfcPPEntity> object = (*(map.begin())).second; int selected_id = object->m_id; for( int i=0; i<topLevelItemCount(); ++i ) { QTreeWidgetItem* toplevel_item = topLevelItem( i ); QTreeWidgetItem* selected_item = ViewerUtil::findItemByIfcId( toplevel_item, selected_id ); if( selected_item != 0 ) { blockSignals(true); m_block_selection_signals = true; setCurrentItem( selected_item, 1, QItemSelectionModel::SelectCurrent ); blockSignals(false); m_block_selection_signals = false; break; } } }
std::string srv_scrape(const Ctracker_input& ti, t_user* user) { if (m_use_sql && m_config.m_log_scrape) m_scrape_log_buffer += Csql_query(m_database, "(?,?,?),")(ntohl(ti.m_ipa))(user ? user->uid : 0)(srv_time()).read(); if (!m_config.m_anonymous_scrape && !user) return "d14:failure reason25:unregistered torrent passe"; std::string d; d += "d5:filesd"; if (ti.m_info_hashes.empty()) { m_stats.scraped_full++; d.reserve(90 * m_torrents.size()); for (auto& i : m_torrents) { if (i.second.leechers || i.second.seeders) d += (boost::format("20:%sd8:completei%de10:downloadedi%de10:incompletei%dee") % boost::make_iterator_range(i.first) % i.second.seeders % i.second.completed % i.second.leechers).str(); } } else { m_stats.scraped_http++; if (ti.m_info_hashes.size() > 1) m_stats.scraped_multi++; for (auto& j : ti.m_info_hashes) { if (const t_torrent* i = find_torrent(j)) d += (boost::format("20:%sd8:completei%de10:downloadedi%de10:incompletei%dee") % j % i->seeders % i->completed % i->leechers).str(); } } d += "e"; if (m_config.m_scrape_interval) d += (boost::format("5:flagsd20:min_request_intervali%dee") % m_config.m_scrape_interval).str(); d += "e"; return d; }
void PropertyExpressionEngine::buildGraph(const ExpressionMap & exprs, boost::unordered_map<int, ObjectIdentifier> & revNodes, DiGraph & g) const { boost::unordered_map<ObjectIdentifier, int> nodes; std::vector<Edge> edges; // Build data structure for graph for (ExpressionMap::const_iterator it = exprs.begin(); it != exprs.end(); ++it) buildGraphStructures(it->first, it->second.expression, nodes, revNodes, edges); // Create graph g = DiGraph(revNodes.size()); // Add edges to graph for (std::vector<Edge>::const_iterator i = edges.begin(); i != edges.end(); ++i) add_edge(i->first, i->second, g); // Check for cycles bool has_cycle = false; int src = -1; cycle_detector vis(has_cycle, src); depth_first_search(g, visitor(vis)); if (has_cycle) { std::string s = revNodes[src].toString() + " reference creates a cyclic dependency."; throw Base::Exception(s.c_str()); } }
static double recall(const boost::unordered_map<int, double> &real, const boost::unordered_map<int, double> &fake, double thres = 0.0) { return 1.0 * hit(real, fake, thres).first / real.size(); }
std::string RippleAddress::humanAccountID () const { switch (nVersion) { case VER_NONE: throw std::runtime_error ("unset source - humanAccountID"); case VER_ACCOUNT_ID: { boost::mutex::scoped_lock sl (rncLock); boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData); if (it != rncMap.end ()) return it->second; if (rncMap.size () > 10000) rncMap.clear (); return rncMap[vchData] = ToString (); } case VER_ACCOUNT_PUBLIC: { RippleAddress accountID; (void) accountID.setAccountID (getAccountID ()); return accountID.ToString (); } default: throw std::runtime_error (str (boost::format ("bad source: %d") % int (nVersion))); } }
static double precision(const boost::unordered_map<int, double> &real, const boost::unordered_map<int, double> &fake, double thres = 0.0) { if (real.size() == 0) return 0.0; std::pair<int, int> count = hit(real, fake, thres); return 0 == count.second ? 0.0 : 1.0 * count.first / count.second; }
inline void operator<< (object::with_zone& o, const boost::unordered_map<K,V>& v) { o.type = type::MAP; if(v.empty()) { o.via.map.ptr = NULL; o.via.map.size = 0; } else { object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size()); object_kv* const pend = p + v.size(); o.via.map.ptr = p; o.via.map.size = v.size(); typename boost::unordered_map<K,V>::const_iterator it(v.begin()); do { p->key = object(it->first, o.zone); p->val = object(it->second, o.zone); ++p; ++it; } while(p < pend); } }
static void serialize(storage_type& s, const boost::unordered_map<T1, T2>& o) { uint32_t sz = o.size(); s.serialize(sz); for (typename boost::unordered_map<T1,T2>::const_iterator it = o.begin(), it_end = o.end(); it != it_end; ++it) { s.serialize(it->first); s.serialize(it->second); } }
void PropertyExpressionEngine::buildGraphStructures(const ObjectIdentifier & path, const boost::shared_ptr<Expression> expression, boost::unordered_map<ObjectIdentifier, int> & nodes, boost::unordered_map<int, ObjectIdentifier> & revNodes, std::vector<Edge> & edges) const { std::set<ObjectIdentifier> deps; /* Insert target property into nodes structure */ if (nodes.find(path) == nodes.end()) { int s = nodes.size(); revNodes[s] = path; nodes[path] = s; } else revNodes[nodes[path]] = path; /* Get the dependencies for this expression */ expression->getDeps(deps); /* Insert dependencies into nodes structure */ std::set<ObjectIdentifier>::const_iterator di = deps.begin(); while (di != deps.end()) { Property * prop = di->getProperty(); if (prop) { ObjectIdentifier cPath(di->canonicalPath()); if (nodes.find(cPath) == nodes.end()) { int s = nodes.size(); nodes[cPath] = s; } edges.push_back(std::make_pair(nodes[path], nodes[cPath])); } ++di; } }
void hopscotch_map_sanity_checks() { ASSERT_TRUE(cm2.begin() == cm2.end()); for (size_t i = 0;i < NINS; ++i) { cm2[17 * i] = i; um2[17 * i] = i; } for (size_t i = 0;i < NINS; ++i) { assert(cm2[17 * i] == i); assert(um2[17 * i] == i); } assert(cm2.size() == NINS); assert(um2.size() == NINS); for (size_t i = 0;i < NINS; i+=2) { cm2.erase(17*i); um2.erase(17*i); } for (size_t i = 0;i < NINS; i+=2) { assert(cm2.count(17*i) == i % 2); assert(um2.count(17*i) == i % 2); if (cm2.count(17*i)) { assert(cm2.find(17*i)->second == i); } } assert(cm2.size() == NINS / 2); assert(um2.size() == NINS / 2); typedef graphlab::hopscotch_map<uint32_t, uint32_t>::value_type vpair; { size_t cnt = 0; foreach(vpair &v, cm2) { ASSERT_EQ(v.second, um2[v.first]); ++cnt; } ASSERT_EQ(cnt, NINS / 2); }
void save(Archive & ar, const boost::unordered_map<T,U> & t, unsigned int version) { // write the size // TODO: should we handle bucket size as well? typedef typename boost::unordered_map<T, U>::size_type size_type; typedef typename boost::unordered_map<T,U>::const_iterator const_iterator; size_type size = t.size(); ar & BOOST_SERIALIZATION_NVP(size); unsigned int count = 0; for (const_iterator it = t.begin(); it != t.end(); it++) { ar & boost::serialization::make_nvp("pair" + count, *it); count++; } }
/// Only used by Cpp Vertex Shader void stream_assembler::update_register_map( boost::unordered_map<semantic_value, size_t> const& reg_map ) { register_to_input_element_desc.clear(); register_to_input_element_desc.reserve( reg_map.size() ); typedef pair<semantic_value, size_t> pair_t; for(auto const& sv_reg_pair: reg_map) { input_element_desc const* elem_desc = layout_->find_desc(sv_reg_pair.first); if(elem_desc == nullptr) { register_to_input_element_desc.clear(); return; } register_to_input_element_desc.push_back( make_pair(sv_reg_pair.second, elem_desc) ); } }
std::string RippleAddress::humanAccountID () const { switch (nVersion) { case VER_NONE: throw std::runtime_error ("unset source - humanAccountID"); case VER_ACCOUNT_ID: { StaticScopedLockType sl (s_lock, __FILE__, __LINE__); boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData); if (it != rncMap.end ()) return it->second; // VFALCO NOTE Why do we throw everything out? We could keep two maps // here, switch back and forth keep one of them full and clear the // other on a swap - but always check both maps for cache hits. // if (rncMap.size () > 250000) rncMap.clear (); return rncMap[vchData] = ToString (); } case VER_ACCOUNT_PUBLIC: { RippleAddress accountID; (void) accountID.setAccountID (getAccountID ()); return accountID.ToString (); } default: throw std::runtime_error (str (boost::format ("bad source: %d") % int (nVersion))); } }
int DeviceCassandraController::updateDevice( const string &devicename, const string &username, boost::unordered_map<string, string> ¶ms) { if (params.size() <= 0) return 0; string errorCode = ""; int result; // Get the current device. boost::shared_ptr<Device> device = getDevice(devicename, username, errorCode); if (!errorCode.empty()) { return boost::lexical_cast<int>(errorCode); } // Check if devicename needs to be changed. if (params.count("new_devicename")) { // Delete the current device from db. result = deleteDevice(devicename, username); if (result != 0) { return result; } } // Update data in the current device. if (params.count("new_devicename")) { device->setDevicename(params["new_devicename"]); } if (params.count("type")) { device->setType(params["type"]); } if (params.count("metadata")) { device->setContentMeta(params["metadata"]); device->setContentTimestamp(time(NULL)); } if (params.count("dir_ip")) { device->setDirIp(params["dir_ip"]); } if (params.count("dir_port")) { unsigned short portValue = -1; if (!ControllerHelper::isNullOREmptyString(params["dir_port"])) portValue = boost::lexical_cast<unsigned short>(params["dir_port"]); device->setDirPort(portValue); } if (params.count("ip")) { device->setIp(params["ip"]); } if (params.count("port")) { unsigned short portValue = -1; if (!ControllerHelper::isNullOREmptyString(params["port"])) portValue = boost::lexical_cast<unsigned short>(params["port"]); device->setPort(portValue); } if (params.count("os")) { device->setOs(params["os"]); } if (params.count("description")) { device->setDescription(params["description"]); } if (params.count("public_folder")) { device->setPublicFolder(params["public_folder"]); } if (params.count("private_folder")) { device->setPrivateFolder(params["private_folder"]); } if (params.count("is_indexed")) { bool is_indexed = false; if (boost::iequals(params["is_indexed"], "true")) is_indexed = true; device->setSearchable(is_indexed); } // Update lastseen. device->setLastSeen(time(NULL)); // Add the new device. result = addDevice(device); return result; }
void Task::featuresOut(const int current_image_idx, const boost::unordered_map<boost::uuids::uuid, StereoFeature> &hash) { ExteroFeatures features_samples; base::samples::Pointcloud features_points; double const &baseline(cameracalib.extrinsic.tx); cv::Mat cv_image1; /** Uncertainty in the images (left and right) planes **/ Eigen::Matrix4d px_var; px_var << this->pxleftVar, Eigen::Matrix2d::Zero(), Eigen::Matrix2d::Zero(), this->pxrightVar; #ifdef DEBUG_PRINTS std::cout<<"[FEATURES_OUT] Current hash.size(): "<<hash.size()<<"\n"; #endif /** Parse the hash table of features **/ for (boost::unordered_map<boost::uuids::uuid, StereoFeature>::const_iterator it = hash.begin(); it != hash.end(); ++it) { //std::cout<<"[FEATURES_OUT] img_idx: "<<it->second.img_idx<<" current_idx: "<<current_image_idx<<"\n"; if (it->second.img_idx == current_image_idx) { Feature feature; /** Get the uuid **/ feature.index = it->first; /** Take the "Stereo" 2d point **/ cv::Point const &left_pt(it->second.keypoint_left.pt); cv::Point const &right_pt(it->second.keypoint_right.pt); feature.stereo_point = base::Vector3d(left_pt.x, right_pt.x, left_pt.y); /** Compute the 3d point **/ double disparity = std::min(right_pt.x - left_pt.x, -1); base::Vector4d image_point (left_pt.x, left_pt.y, disparity, 1); base::Vector4d homogeneous_point = Q * image_point; feature.point_3d = base::Vector3d (homogeneous_point(0)/homogeneous_point(3), homogeneous_point(1)/homogeneous_point(3), homogeneous_point(2)/homogeneous_point(3)); #ifdef DEBUG_PRINTS std::cout<<"[FEATURES_OUT] Image point[left]: "<<left_pt.x<<" "<<left_pt.y<<"\n"; std::cout<<"[FEATURES_OUT] Image point[right]: "<<right_pt.x<<" "<<right_pt.y<<"\n"; std::cout<<"[FEATURES_OUT] 3D point:\n"<<feature.point_3d<<"\n"; #endif if (_output_debug.value()) { /** 3D point coordinates in base point cloud structure **/ features_points.points.push_back(base::Vector3d ( homogeneous_point(0)/homogeneous_point(3), homogeneous_point(1)/homogeneous_point(3), homogeneous_point(2)/homogeneous_point(3))); /** Color **/ cv_image1 = frame_helper::FrameHelper::convertToCvMat(this->left_color_frame); cv::Vec3b color = cv_image1.at<cv::Vec3b>(left_pt.y, left_pt.x); base::Vector4d color4d; color4d[0] = color[0]/255.0;//R color4d[1] = color[1]/255.0;//G color4d[2] = color[2]/255.0;//B color4d[3] = 1.0;//Alpha features_points.colors.push_back(color4d); } /** Compute the covariance **/ Eigen::Matrix<double, 3, 4> noise_jacobian; /** Jacobian Matrix for the triangulation noise model */ double disparity_power = pow(disparity,2); noise_jacobian << -(baseline*right_pt.x)/disparity_power, 0.00, (baseline*left_pt.x)/disparity_power, 0.00, -(baseline*left_pt.y)/disparity_power, baseline/disparity, (baseline*left_pt.y)/disparity_power, 0.00, -(baseline*cameracalib.camLeft.fx)/disparity_power, 0.00, (baseline*cameracalib.camLeft.fx)/disparity_power, 0.00; feature.cov_3d = noise_jacobian * px_var * noise_jacobian.transpose(); /** Store the feature in the vector **/ features_samples.features.push_back(feature); } } #ifdef DEBUG_PRINTS std::cout<<"[FEATURES_OUT] Sent "<<features_samples.features.size()<<" vector of uuids\n"; #endif features_samples.time = this->frame_pair.time; features_samples.img_idx = current_image_idx; _features_samples_out.write(features_samples); if (_output_debug.value()) { features_points.time = this->frame_pair.time; _features_point_samples_out.write(features_points); } return; }
int main(int ac, char* av[]) { //read and parse command line inputs (using boose::program_options) po::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") //scenario parameters ("lambda,l", po::value<double>(&lambda_mean)->default_value(10), "mean demand (E[lambda])") ("beta,b", po::value<double>(&beta0)->default_value(1), "beta") ("cost,c", po::value<double>(&cost)->default_value(1), "unit cost") //file names input ("path,p", po::value<string>(&path), "path for temporary archive files") ("outfile,o", po::value<string>(&resultFile), "file to save result") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("help")) { cout << "Usage: options_description [options]\n"; cout << desc; return 0; } //initialize the file names by taking all parameters modelName = "NVLearning_Full"; if (resultFile == "") resultFile = modelName + ".result.txt"; //Open output file file.open(resultFile, fstream::app|fstream::out); if (! file) { //if fail to open the file cerr << "can't open output file NVLearning_Full_result.txt!" << endl; exit(EXIT_FAILURE); } file << setprecision(10); cout << setprecision(10); //omp_set_num_threads(omp_get_num_procs()); //cout << "Num of Procs: " << omp_get_num_procs() << endl; //cout << "Max Num of Threads: " << omp_get_max_threads() << endl; cout << "Num of periods (N): " << N << endl; cout << "r\tc\talpha\tbeta\tQ_F\tPi_F\tTime_F\tCPUTime_F\tComp_F" << endl; //file << "Num of Procs: " << omp_get_num_procs() << endl; //file << "Max Num of Threads: " << omp_get_max_threads() << endl; //file << "Num of periods (N): " << N << endl; file << "r\tc\talpha\tbeta\tQ_F\tPi_F\tTime_F\tCPUTime_F\tComp_F" << endl; //initialize cost parameters price = 2; //lambda_mean = 10; //cost = 1; //beta0 = 1; for (lambda_mean=10; lambda_mean<=50; lambda_mean+=10) for (beta0=2; beta0>=0.05; beta0/=2) { alpha0 = beta0*lambda_mean; for (cost=1.8; cost>=0.15; cost-=0.1) { v_map.clear(); cout << price << "\t" << cost << "\t" << alpha0 << "\t" << beta0 << "\t"; file << price << "\t" << cost << "\t" << alpha0 << "\t" << beta0 << "\t"; auto startTime = chrono::system_clock::now(); clock_t cpu_start = clock(); V_F(1, 0, 0); clock_t cpu_end = clock(); auto endTime = chrono::system_clock::now(); cout << chrono::duration_cast<chrono::milliseconds> (endTime-startTime).count() << "\t" << 1000.0*(cpu_end-cpu_start)/CLOCKS_PER_SEC << "\t"; file << chrono::duration_cast<chrono::milliseconds> (endTime-startTime).count() << "\t" << 1000.0*(cpu_end-cpu_start)/CLOCKS_PER_SEC << "\t"; scenarioName = ".l" + dbl_to_str(lambda_mean) +".b" + dbl_to_str(beta0) + ".c" + dbl_to_str(cost); archiveFile = path + modelName + scenarioName + ".oarchive.txt"; archiveVMap(v_map, archiveFile); auto mapSize = v_map.size(); cout << mapSize+1 << endl; file << mapSize+1 << endl; } } file.close(); return 0; }