/* returns 1 if a solution is found; 0 otherwise. */ int feed( int depth, int max_depth, int start,/* the feed to start with. */ char* choices, int num_feeds, short feeds[][MAX_NUM_VITAMINS], int num_vitamins, short *requirements ) { if (depth == max_depth) { return is_enough(choices, depth, feeds, requirements, num_vitamins); } int r; int i; for (i = start; i < num_feeds; i++) { choices[depth] = i; r = feed( depth + 1, max_depth, i + 1, choices, num_feeds, feeds, num_vitamins, requirements ); if (r) { return r; } } return 0; }
/* * Update ni->in_txrate. */ void ieee80211_amrr_choose(struct ieee80211_amrr *amrr, struct ieee80211_node *ni, struct ieee80211_amrr_node *amn) { int need_change = 0; uint8_t rate; if (is_success(amn) && is_enough(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && !is_max_rate(ni)) { amn->amn_recovery = 1; amn->amn_success = 0; increase_rate(ni); rate = ni->in_rates.ir_rates[ni->in_txrate] & IEEE80211_RATE_VAL; ieee80211_dbg(IEEE80211_MSG_XRATE, "AMRR increasing rate %d (txcnt=%d retrycnt=%d)", rate, amn->amn_txcnt, amn->amn_retrycnt); DTRACE_PROBE4(amrr__increase__rate, struct ieee80211_node *, ni, uint8_t, rate, uint_t, amn->amn_txcnt, uint_t, amn->amn_retrycnt); need_change = 1; } else {
void Display::buy_drink(int number) { if(is_enough(number)) { automat->give_drink(number); } else { std::cout<<"#Not enough money. Please, insert additional "<<automat->get_price(number)-automat->get_client_money()<<"$ #\n"; } show_balance(); }
static int amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn, struct ieee80211_node *ni) { int rix = amn->amn_rix; KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt)); if (is_success(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && rix + 1 < ni->ni_rates.rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "AMRR increasing rate %d (txcnt=%d retrycnt=%d)", ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } else { amn->amn_recovery = 0; } } else if (is_failure(amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { amn->amn_success_threshold *= 2; if (amn->amn_success_threshold > amrr->amrr_max_success_threshold) amn->amn_success_threshold = amrr->amrr_max_success_threshold; } else { amn->amn_success_threshold = amrr->amrr_min_success_threshold; } rix--; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)", ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } amn->amn_recovery = 0; } /* reset counters */ amn->amn_txcnt = 0; amn->amn_retrycnt = 0; return rix; }
/* * Return the rate index to use in sending a data frame. * Update our internal state if it's been long enough. * If the rate changes we also update ni_txrate to match. */ int ieee80211_amrr_choose(struct ieee80211_node *ni, struct ieee80211_amrr_node *amn) { struct ieee80211_amrr *amrr = amn->amn_amrr; int rix; if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) { rix = amrr_update(amrr, amn, ni); if (rix != amn->amn_rix) { /* update public rate */ ni->ni_txrate = ni->ni_rates.rs_rates[rix] & IEEE80211_RATE_VAL; amn->amn_rix = rix; } amn->amn_ticks = ticks; } else rix = amn->amn_rix; return rix; }
/* * Examine and potentially adjust the transmit rate. */ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni)); int rix; #define is_success(amn) \ (amn->amn_tx_try1_cnt < (amn->amn_tx_try0_cnt/10)) #define is_enough(amn) \ (amn->amn_tx_try0_cnt > 10) #define is_failure(amn) \ (amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3)) rix = amn->amn_rix; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d", amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt, amn->amn_tx_try3_cnt, amn->amn_success_threshold); if (is_success (amn) && is_enough (amn)) { amn->amn_success++; if (amn->amn_success == amn->amn_success_threshold && rix + 1 < ni->ni_rates.rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "increase rate to %d", rix); } else { amn->amn_recovery = 0; } } else if (is_failure (amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { /* recovery failure. */ amn->amn_success_threshold *= 2; amn->amn_success_threshold = min (amn->amn_success_threshold, (u_int)ath_rate_max_success_threshold); IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "decrease rate recovery thr: %d", amn->amn_success_threshold); } else { /* simple failure. */ amn->amn_success_threshold = ath_rate_min_success_threshold; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "decrease rate normal thr: %d", amn->amn_success_threshold); } amn->amn_recovery = 0; rix--; } else { amn->amn_recovery = 0; } } if (is_enough (amn) || rix != amn->amn_rix) { /* reset counters. */ amn->amn_tx_try0_cnt = 0; amn->amn_tx_try1_cnt = 0; amn->amn_tx_try2_cnt = 0; amn->amn_tx_try3_cnt = 0; amn->amn_tx_failure_cnt = 0; } if (rix != amn->amn_rix) { ath_rate_update(sc, ni, rix); } }
/* * Examine and potentially adjust the transmit rate. */ static void ath_rate_ctl(void *arg, struct ieee80211_node *ni) { struct ath_softc *sc = arg; struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni)); int old_rate; #define is_success(amn) \ (amn->amn_tx_try1_cnt < (amn->amn_tx_try0_cnt/10)) #define is_enough(amn) \ (amn->amn_tx_try0_cnt > 10) #define is_failure(amn) \ (amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3)) #define is_max_rate(ni) \ ((ni->ni_txrate + 1) >= ni->ni_rates.rs_nrates) #define is_min_rate(ni) \ (ni->ni_txrate == 0) old_rate = ni->ni_txrate; DPRINTF (sc, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d\n", amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt, amn->amn_tx_try3_cnt, amn->amn_success_threshold); if (is_success (amn) && is_enough (amn)) { amn->amn_success++; if (amn->amn_success == amn->amn_success_threshold && !is_max_rate (ni)) { amn->amn_recovery = 1; amn->amn_success = 0; ni->ni_txrate++; DPRINTF (sc, "increase rate to %d\n", ni->ni_txrate); } else { amn->amn_recovery = 0; } } else if (is_failure (amn)) { amn->amn_success = 0; if (!is_min_rate (ni)) { if (amn->amn_recovery) { /* recovery failure. */ amn->amn_success_threshold *= 2; amn->amn_success_threshold = min (amn->amn_success_threshold, (u_int)ath_rate_max_success_threshold); DPRINTF (sc, "decrease rate recovery thr: %d\n", amn->amn_success_threshold); } else { /* simple failure. */ amn->amn_success_threshold = ath_rate_min_success_threshold; DPRINTF (sc, "decrease rate normal thr: %d\n", amn->amn_success_threshold); } amn->amn_recovery = 0; ni->ni_txrate--; } else { amn->amn_recovery = 0; } } if (is_enough (amn) || old_rate != ni->ni_txrate) { /* reset counters. */ amn->amn_tx_try0_cnt = 0; amn->amn_tx_try1_cnt = 0; amn->amn_tx_try2_cnt = 0; amn->amn_tx_try3_cnt = 0; amn->amn_tx_failure_cnt = 0; } if (old_rate != ni->ni_txrate) { ath_rate_update(sc, ni, ni->ni_txrate); } }
static int amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn, struct ieee80211_node *ni) { int rix = amn->amn_rix; const struct ieee80211_rateset *rs = NULL; KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt)); rs = ieee80211_ratectl_get_rateset(ni); IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR: current rate %d, txcnt=%d, retrycnt=%d", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); /* * XXX This is totally bogus for 11n, as although high MCS * rates for each stream may be failing, the next stream * should be checked. * * Eg, if MCS5 is ok but MCS6/7 isn't, and we can go up to * MCS23, we should skip 6/7 and try 8 onwards. */ if (is_success(amn)) { amn->amn_success++; if (amn->amn_success >= amn->amn_success_threshold && rix + 1 < rs->rs_nrates) { amn->amn_recovery = 1; amn->amn_success = 0; rix++; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR increasing rate %d (txcnt=%d retrycnt=%d)", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } else { amn->amn_recovery = 0; } } else if (is_failure(amn)) { amn->amn_success = 0; if (rix > 0) { if (amn->amn_recovery) { amn->amn_success_threshold *= 2; if (amn->amn_success_threshold > amrr->amrr_max_success_threshold) amn->amn_success_threshold = amrr->amrr_max_success_threshold; } else { amn->amn_success_threshold = amrr->amrr_min_success_threshold; } rix--; IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: AMRR decreasing rate %d (txcnt=%d retrycnt=%d)", __func__, rs->rs_rates[rix] & IEEE80211_RATE_VAL, amn->amn_txcnt, amn->amn_retrycnt); } amn->amn_recovery = 0; } /* reset counters */ amn->amn_txcnt = 0; amn->amn_retrycnt = 0; return rix; }