// Determine the minimum useful population size int bisection(Random& rand, Configuration& config, evaluation::pointer problem, optimize::pointer solver) { int runs = config.get<int>("runs"); float good_enough = config.get<int>("fitness_limit"); vector<Record> records; // initial bounds int min = 0; int max = 1; size_t failed_on = 0; bool success; // Double the maximum size until a successful run is found do { // double the bounds each time min = max; max *= 2; config.set("pop_size", max); std::cout << "Pop size: " << max << std::endl; success = true; // Perform multiple runs, stopping as soon as one of the runs failed to find // the global optimum for (int i = 0; success and i < runs; i++) { int problem_number = ((i + failed_on) % runs); std::cout << "\tTrying problem: " << problem_number << std::endl; auto results = single_run(rand, config, problem, solver, problem_number); if (results.best().first < good_enough) { failed_on = problem_number; success = false; } } } while (!success); // Bisect between the min (unsuccessful) and max (successful) until they meet int guess; while (min + 1 < max) { guess = (max + min) / 2; std::cout << "Pop size: " << guess << std::endl; config.set("pop_size", guess); success = true; // Perform multiple runs, stopping as soon as one of the runs failed to find // the global optimum for (int i = 0; success and i < runs; i++) { int problem_number = ((i + failed_on) % runs); std::cout << "\tTrying problem: " << problem_number << std::endl; auto results = single_run(rand, config, problem, solver, problem_number); if (results.best().first < good_enough) { failed_on = problem_number; success = false; } } // update the bound if (success) { max = guess; } else { min = guess; } } return max; }
void find_best_decision_check_monotone(size_t n) { score_strategy_cached c; std::vector<int> best(n); double bestScore = c(best); for (size_t i = n; i--;) { std::vector<int> decision = best; bool decreasing = true; double prevScore = 0; for (size_t j = 0; j <= i + 1; ++j) { decision[i] = j; print_decision(decision); auto score = c(decision); if (j == 0) { prevScore = score; } else if (decreasing && score > prevScore) { decreasing = false; } else if (!decreasing && score < prevScore) { std::cout << "Not monotone" << std::endl; decision[i] = j - 1; for (auto x : decision) std::cout << ' ' << x; std::cout << std::endl; decision[i] = j; for (auto x : decision) std::cout << ' ' << x; std::cout << std::endl; } if (score < bestScore) { best = decision; bestScore = score; } } } print_decision(best); std::cout << ' ' << bestScore << std::endl; }
int main(void) { // prepare(); scanf("%lld", &find); printf("%lld\n", best(find)); return 0; }
int main(int argc, char const *argv[]) { void reg(float scores[40]); float best(float scores[40]); float worst(float scores[40]); void report(float scores[40]); float average(float scores[40]); float scores[40]; int position; printf("scores average\n"); reg(scores); printf("The best score is %f \n", best(scores)); printf("The worst score is %f \n", worst(scores)); printf("Score report \n"); report(scores); printf("The average is %f \n", average(scores)); printf("Give me a number of score \n"); scanf("%i", &position); if (position >= 0 && position <= 40) { printf("The score that you look is %f \n", scores[position]); } return 0; }
wxSize wxRadioButton::DoGetBestSize() const { static int s_radioSize = 0; if ( !s_radioSize ) { wxScreenDC dc; dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); s_radioSize = dc.GetCharHeight(); } wxString str = GetLabel(); int wRadio, hRadio; if ( !str.empty() ) { GetTextExtent(GetLabelText(str), &wRadio, &hRadio); wRadio += s_radioSize + GetCharWidth(); if ( hRadio < s_radioSize ) hRadio = s_radioSize; } else { wRadio = s_radioSize; hRadio = s_radioSize; } wxSize best(wRadio, hRadio); CacheBestSize(best); return best; }
int try_all_perm_random_restart(int n, int restart_at, int stop_after) { int curr_best = get_current_score(n, dbname); int n1_score = get_current_score(n-1, dbname); perm deck(n), best(n); init_deck(deck); shuffle_no_fix(deck); int highest_count_so_far = 0; int count = 0; int iterations = 0; // while (next_perm_swap1(deck)) { //while (next_perm_rand_swap2(deck)) { while (next_permutation(deck.begin(), deck.end())) { //while (next_perm_seq_pair(deck)) { //while (next_perm_all_pair(deck)) { //while (next_perm_all_pair_rev(deck)) { ++iterations; if (iterations >= stop_after) return highest_count_so_far; ++count; if (deck[0] == 1) { shuffle_no_fix(deck); count = 0; ping('1'); } if (count >= restart_at) { count = 0; shuffle_no_fix(deck); ping('.'); } const int score = do_all_top_swops_copy(deck); /* // Heuristic cut-off: if the last number is home, then re-start if // the previous perm's best score plus the current score is less // than the highest score so far. if (deck.back() == n && n1_score + score < highest_count_so_far) { count = 0; shuffle_no_fix(deck); ping('c'); } */ if (score > highest_count_so_far) { highest_count_so_far = score; best = deck; if (highest_count_so_far > curr_best) { ping('!'); //int diff = highest_count_so_far - curr_best; curr_best = highest_count_so_far; set_current_perm(n, best, dbname); } } } // cout << best << " (n=" << n << ", optimal_count=" << highest_count_so_far // << ")" << endl; return highest_count_so_far; }
wxSize wxListBox::DoGetBestSize() const { int lbWidth = 100; // some defaults int lbHeight = 110; int wLine; // Find the widest line for(unsigned int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); GetTextExtent(str, &wLine, NULL); lbWidth = wxMax(lbWidth, wLine); } // Add room for the scrollbar lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); // And just a bit more int cx, cy; GetTextExtent( wxT("X"), &cx, &cy); lbWidth += 3 * cx; // don't make the listbox too tall (limit height to around 10 items) but don't // make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); wxSize best(lbWidth, lbHeight); CacheBestSize(best); return best; }
pair<Emotion, float> EmoDetector::predictBestWinsOneVsAll(cv::Mat& frame) { pair<Emotion, float> best(UNKNOWN, numeric_limits<float>::min()); if (detectors_ext.size() == 0) { return make_pair(UNKNOWN, 0.0f); } for (map<string, pair<vector<Emotion>, Classifier*> >::iterator ii = this->detectors_ext.begin(); ii != this->detectors_ext.end(); ++ii) { if (ii->second.first.size() != 1) { continue; } Emotion emo = ii->second.first[0]; Classifier* cl = ii->second.second; float prediction = cl->predict(frame); if (best.second < prediction) { best.first = emo; best.second = prediction; } } return best; }
// Recursively drills down from a given size until either it finds the correct // population size, or you discover that max isn't big enough int recurse(Random& rand, Configuration& config, evaluation::pointer problem, optimize::pointer solver, int min, int max) { int runs = config.get<int>("runs"); float good_enough = config.get<float>("fitness_limit"); vector<Record> records; int result; for (int i = 0; i < runs; i++) { config.set("pop_size", max); std::cout << "Pop size: " << max << " Trying problem: " << i << std::endl; auto results = single_run(rand, config, problem, solver, i); if (results.best().first < good_enough) { // fail this size, you have to get bigger std::cout << "\tfailed" << std::endl; return -1; } else { int guess = (max + min) / 2; if (min != guess) { result = recurse(rand, config, problem, solver, min, guess); // If you found the correct population size if (result != -1) { return result; } else { // You failed, increase the minimum min = guess; } } } } return max; }
wxSize wxChoice::DoGetBestSize() const { // find the widest string int wChoice = 0; const unsigned int nItems = GetCount(); for ( unsigned int i = 0; i < nItems; i++ ) { int wLine; GetTextExtent(GetString(i), &wLine, NULL); if ( wLine > wChoice ) wChoice = wLine; } // give it some reasonable default value if there are no strings in the // list if ( wChoice == 0 ) wChoice = 100; // the combobox should be slightly larger than the widest string wChoice += 5*GetCharWidth(); wxSize best(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight())); CacheBestSize(best); return best; }
std::vector<PerceptualHash::ComparisonResult> PerceptualHash::nbest(int n, const ulong64& hash, const std::vector<ulong64>& dataSet) { if (n == 1) { std::vector<PerceptualHash::ComparisonResult> result; result.push_back(best(hash, dataSet)); return result; } std::vector<int> nbestDistances(n, sizeof(ulong64) * 8); std::vector<size_t> nbestObjectIndexes(n, -1); for (size_t i = 0; i < dataSet.size(); i++) { const int dist = hammingDistance(hash, dataSet[i]); for (size_t j = 0; j < nbestDistances.size(); j++) { if (dist < nbestDistances[j]) { for (size_t k = n - 1; k > j; k--) { nbestDistances[k] = nbestDistances[k - 1]; nbestObjectIndexes[k] = nbestObjectIndexes[k - 1]; } nbestDistances[j] = dist; nbestObjectIndexes[j] = i; break; } } } std::vector<ComparisonResult> nbestObjects(n); for (size_t i = 0; i < n; i++) { ComparisonResult c; c.distance = nbestDistances[i]; c.index = nbestObjectIndexes[i]; nbestObjects[i] = c; } return nbestObjects; }
wxSize CFontNamesComboBox::DoGetBestSize() const { int hBitmap = 0; int wChoice = 0; int hChoice; const unsigned int nItems = GetCount(); for( unsigned int i = 0; i < nItems; i++ ) { int wLine; GetTextExtent( GetString( i ), &wLine, NULL ); if( wLine > wChoice ) wChoice = wLine; } if( wChoice == 0 ) wChoice = 100; wChoice += 5 * GetCharWidth(); if( m_bmp1 ) { wChoice += m_bmp1->GetWidth(); hBitmap = m_bmp1->GetHeight(); } int cx, cy; wxGetCharSize( GetHWND(), &cx, &cy, GetFont() ); if( hBitmap > cy ) cy = hBitmap; int hItem = SendMessage( GetHwnd(), CB_GETITEMHEIGHT, (WPARAM) -1, 0 ); if( hItem > cy ) hItem = cy; SendMessage( GetHwnd(), CB_SETITEMHEIGHT, (WPARAM) -1, hItem ); hChoice = ( EDIT_HEIGHT_FROM_CHAR_HEIGHT( cy ) * 6 ) + hItem - 6; wxSize best( wChoice, hChoice ); CacheBestSize( best ); return best; }
wxSize wxSpinCtrl::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); wxSize best(95, ret.y); CacheBestSize(best); return best; }
wxSize wxSpinCtrlGTKBase::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); wxSize best(95, ret.y); // FIXME: 95? CacheBestSize(best); return best; }
//-------------------------------------------------------------- void ofApp::update(){ switch (stat) { case s01: if (space){ stat = s02; timeStamp = ofGetElapsedTimef(); } break; case s02: if (!space) { stat = s03; timeStamp = ofGetElapsedTimef(); fiveSeconds.push_back(time); //記録 bestScore = best(fiveSeconds, fiveSeconds.size()); } break; case s03: if (time >= 5.0){ stat = s01; timeStamp = ofGetElapsedTimef(); if (fiveSeconds.size() >= 6) { fiveSeconds.erase(fiveSeconds.begin()); } } break; default: break; } }
ClosestPolygonPoint findClosest(Point from, Polygons& polygons) { Polygon emptyPoly; ClosestPolygonPoint none(from, -1, emptyPoly); if (polygons.size() == 0) return none; PolygonRef aPolygon = polygons[0]; if (aPolygon.size() == 0) return none; Point aPoint = aPolygon[0]; ClosestPolygonPoint best(aPoint, 0, aPolygon); int64_t closestDist = vSize2(from - best.location); for (unsigned int ply = 0; ply < polygons.size(); ply++) { PolygonRef poly = polygons[ply]; if (poly.size() == 0) continue; ClosestPolygonPoint closestHere = findClosest(from, poly); int64_t dist = vSize2(from - closestHere.location); if (dist < closestDist) { best = closestHere; closestDist = dist; } } return best; }
wxSize wxDateTimePickerCtrl::DoGetBestSize() const { wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this)); // Use the same native format as the underlying native control. #if wxUSE_INTL wxString s = wxDateTime::Now().Format(wxLocale::GetInfo(MSWGetFormat())); #else // !wxUSE_INTL wxString s("XXX-YYY-ZZZZ"); #endif // wxUSE_INTL/!wxUSE_INTL // the best size for the control is bigger than just the string // representation of the current value because the control must accommodate // any date and while the widths of all digits are usually about the same, // the width of the month string varies a lot, so try to account for it s += wxT("WW"); int x, y; dc.GetTextExtent(s, &x, &y); // account for the drop-down arrow or spin arrows x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X); // and for the checkbox if we have it if ( MSWAllowsNone() ) x += 3*GetCharWidth(); wxSize best(x, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); CacheBestSize(best); return best; }
wxSize wxTextCtrl::DoGetBestSize() const { // FIXME should be different for multi-line controls... wxSize ret( wxControl::DoGetBestSize() ); wxSize best(80, ret.y); CacheBestSize(best); return best; }
void Simplex::getBest() { if (this->isPrimal){ for(int i(0); i < best.rows(); ++i) best(i) = 0; for(int i(0); i < side.rows(); ++i){ if(side(i) <= problem->nbVars){ best(side(i) - 1) = tab(i+1, 0); } } } else { for(int i(0); i < best.rows(); ++i){ best(i) = tab(0,this->problem->nbVars+i); } } }
/***************************************************** ** ** ToolbarLabel --- DoGetBestSize ** ******************************************************/ wxSize ToolbarLabel::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); wxSize best(95, ret.y); //printf( "DoGetBestSize :::\n" ); return best; }
wxSize wxDatePickerCtrl::DoGetBestSize() const { const int y = GetCharHeight(); wxSize best(DEFAULT_ITEM_WIDTH, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); CacheBestSize(best); return best; }
void test6() { const int n = 53; perm best(*get_current_perm(n)); perm root(best); do_all_top_swops(root); cout << "root (n=" << n << "): " << root << endl; dfs(root, -1); }
int best(int x=0,int y=0) { int o = getXY(x,y); if (o>=sizeof(t)/sizeof(*t)) return 0; if (bests[o] != -1) return bests[o]; int a1 = best(x+1,y); int a2 = best(x+1,y+1); int r = (a1<a2 ? a2 : a1)+t[o]; bests[o] = r; return r; }
inline bool delayed_available(void) const { if(delay_queue.empty()) return false; utils::unix_timestamp now(utils::get_timestamp()); utils::unix_timestamp best(delay_queue.top_priority()); return best < now; }
/** * @brief Find the smallest eigen value on the given stack * * This static method iterates through a stack to find the best (smallest) * eigen value as computed by the Gruen registration algorithm. If the stack * is empty or if for some unapparent reason why the best point cannot be * found, stack.end() is returned. * * @param stack Stack to find the best point in. * * @return SmtkQStackIter Returns an iterator with the best value */ SmtkQStackIter SmtkMatcher::FindSmallestEV(SmtkQStack &stack) { SmtkQStackIter best(stack.begin()), current(stack.begin()); while ( current != stack.end() ) { if (current.value().GoodnessOfFit() < best.value().GoodnessOfFit() ) { best = current; } ++current; } return (best); }
void test2() { const int n = 97; perm best(*get_current_perm(n)); perm root(best); for(int i = 0; i < 10000; ++i) { next_permutation(root.begin(), root.end()); dfs(root, -1); ping('.'); } }
wxSize wxBitmapButton::DoGetBestSize() const { if ( m_bmpNormal.Ok() ) { int width = m_bmpNormal.GetWidth(), height = m_bmpNormal.GetHeight(); int marginH = 0, marginV = 0; #if wxUSE_UXTHEME if ( wxUxThemeEngine::GetIfActive() ) { wxUxThemeHandle theme((wxBitmapButton *)this, L"BUTTON"); MARGINS margins; wxUxThemeEngine::Get()->GetThemeMargins(theme, NULL, BP_PUSHBUTTON, PBS_NORMAL, TMT_CONTENTMARGINS, NULL, &margins); // XP doesn't draw themed buttons correctly when the client area is // smaller than 8x8 - enforce this minimum size for small bitmaps if ( width < 8 ) width = 8; if ( height < 8 ) height = 8; // don't add margins for the borderless buttons, they don't need // them and it just makes them appear larger than needed if ( !HasFlag(wxBORDER_NONE) ) { // we need 2 extra pixels for the focus rectangle, without them // it's overwritten by the bitmap itself marginH = margins.cxLeftWidth + margins.cxRightWidth + 2; marginV = margins.cyTopHeight + margins.cyBottomHeight + 2; } } else #endif // wxUSE_UXTHEME { if ( !HasFlag(wxBORDER_NONE) ) { marginH = 2*m_marginX; marginV = 2*m_marginY; } } wxSize best(width + marginH, height + marginV); CacheBestSize(best); return best; } // no idea what our best size should be, defer to the base class return wxBitmapButtonBase::DoGetBestSize(); }
int SRGAntColony(SRGGraph& g, std::vector<bool>& relays, std::size_t genSize, std::size_t iterations) { PheromoneMatrix p(relays.size()); p.setEvaporationRate(0.3); p.setQ(relays.size()*0.3); std::vector<bool> best(relays.size(),true), oldBest(relays.size(),true); int opt = relays.size(); //put a proper hating criterion in bool halt = false; std::vector<RanGen*> generators(NUM_THREADS); for(int i=0; i<NUM_THREADS; ++i) generators[i] = new RanGen(rand()); for(int i=0; !halt || i<iterations; ++i) { std:copy(best.begin(), best.end(), oldBest.begin()); std::vector<std::vector<std::size_t> > tours(genSize, std::vector<std::size_t>(0)); std::vector<size_t> result(genSize); for(int j=0; j<genSize/NUM_THREADS; ++j) { //some parallel code? pthread_t threads[NUM_THREADS]; ACOInfo * infos[NUM_THREADS]; std::vector<std::vector<bool> > relayArray(NUM_THREADS, std::vector<bool>(relays.size(),true)); for(int k=0; k<NUM_THREADS; ++k) { tours[j*NUM_THREADS+k].reserve(relays.size()); infos[k] = new ACOInfo(g,&relayArray[k],&tours[j*NUM_THREADS+k],&p, generators[k], &result[j*NUM_THREADS+k]); int rc = pthread_create(&threads[k], NULL, DropThread, (void *) infos[k]); } for(int k=0; k<NUM_THREADS; ++k) pthread_join(threads[k],NULL); for(int k=0; k<NUM_THREADS; ++k) { if(result[j*NUM_THREADS+k] < opt) { std::copy(relayArray[k].begin(), relayArray[k].end(), best.begin()); opt = result[j*NUM_THREADS+k]; } delete infos[k]; } } for(int j=0; j<genSize; ++j) { p.update(tours[j],(float) result[j]); } halt = true; for(int j=0; j<best.size(); ++j) if(best[j]!=oldBest[j]) halt = false; } std::copy(best.begin(), best.end(), relays.begin()); return opt; }
wxSize wxDatePickerCtrl::DoGetBestSize() const { wxClientDC dc(const_cast<wxDatePickerCtrl *>(this)); // we can't use FormatDate() here as the CRT doesn't always use the same // format as the date picker control wxString s; for ( int len = 100; ; len *= 2 ) { if ( ::GetDateFormat ( LOCALE_USER_DEFAULT, // the control should use the same DATE_SHORTDATE, // the format used by the control NULL, // use current date (we don't care) NULL, // no custom format wxStringBuffer(s, len), // output buffer len // and its length ) ) { // success break; } const DWORD rc = ::GetLastError(); if ( rc != ERROR_INSUFFICIENT_BUFFER ) { wxLogApiError(wxT("GetDateFormat"), rc); // fall back on wxDateTime, what else to do? s = wxDateTime::Today().FormatDate(); break; } } // the best size for the control is bigger than just the string // representation of todays date because the control must accommodate any // date and while the widths of all digits are usually about the same, the // width of the month string varies a lot, so try to account for it s += wxT("WW"); int x, y; dc.GetTextExtent(s, &x, &y); // account for the drop-down arrow or spin arrows x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X); // and for the checkbox if we have it if ( HasFlag(wxDP_ALLOWNONE) ) x += 3*GetCharWidth(); wxSize best(x, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y)); CacheBestSize(best); return best; }
static void term_mvaddch(int x, int y, int ch, fcolor *fg, fcolor *bg) { if (x < 0 || y < 0 || x >= minsize.width || y >= minsize.height) return; if (colormode == coerce_16) { int c = best(fg, bg); attrset(COLOR_ATTR(c)); mvaddch(y, x, ch); } else { buffer_plot(ch, x, y, fg, bg); } }