void Player::GenerateResearchSites() { _researchSites.clear(); typedef std::map<uint32, SiteSet> Sites; Sites tempSites; for (ResearchSiteDataMap::const_iterator itr = sResearchSiteDataMap.begin(); itr != sResearchSiteDataMap.end(); ++itr) { ResearchSiteEntry const* entry = itr->second.entry; if (CanResearchWithLevel(entry->ID) && CanResearchWithSkillLevel(entry->ID)) tempSites[entry->mapId].insert(entry->ID); } for (Sites::const_iterator itr = tempSites.begin(); itr != tempSites.end(); ++itr) { uint8 mapMax = std::min<int>(itr->second.size(), 4); for (uint8 i = 0; i < mapMax;) { SiteSet::const_iterator itr2 = itr->second.begin(); std::advance(itr2, urand(0, itr->second.size() - 1)); if (!HasResearchSite(*itr2)) { _researchSites.insert(*itr2); ++i; } } } _archaeologyChanged = true; ShowResearchSites(); }
void LS_movement_mh(SQM_solution &X) { int best_location; double best_rt; /* Obtain the server with more workload */ int k = LS_get_server_with_more_workload(X); /* Obtain the adyacent servers */ Servers *servers = LS_get_adjacent_servers(X,k); /* Obtain the adyacent server with less workload */ int j = LS_get_server_with_less_workload(X,servers); int loc_j = X.get_server_location(j); delete servers; /* Put a server near the server with more workload */ Sites *sites = LS_get_adjacent_sites(X,k); for (Sites::iterator it = sites->begin(),end = sites->end(); it != end;it++) { X.test_server_location(j,*it); if (best_location == UNASIGNED_LOCATION || X.get_response_time() < best_rt) { best_location = *it; best_rt = X.get_response_time(); } } X.test_server_location(j,loc_j); /* The past location of the server */ X.set_server_location(j,best_location); delete sites; }
int LS_movement_lm(SQM_solution &X) { int best_loc = UNASIGNED_LOCATION; double best_rt; int p = X.get_servers(); /* Obtain the server with less workload */ int j = LS_get_server_with_less_workload(X); int loc_j = X.get_server_location(j); double v = X.get_server_speed(j); double beta = X.get_server_beta(j); /* obtain the news workloads */ int k = LS_get_server_with_more_workload(X); /* Put a server near the server with more workload */ Sites *lst = LS_get_adjacent_sites(X,k); for (Sites::iterator it = lst->begin(),end = lst->end(); it != end;it++) { X.test_server_location(j,*it); if (best_loc == UNASIGNED_LOCATION || X.get_response_time() < best_rt) { best_loc = *it; best_rt = X.get_response_time(); } } if (best_loc == UNASIGNED_LOCATION) { cerr << "Warining: No new location" << endl; best_loc = loc_j; } X.test_server_location(j,loc_j); /* The past location of the server */ X.set_server_location(j,best_loc); delete lst; return j; }
void httplus::App::load(kul::hash::map::S2T<std::shared_ptr<http::Server>>& http, kul::hash::map::S2T<std::shared_ptr<https::Server>>& https, Sites& sites) throw(httplus::Exception){ std::shared_ptr<http::Conf> defHttp; if(config.root()["http"]) for(const YAML::Node& c : config.root()["http"]){ if(defHttp && !c["host"]) KEXCEPTION("Only one http allowed without 'host' parameter"); const std::string& port(c["port"] ? c["port"].Scalar() : "80"); kul::Dir d(c["root"].Scalar()); if(!d) KEXCEPTION("Directory does not exist: " + c["root"].Scalar()); kul::Dir p("pub", d); if(!p && !p.mk()) KEXCEPTION("Invalid access on directory: " + d.real()); http::Server* ser = {0}; std::string home(c["home"] ? c["home"].Scalar() : ""); const std::string txt(c["text"] ? c["text"].Scalar() : ""); if(!c["host"]){ defHttp = std::make_shared<http::Conf>(c["root"].Scalar(), home, txt); }else if(sites.count(std::to_string(std::hash<std::string>()(d.real())))){ const Pages& pages((*sites.find(std::to_string(std::hash<std::string>()(d.real())))).second); http.insert(port, std::make_shared<http::Server>(kul::String::UINT16(port), pages)); ser = http[port].get(); ser->confs.insert(c["host"].Scalar(), std::make_shared<http::Conf>(c["root"].Scalar(), home, txt)); }else KERR << "WARN: NO GENERATORS FOR HTTP ROOT: " << d; } for(const auto& p : http) p.second->def = defHttp; if(config.root()["https"]) for(const YAML::Node& c : config.root()["https"]){ kul::Dir d(c["root"].Scalar()); if(!d) KEXCEPTION("Directory does not exist: " + c["root"].Scalar()); kul::Dir p("pub", d); if(!p && !p.mk()) KEXCEPTION("Invalid access on directory: " + d.real()); kul::File crt(c["crt"].Scalar()); kul::File key(c["key"].Scalar()); if(!crt) KEXCEPTION("File does not exist: " + crt.full()); if(!key) KEXCEPTION("File does not exist: " + key.full()); https::Server* ser = {0}; const std::string& port(c["port"] ? c["port"].Scalar() : "443"); const std::string hsh(std::to_string(std::hash<std::string>()(d.real()))); if(!sites.count(hsh)) { KERR << "WARN: NO GENERATORS FOR HTTPS ROOT: " << d; continue; } const Pages& pages((*sites.find(hsh)).second); std::string ssls(c["ssls"] ? c["ssls"].Scalar() : config.root()["ssls"] ? config.root()["ssls"].Scalar() : ""); https.insert(port, std::make_shared<https::Server>(kul::String::UINT16(port), pages, crt, key, ssls)); ser = https[port].get(); ser->init(); if(c["chain"]) ser->setChain(c["chain"].Scalar()); std::string home(c["home"] ? c["home"].Scalar() : ""); const std::string txt(c["text"] ? c["text"].Scalar() : ""); ser->confs.insert(c["host"].Scalar(), std::make_shared<http::Conf>(c["root"].Scalar(), home, txt)); } }
void Convex_hull::Graham_yao::build_lower_hull(Poly_chain_2& chain, const Sites& p) { std::vector< Point >::const_iterator iter = p.begin(); ++iter; init(chain, *(p.begin()), *iter); for ( ; iter != p.end() ; ++iter) { add_ccw(chain, *iter); } }
Sites* LS_get_adjacent_sites(SQM_solution &X,int i) { SQM_instance *I = X.get_instance(); int m = I->demand_points(); int n = I->potential_sites(); int p = X.get_servers(); bool *adjacent; Sites *lst; int loc_i,loc_j; int nearest_loc = UNASIGNED_LOCATION; int **a = X.preferred_servers(); int sites,order; logDebug(cout << "LS_get_adjacent_sites: Start" << endl); lst = new Sites; adjacent = new bool [n]; for (int k = 0;k < n;k++) adjacent[k] = false; loc_i = X.get_server_location(i); sites = 0; order = 0; do { for (int j = 0;j < m;j++) if (a[j][order] == i) { double radious = I->distance(loc_i,j); for (int loc = 0;loc < n;loc++) if (I->distance(loc,j) <= radious) if (!adjacent[loc]) { adjacent[loc] = true; sites++; } } order++; } while (sites == 0 && order < p); for (int loc = 0;loc < n;loc++) if (adjacent[loc]) lst->push_back(loc); delete [] adjacent; logDebug(cout << "LS_get_adjacent_sites: Finish" << endl); return lst; }