void Search_Branch_And_Bound_Improved_Threaded<RETURNTYPE,DIMTYPE,SUBSET,CRITERION,max_threads>::pre_evaluate_availables() { assert(currentset); assert(grandparent::get_criterion()); const PSubset ¤tset=grandparent::get_currentset(); // pre-evaluate available features before next tree level construction RETURNTYPE value; DIMTYPE feature; typename grandparent::PNode avail; for(bool got=getFirstAvailable(avail);got;got=getNextAvailable(avail)) { assert(currentset->selected_raw(avail->feature)); currentset->deselect_raw(avail->feature); _evaluator.add_candidate(currentset,avail->feature); currentset->select_raw(avail->feature); } PSubset dummysub; for(bool got=_evaluator.getFirstResult(value,dummysub,feature);got;got=_evaluator.getNextResult(value,dummysub,feature)) { if(getAvailable(feature,avail)) { avail->value=value; avail->type=grandparent::COMPUTED; } } }
void Search_Branch_And_Bound_Basic<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>::pre_evaluate_availables() { const PSubset ¤tset=parent::get_currentset(); assert(currentset); // pre-evaluate available features before next tree level construction PNode avail; for(bool got=getFirstAvailable(avail);got;got=getNextAvailable(avail)) { avail->value=(RETURNTYPE)rand(); // in basic B&B ordering is not defined, randomization here aims at preventing worst-case scenarios avail->type=parent::UNKNOWN; } }
void onSwitchLongEnterPress(const char *result) { if (result == STR_MENU_SWITCHES) checkIncDecSelection = SWSRC_FIRST_SWITCH; else if (result == STR_MENU_TRIMS) checkIncDecSelection = SWSRC_FIRST_TRIM; else if (result == STR_MENU_LOGICAL_SWITCHES) checkIncDecSelection = SWSRC_FIRST_LOGICAL_SWITCH + getFirstAvailable(0, NUM_LOGICAL_SWITCH, isLogicalSwitchAvailable); else if (result == STR_MENU_OTHER) checkIncDecSelection = SWSRC_ON; else if (result == STR_MENU_INVERT) checkIncDecSelection = SWSRC_INVERT; }
void onSourceLongEnterPress(const char *result) { if (result == STR_MENU_INPUTS) checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable)+1; #if defined(LUA_MODEL_SCRIPTS) else if (result == STR_MENU_LUA) checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable); #endif else if (result == STR_MENU_STICKS) checkIncDecSelection = MIXSRC_FIRST_STICK; else if (result == STR_MENU_POTS) checkIncDecSelection = MIXSRC_FIRST_POT; else if (result == STR_MENU_MAX) checkIncDecSelection = MIXSRC_MAX; else if (result == STR_MENU_HELI) checkIncDecSelection = MIXSRC_FIRST_HELI; else if (result == STR_MENU_TRIMS) checkIncDecSelection = MIXSRC_FIRST_TRIM; else if (result == STR_MENU_SWITCHES) checkIncDecSelection = MIXSRC_FIRST_SWITCH; else if (result == STR_MENU_TRAINER) checkIncDecSelection = MIXSRC_FIRST_TRAINER; else if (result == STR_MENU_CHANNELS) checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_CH, MIXSRC_LAST_CH, isSourceAvailable); else if (result == STR_MENU_GVARS) checkIncDecSelection = MIXSRC_FIRST_GVAR; else if (result == STR_MENU_TELEMETRY) { for (int i = 0; i < MAX_SENSORS; i++) { TelemetrySensor * sensor = & g_model.telemetrySensors[i]; if (sensor->isAvailable()) { checkIncDecSelection = MIXSRC_FIRST_TELEM + 3*i; break; } } } }
void Search_Branch_And_Bound_Improved_Threaded<RETURNTYPE,DIMTYPE,SUBSET,CRITERION,max_threads>::process_leafs() { assert(currentset); assert(grandparent::get_criterion()); const PSubset ¤tset=grandparent::get_currentset(); typename grandparent::PNode avail; for(bool got=getFirstAvailable(avail);got;got=getNextAvailable(avail)) { assert(currentset->selected_raw(avail->feature)); currentset->deselect_raw(avail->feature); _evaluator.add_candidate(currentset,avail->feature); currentset->select_raw(avail->feature); } RETURNTYPE value; DIMTYPE feature; PSubset sub; for(bool got=_evaluator.getFirstResult(value,sub,feature);got;got=_evaluator.getNextResult(value,sub,feature)) { grandparent::update_bound(value,sub); //adds to tracker! } }
int checkIncDec(unsigned int event, int val, int i_min, int i_max, unsigned int i_flags, IsValueAvailable isValueAvailable, const CheckIncDecStops &stops) { int newval = val; #if defined(DBLKEYS) uint32_t in = KEYS_PRESSED(); if (!(i_flags & NO_DBLKEYS) && (EVT_KEY_MASK(event))) { bool dblkey = true; if (DBLKEYS_PRESSED_RGT_LFT(in)) { if (!isValueAvailable || isValueAvailable(-val)) { newval = -val; } } else if (DBLKEYS_PRESSED_RGT_UP(in)) { newval = (i_max > stops.max() ? stops.max() : i_max); while (isValueAvailable && !isValueAvailable(newval) && newval>i_min) { --newval; } } else if (DBLKEYS_PRESSED_LFT_DWN(in)) { newval = (i_min < stops.min() ? stops.min() : i_min); while (isValueAvailable && !isValueAvailable(newval) && newval<i_max) { ++newval; } } else if (DBLKEYS_PRESSED_UP_DWN(in)) { newval = 0; } else { dblkey = false; } if (dblkey) { killEvents(KEY_UP); killEvents(KEY_DOWN); killEvents(KEY_RIGHT); killEvents(KEY_LEFT); killEvents(KEY_PAGE); killEvents(KEY_MENU); killEvents(KEY_ENTER); killEvents(KEY_EXIT); event = 0; } } #endif if (s_editMode>0 && (IS_ROTARY_RIGHT(event) || event==EVT_KEY_FIRST(KEY_UP) || event==EVT_KEY_REPT(KEY_UP))) { do { if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) { newval += min(10, i_max-val); } else { newval++; } } while (isValueAvailable && !isValueAvailable(newval) && newval<=i_max); if (newval > i_max) { newval = val; killEvents(event); AUDIO_WARNING2(); } else { AUDIO_KEYPAD_UP(); } } else if (s_editMode>0 && (IS_ROTARY_LEFT(event) || event==EVT_KEY_FIRST(KEY_DOWN) || event==EVT_KEY_REPT(KEY_DOWN))) { do { if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) { newval -= min(10, val-i_min); } else { newval--; } } while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min); if (newval < i_min) { newval = val; killEvents(event); AUDIO_WARNING2(); } else { AUDIO_KEYPAD_DOWN(); } } if (!READ_ONLY() && i_min==0 && i_max==1 && (event==EVT_KEY_BREAK(KEY_ENTER) || IS_ROTARY_BREAK(event))) { s_editMode = 0; newval = !val; } #if defined(AUTOSWITCH) if (i_flags & INCDEC_SWITCH) { newval = checkIncDecMovedSwitch(newval); } #endif #if defined(AUTOSOURCE) if (i_flags & INCDEC_SOURCE) { if (s_editMode>0) { int source = GET_MOVED_SOURCE(i_min, i_max); if (source) { newval = source; } #if defined(AUTOSWITCH) else { unsigned int swtch = abs(getMovedSwitch()); if (swtch) { newval = switchToMix(swtch); } } #endif } } #endif if (newval > i_max || newval < i_min) { newval = (newval > i_max ? i_max : i_min); killEvents(event); AUDIO_WARNING2(); } if (newval != val) { if (!(i_flags & NO_INCDEC_MARKS) && (newval != i_max) && (newval != i_min) && stops.contains(newval) && !IS_ROTARY_EVENT(event)) { bool pause = (newval > val ? !stops.contains(newval+1) : !stops.contains(newval-1)); if (pause) { pauseEvents(event); // delay before auto-repeat continues if (newval>val) // without AUDIO it's optimized, because the 2 sounds are the same AUDIO_KEYPAD_UP(); else AUDIO_KEYPAD_DOWN(); } } eeDirty(i_flags & (EE_GENERAL|EE_MODEL)); checkIncDec_Ret = (newval > val ? 1 : -1); } else { checkIncDec_Ret = 0; } if (i_flags & INCDEC_SOURCE) { if (event == EVT_KEY_LONG(KEY_ENTER)) { killEvents(event); checkIncDecSelection = MIXSRC_NONE; if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) { if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE) { POPUP_MENU_ADD_ITEM(STR_MENU_INPUTS); } } #if defined(LUA_MODEL_SCRIPTS) if (i_min <= MIXSRC_FIRST_LUA && i_max >= MIXSRC_FIRST_LUA) { if (getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE) { POPUP_MENU_ADD_ITEM(STR_MENU_LUA); } } #endif if (i_min <= MIXSRC_FIRST_STICK && i_max >= MIXSRC_FIRST_STICK) POPUP_MENU_ADD_ITEM(STR_MENU_STICKS); if (i_min <= MIXSRC_FIRST_POT && i_max >= MIXSRC_FIRST_POT) POPUP_MENU_ADD_ITEM(STR_MENU_POTS); if (i_min <= MIXSRC_MAX && i_max >= MIXSRC_MAX) POPUP_MENU_ADD_ITEM(STR_MENU_MAX); #if defined(HELI) if (i_min <= MIXSRC_FIRST_HELI && i_max >= MIXSRC_FIRST_HELI) POPUP_MENU_ADD_ITEM(STR_MENU_HELI); #endif if (i_min <= MIXSRC_FIRST_TRIM && i_max >= MIXSRC_FIRST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS); if (i_min <= MIXSRC_FIRST_SWITCH && i_max >= MIXSRC_FIRST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES); if (i_min <= MIXSRC_FIRST_TRAINER && i_max >= MIXSRC_FIRST_TRAINER) POPUP_MENU_ADD_ITEM(STR_MENU_TRAINER); if (i_min <= MIXSRC_FIRST_CH && i_max >= MIXSRC_FIRST_CH) POPUP_MENU_ADD_ITEM(STR_MENU_CHANNELS); if (i_min <= MIXSRC_FIRST_GVAR && i_max >= MIXSRC_FIRST_GVAR && isValueAvailable(MIXSRC_FIRST_GVAR)) { POPUP_MENU_ADD_ITEM(STR_MENU_GVARS); } if (i_min <= MIXSRC_FIRST_TELEM && i_max >= MIXSRC_FIRST_TELEM) { for (int i = 0; i < MAX_SENSORS; i++) { TelemetrySensor * sensor = & g_model.telemetrySensors[i]; if (sensor->isAvailable()) { POPUP_MENU_ADD_ITEM(STR_MENU_TELEMETRY); break; } } } popupMenuHandler = onSourceLongEnterPress; } if (checkIncDecSelection != 0) { newval = checkIncDecSelection; if (checkIncDecSelection != MIXSRC_MAX) s_editMode = EDIT_MODIFY_FIELD; checkIncDecSelection = 0; } } else if (i_flags & INCDEC_SWITCH) { if (event == EVT_KEY_LONG(KEY_ENTER)) { killEvents(event); checkIncDecSelection = SWSRC_NONE; if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES); if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS); if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) { for (int i = 0; i < NUM_LOGICAL_SWITCH; i++) { if (isValueAvailable && isValueAvailable(SWSRC_FIRST_LOGICAL_SWITCH+i)) { POPUP_MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES); break; } } } if (isValueAvailable && isValueAvailable(SWSRC_ON)) POPUP_MENU_ADD_ITEM(STR_MENU_OTHER); if (isValueAvailable && isValueAvailable(-newval)) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT); popupMenuHandler = onSwitchLongEnterPress; s_editMode = EDIT_MODIFY_FIELD; } if (checkIncDecSelection != 0) { newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection); s_editMode = EDIT_MODIFY_FIELD; checkIncDecSelection = 0; } } return newval; }