int solution(uint goal) { if (min_num.count(goal) == 1) { return (int) min_num.at(goal).size(); } else { bool f = false; int result = INT32_MAX; multiset<uint> cur_set; int prev_sol; for (auto i = values.begin(); i != values.end(); i++) { if (goal - *i > goal) { continue; } prev_sol = solution(goal - *i); if (prev_sol == -1) { continue; } if (result > 1 + prev_sol) { f = true; result = 1 + prev_sol; cur_set = min_num.at(goal - *i); cur_set.insert(*i); } } min_num[goal] = cur_set; if (f) { return result; } else { return -1; } } }
int main() { use_io_optimizations(); unsigned int test_cases; cin >> test_cases; cin.ignore(); for (unsigned int test {1}; test <= test_cases; ++test) { cout << "Case #" << test << ": "; string message; getline(cin, message); for (auto i = message.cbegin(); i != message.cend(); ++i) { if (i != message.cbegin() && buttons.at(*i) == buttons.at(*(i - 1))) { cout << ' '; } cout << string(presses.at(*i), buttons.at(*i)); } cout << '\n'; } return 0; }
static map<u32, set<u32>> findExclusiveGroups(const RoseBuildImpl &build, const map<u32, unordered_set<u32>> &exclusiveInfo, const map<u32, vector<RoseVertex>> &vertex_map, const bool is_infix) { map<u32, set<u32>> exclusiveGroups; for (const auto &e : exclusiveInfo) { u32 i = e.first; const auto &s = e.second; set<u32> group; set<RoseVertex> q1(vertex_map.at(i).begin(), vertex_map.at(i).end()); DEBUG_PRINTF("vertex set:%zu\n", q1.size()); for (const auto &val : s) { set<RoseVertex> q2(vertex_map.at(val).begin(), vertex_map.at(val).end()); if (contains(exclusiveInfo.at(val), i) && (!is_infix || mergeableRoseVertices(build, q1, q2))) { group.insert(val); } } if (!group.empty()) { exclusiveGroups[i] = group; } } return exclusiveGroups; }
void mouseFunc(int button, int state, int _x , int _y) { if ( trialMode!=PROBEMODE || !canCalibrate ) return; if ( button== GLUT_LEFT_BUTTON && canCalibrate ) { response=true; } if (button == GLUT_RIGHT_BUTTON && canCalibrate ) { response=false; } responseFile << trialNumber << "\t" << factors.at("Tilt") << "\t" << factors.at("Slant") << "\t" << factors.at("Binocular") << "\t" << factors.at("OmegaY") << "\t" << responseTimer.getElapsedTimeInMilliSec() << "\t" << response << endl; beepOk(); factors = trial.getNext(); trialMode=FIXATIONMODE; translationTimer.start(); responseTimer.start(); trialNumber++; glutPostRedisplay(); }
void TikzExporter2::export_single_snapshot_internal(ostream& output, const Snapshot& s, const task_id t, const map<task_id, vector<task_id>>& rt, const unsigned int depth, const float leftoffset) const{ const float mywidth = 1.5f; const float myheight = 1.5f; const vector<task_id>& marked = s.marked; output << "\\node["; output << "circle, scale=0.75, fill"; if(marked.size() == 0 || find(marked.begin(), marked.end(), t) != marked.end()){ output << ", task_scheduled"; } float complete_width=get_subtree_width(t, rt); output << "] (tid" << t << ") at (" << mywidth * (leftoffset + 0.5f * complete_width) << "," << myheight * depth << "){"; if(show_labels){ output << "\\scriptsize{" << t << "}"; } output << "};" << endl; float cur_leftoffset = leftoffset; // draw "children" for(auto const& it : rt.at(t)){ export_single_snapshot_internal(output, s, it, rt, depth + 1, cur_leftoffset); cur_leftoffset += get_subtree_width(it, rt); } // draw arrows from children for(auto const& it : rt.at(t)){ output << "\\draw[](tid" << t << ") -- (tid" << it << ");" << endl; } }
void drawTrial() { switch ( trialMode ) { case FIXATIONMODE : { // disegna le dita per debug if ( block.at("Phase")==1 && isDrawing==1 ) drawFixation(); } break; case HANDONSTARTMODE : { // disegna le dita per debug if ( block.at("Phase")==1 && isDrawing==1 ) drawFingerTips(); } break; case STIMULUSMODE: { // Disegna le dita solo durante la fase di adattamento if ( block.at("Phase")==1 && isDrawing==1 ) drawFingerTips(); drawStimulus(); } break; } }
void Waltz::setConfiguration(map<string, int> config) { this->config.MaxStepsAfterWinner = config.at("MaxStepsAfterWinner"); this->config.BatteryCapacity = config.at("BatteryCapacity"); this->config.BatteryConsumptionRate = config.at("BatteryConsumptionRate"); this->config.BatteryRechargeRate = config.at("BatteryRechargeRate"); this->batteryRemianing = this->config.BatteryCapacity; }
void addAnomalyState(map<int, State*> & states){ State* state = states.at(8); Option* option = new Option(); option->setChoice("Watch her to see what she will do"); option->setNextState(states.at(7)); state->addOption(option); }
vector<vector<int>> getCoinCombinationsWithTargetSumDynamic(const set<int>& coins, int target) { vector<vector<int>> coin_combinations; for (int coin : coins) { int remaining_value = target - coin; if (remaining_value == 0) { coin_combinations.push_back({coin}); } else if (remaining_value > 0) { if (combinations_for_target.at(remaining_value).size() > 0) { for (vector<int> combination : combinations_for_target.at(remaining_value)) { combination.push_back(coin); coin_combinations.push_back(combination); } } } } return coin_combinations; }
double getSIScaling(const string &originUnit, const string &destinationUnit) { double scaling = 1.0; if (!isScalable(originUnit, destinationUnit)) { throw nix::InvalidUnit("Origin unit and destination unit are not scalable versions of the same SI unit!", "nix::util::getSIScaling"); } string org_unit, org_prefix, org_power; string dest_unit, dest_prefix, dest_power; splitUnit(originUnit, org_prefix, org_unit, org_power); splitUnit(destinationUnit, dest_prefix, dest_unit, dest_power); if ((org_prefix == dest_prefix) && (org_power == dest_power)) { return scaling; } if (dest_prefix.empty() && !org_prefix.empty()) { scaling = PREFIX_FACTORS.at(org_prefix); } else if (org_prefix.empty() && !dest_prefix.empty()) { scaling = 1.0 / PREFIX_FACTORS.at(dest_prefix); } else if (!org_prefix.empty() && !dest_prefix.empty()) { scaling = PREFIX_FACTORS.at(org_prefix) / PREFIX_FACTORS.at(dest_prefix); } if (!org_power.empty()) { int power = std::stoi(org_power); scaling = pow(scaling, power); } return scaling; }
void get_tokens(const string &expr) { stack<string> operators; string current_token; for (unsigned int i = 0; i < expr.size(); ++i) { // If the next char is a space or we're at the end of the expression if (isspace(expr[i + 1]) || i == expr.size() - 1) { current_token += expr[i]; if (is_operator(current_token)) { // If the stack contains higher precedence tokens, while (!operators.empty() && precedence.at(operators.top()) >= precedence.at(current_token)) { postfix.push_back(operators.top()); operators.pop(); } operators.push(current_token); } else { postfix.push_back(current_token); } current_token = ""; } else if (!isspace(expr[i])) { current_token += expr[i]; } } // Check for remainding operators while(!operators.empty()) { postfix.push_back(operators.top()); operators.pop(); } }
map<string,double> perturb_solution_gradient(map<string,Vec4d>&targets,map<string,double>&solution) { map<string,double> sp; for(auto && param : solution) { // data gradient double grad = 0; for(auto && target : targets) { Vec4d cur_pos = joint_position(target.first,solution); for(int i = 0; i < 4; ++i) { grad += 2 * (cur_pos.values[i] - target.second.values[i]) * diff(target.first,param.first,i,solution); } } // regularizer gradient auto null_value = null_solution.at(param.first); double C = regularizers.at(param.first); double diff = null_value - param.second; grad += C * -2 * diff; // update sp[param.first] = param.second - step_size*grad; } return sp; }
void destructStory(map<int, State*> &states){ for(int i = 1; i <= states.size(); i++){ for(int j = 0; j < states.at(i)->getOptions().size(); j++){ delete states.at(i)->getOptions().at(j); } delete states.at(i); } }
string Ram::stateToString(map<AddrSpace, vector<vector<bool>>> state) { string out; out += "# Code:\n"; out += spaceToString(state.at(CODE)); out += "\n# Data:\n"; out += spaceToString(state.at(DATA)); return out; }
RenderedMatch::RenderedMatch(IngameState& ingameState, fea::Renderer2D& renderer, PlayersColor color) : cyvmath::mikelepage::Match({}, false, false, createPlayerArray(color, *this)) // TODO , m_renderer{renderer} , m_ingameState{ingameState} , m_board(renderer, color) , m_gameEnded{false} , m_ownColor{color} , m_opColor{!color} , m_self{dynamic_cast<LocalPlayer&>(*m_players[m_ownColor])} , m_op{dynamic_cast<RemotePlayer&>(*m_players[m_opColor])} , m_setupAccepted{false} , m_piecePromotionBackground{{glm::vec2{100, 100}, glm::vec2{100, 100}, glm::vec2{100, 100}}} , m_piecePromotionTypes{{PieceType::UNDEFINED, PieceType::UNDEFINED, PieceType::UNDEFINED}} , m_renderPiecePromotionBgs{0} , m_piecePromotionHover{0} , m_piecePromotionMousePress{0} { // hardcoded temporarily [TODO] static const map<PlayersColor, Coordinate> fortressStartCoords { {PlayersColor::WHITE, HexCoordinate(4, 7)}, {PlayersColor::BLACK, HexCoordinate(6, 3)} }; auto ownFortress = make_unique<RenderedFortress>(m_ownColor, fortressStartCoords.at(m_ownColor), m_board); m_renderedEntities[RenderPriority::FORTRESS].push_back(ownFortress->getQuad()); m_self.setFortress(move(ownFortress)); m_op.setFortress(make_unique<RenderedFortress>(m_opColor, fortressStartCoords.at(m_opColor), m_board)); glm::uvec2 boardSize = m_board.getSize(); glm::uvec2 boardPos = m_board.getPosition(); auto tmpTexture = makeTexture("res/setup-done.png"); m_buttonSetupDoneTexture = move(tmpTexture.first); m_buttonSetupDone.setPosition(boardPos + boardSize - tmpTexture.second); m_buttonSetupDone.setSize(tmpTexture.second); // hardcoded for now, can be done properly somewhen else m_buttonSetupDone.setTexture(m_buttonSetupDoneTexture); for (auto& quad : m_piecePromotionBackground) quad.setColor({95, 95, 95}); placePiecesSetup(); ingameState.tick = bind(&RenderedMatch::tick, this); ingameState.onMouseMoved = bind(&Board::onMouseMoved, &m_board, _1); ingameState.onMouseButtonPressed = bind(&Board::onMouseButtonPressed, &m_board, _1); ingameState.onMouseButtonReleased = bind(&Board::onMouseButtonReleased, &m_board, _1); ingameState.onKeyPressed = [](const fea::Event::KeyEvent&) { }; ingameState.onKeyReleased = [](const fea::Event::KeyEvent&) { }; m_board.onTileMouseOver = bind(&RenderedMatch::onTileMouseOver, this, _1); m_board.onTileClicked = bind(&RenderedMatch::onTileClicked, this, _1); m_board.onMouseMoveOutside = bind(&RenderedMatch::onMouseMoveOutside, this, _1); m_board.onClickedOutside = bind(&RenderedMatch::onClickedOutsideBoard, this, _1); setStatus("Setup"); }
void Service(bt_pid_t root_pid){ char stdout_path[BT_MAX_PATH]={0}; bt_getenv("STDIN", stdout_path, BT_MAX_PATH); bt_handle fh=bt_fopen(stdout_path, FS_Read | FS_Write); stdin_handle = fh; bt_term_stdout(); bt_term_StartEventMode(); bt_term_SetEventMode(bt_terminal_event_mode::Both); uint16_t terminal_ext_id = bt_query_extension("TERMINAL"); bt_subscribe(bt_kernel_messages::ProcessEnd); bt_subscribe(bt_kernel_messages::MessageReceipt); MessageLoop msgLoop; msgLoop.SetPreviewer([&](const Message &msg) -> bool { /*stringstream dss; dss << "WM: Message ID " << msg.id << " from: " << msg.from << " source: " << msg.source << " type: " << msg.type << endl; bt_zero(dss.str().c_str());*/ if(msg.From() == 0 && msg.Source() == 0 && msg.Type() == bt_kernel_messages::ProcessEnd) { bt_pid_t pid = msg.Content<bt_pid_t>(); stringstream ss; ss << "WM: PID: " << pid << " terminated." << endl; bt_zero(ss.str().c_str()); if(clients.find(pid) != clients.end()){ clients.erase(pid); } if(pid == root_pid || clients.empty()) return false; }else if(msg.From() == 0 && msg.Source() == 0 && msg.Type() == bt_kernel_messages::MessageReceipt) { bt_msg_header omsg = msg.Content<bt_msg_header>(); if(!(omsg.flags & bt_msg_flags::Reply) && clients.find(omsg.to) != clients.end()){ clients.at(omsg.to)->SendNextEvent(); } }else if(msg.From() == 0 && msg.Source() == terminal_ext_id && msg.Type() == bt_terminal_message_type::InputEvent) { bt_terminal_event event = msg.Content<bt_terminal_event>(); HandleInput(event); }else if(msg.From() == sm::SM_GetServerPID()) { if(msg.Type() == sm::sm_ServiceRequest::StopService) return false; }else { if(clients.find(msg.From()) == clients.end()) { auto newclient = make_shared<Client>(msg.From()); if(newclient) { clients.insert(make_pair(msg.From(), newclient)); } } } return true; }); auto wmHandler = make_shared<CustomHandler>([&](const Message &msg) -> bool{ auto from = msg.From(); if(clients.find(from) != clients.end()){ return clients.at(from)->HandleMessage(msg); }else return true; }); msgLoop.AddHandler(wmHandler); msgLoop.RunLoop(); }
void drawRedDotsPlane() { int planeTilt = (int)factors.at("Tilt"); int planeSlant = (int)factors.at("Slant"); double planeDef = factors.at("Def"); double planeOnset=1; bool backprojectionActive=true; double theta=0.0; Eigen::Affine3d modelTransformation; glPushMatrix(); //glLoadIdentity(); //glTranslated(0,0,focalDistance); glMultMatrixd(stimTransformation.data()); switch ( planeTilt ) { case 0: { theta = -acos(exp(-0.346574+0.5*planeDef-planeDef/2*(1-planeOnset*periodicValue/oscillationAmplitude))); glRotated(toDegrees(theta),0,1,0); if (backprojectionActive) glScaled(1/sin(toRadians( -90-planeSlant)),1,1); //backprojection phase } break; case 90: { theta = -acos(exp(-0.346574+0.5*planeDef-planeDef/2*(1-planeOnset*periodicValue/oscillationAmplitude))); glRotated( toDegrees(theta),1,0,0); if (backprojectionActive) glScaled(1,1/sin(toRadians( -90-planeSlant )),1); //backprojection phase } break; case 180: { theta = acos(exp(-0.346574+0.5*planeDef-planeDef/2*(1+planeOnset*periodicValue/oscillationAmplitude))); glRotated(toDegrees(theta),0,1,0); if (backprojectionActive) glScaled(1/sin(toRadians( -90-planeSlant )),1,1); //backprojection phase } break; case 270: { theta = acos(exp(-0.346574+0.5*planeDef-planeDef/2*(1+planeOnset*periodicValue/oscillationAmplitude))); glRotated( toDegrees(theta),1,0,0); if (backprojectionActive) glScaled(1,1/sin(toRadians( -90-planeSlant )),1); //backprojection phase } break; default: cerr << "Error, select tilt to be {0,90,180,270} only" << endl; } stimDrawer.draw(); glGetDoublev(GL_MODELVIEW_MATRIX,modelTransformation.matrix().data()); modelTransformation.matrix() = modelTransformation.matrix().eval(); glPopMatrix(); }
double cal_L(const map<unsigned, vector<example> > &D, const map<unsigned, unsigned> &a, const vector<unsigned> &tras, const Theta &theta)/*{{{*/ { boost::timer::auto_cpu_timer ct("compute likelihood takes %ws\n"); long double L = 0; #pragma omp parallel for reduction(+:L) for (int x = 0;x < stations.size();x ++) { unsigned s = stations[x]; const vector<example> &Ps = D.at(s); vector<example> Pstw; for (const example &exi : Ps) { unsigned ai = exi.art, i = exi.tra; double bi = theta.Ca.at(ai) + theta.C.at(i); uvec qi = theta.Pa.at(ai) + theta.P.at(i); uvec qsum = zvec(theta.l); for (auto it = Pstw.begin();it != Pstw.end();) if (it->t < exi.t && exi.t - it->t >= w) it = Pstw.erase(it); else { qsum += theta.Pa.at(it->art) + theta.P.at(it->tra); it ++; } double coeff = 0; if (Pstw.size() > 0) coeff = 1. / sqrt(Pstw.size()); unsigned slot = exi.t % 86400 / 60 / 60 / theta.Nslot; uvec vterm = theta.V.at(s) + theta.Vt.at(s)[slot] + coeff * qsum; double denom = 0; double expri = exp(bi + inner_prod(qi, vterm)); for (unsigned j : tras) { unsigned aj = a.at(j); double bj = theta.Ca.at(aj) + theta.C.at(j); uvec qj = theta.Pa.at(aj) + theta.P.at(j); denom += exp(bj + inner_prod(qj, vterm)); } #if 0 cout << "bi: " << bi << endl; cout << "qi: " << qi << endl; cout << "vterm: " << vterm << endl; cout << "v: " << theta.V.at(s) << endl; cout << "vt: " << theta.Vt.at(s).at(slot) << endl; cout << "qsum: " << coeff * qsum << endl; cout << "expri: " << expri << ", denom: " << denom << endl << endl; #endif L += log(expri / denom); Pstw.push_back(exi); } } return L; }/*}}}*/
vector<Move> SharedFunctions::calcPossibleMoves(int situation_nimber, vector<int> situation, map<int, int> nimbers, map<int, vector<int>> possible_moves) { vector<Move> moves; for(unsigned stack = 0; stack < situation.size(); stack++) { int stack_size = situation.at(stack); int stack_nimber = nimbers.at(stack_size); int temp_nimber = stack_nimber^situation_nimber; for(pair<int, vector<int>> move : possible_moves) { int diff = stack_size - move.first; vector<int> help_vec; if(diff < 0) { continue; } else if (diff == 0) { for(int split: move.second) { if(split == 0 && split == temp_nimber) { moves.push_back(Move(stack+1, move.first, split, help_vec)); } } } else { for(int split: move.second) { if(diff - split < 0) { continue; } if(split == 1 && nimbers.at(diff) == temp_nimber) { help_vec.push_back(diff); moves.push_back(Move(stack+1, move.first, split, help_vec)); } else if(split > 1) { vector<vector<int>> tmp_comb; tmp_comb = SharedFunctions::getStackSplitCombinations(diff, split); vector<Move> tmp_moves = SharedFunctions::calcMovesFromCombinations(tmp_comb, nimbers, temp_nimber); for(Move tmp_move : tmp_moves) { tmp_move.setStackNumber(stack+1); tmp_move.setTake(move.first); tmp_move.setStackSplit(split); moves.push_back(tmp_move); } } } } } } return moves; }
//Amélioration, ajoute les cours sur plusieurs semaines void rout2(map<int, Prof> &profs, map<int, Promo> &promos, map<int, Course> courses) { //On trie les profs par dispo // sort(profs.begin(), profs.end(), sort_by_availability); //Pour chaque profs for (map<int, Prof>::iterator it=profs.begin(); it!=profs.end(); it++) { grant_lectures((*it).second, promos.at(0), courses); } display_weeks(promos.at(0)); }
string process_char ( char c ) { //assume correct input stringstream ss; string a; ss << c; ss >> a; if ( in_RULES.at ( c ) ) { return PRODUCTION_RULES.at ( c ); } else { return a; } }
void User::broadcast(string const &message) { // Broadcast a message to everyone interested in this user set<User*> users; for (string const &channame : channel) for (string const &username : channels.at(channame).users) users.insert(usersbyname.at(username)); users.insert(this); // Just in case we're not in a channel for (User *user : users) user->write(message); }
void encodeData(istream& input, const map<int, string> &encodingMap, obitstream& output) { int byte = input.get(); // continue until input end of input, byte == -1 while (byte != -1) { string code = encodingMap.at(byte); writeCode(code, output); byte = input.get(); } string eofCode = encodingMap.at(PSEUDO_EOF); writeCode(eofCode, output); }
void Options::handle(View* view, OptionSet set, int lastIndex) { vector<ListElem> options; options.emplace_back("Change settings:", ListElem::TITLE); for (OptionId option : optionSets.at(set)) options.push_back(ListElem(names.at(option), getValueString(option, getValue(option))).setTip(hints.at(option))); options.emplace_back("Done"); auto index = view->chooseFromList("", options, lastIndex, getMenuType(set)); if (!index || (*index) == optionSets.at(set).size()) return; OptionId option = optionSets.at(set)[*index]; changeValue(option, getValue(option), view); handle(view, set, *index); }
int getNextIndex(int starting_index) { int i=starting_index==tfs.size()-1?0:starting_index+1; bool found=movable_.at(tfs[i]); int count=tfs.size(); while (!found && count>0) { i=i==tfs.size()-1?0:i+1; found=movable_.at(tfs[i]); count--; } if (found) return i; else return -1; }
const shared_ptr<devices::HardwareDevice> DeviceManager::find_device_from_info( const map<string, string> search_info) { shared_ptr<devices::HardwareDevice> last_resort_dev; map<string, string> dev_info; for (shared_ptr<devices::HardwareDevice> dev : devices_) { assert(dev); dev_info = get_device_info(dev); // If present, vendor and model always have to match. if (dev_info.count("vendor") > 0 && search_info.count("vendor") > 0) if (dev_info.at("vendor") != search_info.at("vendor")) continue; if (dev_info.count("model") > 0 && search_info.count("model") > 0) if (dev_info.at("model") != search_info.at("model")) continue; // Most unique match: vendor/model/serial_num (but don't match a S/N of 0) if ((dev_info.count("serial_num") > 0) && (dev_info.at("serial_num") != "0") && search_info.count("serial_num") > 0) if (dev_info.at("serial_num") == search_info.at("serial_num") && dev_info.at("serial_num") != "0") return dev; // Second best match: vendor/model/connection_id if (dev_info.count("connection_id") > 0 && search_info.count("connection_id") > 0) if (dev_info.at("connection_id") == search_info.at("connection_id")) return dev; // Last resort: vendor/model/version if (dev_info.count("version") > 0 && search_info.count("version") > 0) if (dev_info.at("version") == search_info.at("version") && dev_info.at("version") != "0") return dev; // For this device, we merely have a vendor/model match. last_resort_dev = dev; } // If there wasn't even a vendor/model/version match, we end up here. // This is usually the case for devices with only vendor/model data. // The selected device may be wrong with multiple such devices attached // but it is the best we can do at this point. After all, there may be // only one such device and we do want to select it in this case. return last_resort_dev; }
void grop_connected_components_helper(int source,list<int> &component,const map<int,list<int> > &adjMap){ //visit this node component.push_back(source); if(!adjMap.at(source).empty()){ for(list<int>::const_iterator list_iterator = adjMap.at(source).begin(); list_iterator != adjMap.at(source).end();++list_iterator){ int n = *list_iterator; if(!is_present(n,component)){ grop_connected_components_helper(n, component, adjMap); } } } }
void WebPage::parse (map < string, WebPage * >&list) { //iterate through outgoing link set for (vector < string >::iterator it = out.begin (); it != out.end (); ++it) { //add incoming link to the webpages on the outgoing list list.at (*it)->addIncomingLink (list.at (fname)); } }
long dfs( int start ){ if( accepting.count(start)>0 ){ return 1; } if( edges.count( start ) == 0 ){ return 0; } if( n.count(start)==0){ for( vector<int>::const_iterator c = edges.at(start).begin(); c != edges.at(start).end(); ++c ){ n[start] += dfs( *c ); } } return n[start]; }
void Action::performAction(map<string, string>& variables) { string variable; // If mVariableName has a value in variables, set variable as this if(variables.find(mVariableName) != variables.end()) variable = variables.at(mVariableName); else { // If it does not have a value, flag a warning and default its value to "0" // Only flag this info if the action IS NOT set (set should be used to initialise this variable!) if(mAction != "set") cout << "Info@" << mPath << " - " << mVariableName << " not initialised, considered as \"0\"" << endl; variable = "0"; } double variable_as_number = stod(variable); string effector_variable = mEffectorVariableValue; // If mEffectorVariableValue is empty, the effector is not a literal and is a variable if(effector_variable.empty()) { // If mComparisonVariableName has a value in variables, set comparison_variable as this if(variables.find(mEffectorVariableName) != variables.end()) effector_variable = variables.at(mEffectorVariableName); else { // If it does not have a value, flag a warning and default its value to "0". cout << "Info@" << mPath << " - " << mEffectorVariableName << " not initialised, considered as \"0\"" << endl; effector_variable = "0"; } } double comparison_variable_as_numer = stod(effector_variable); // Find the correct action operation if(mAction == "set") variables[mVariableName] = effector_variable; else if(mAction == "increase") variables[mVariableName] = to_string(variable_as_number + comparison_variable_as_numer); else if(mAction == "decrease") variables[mVariableName] = to_string(variable_as_number - comparison_variable_as_numer); else if(mAction == "multiply") variables[mVariableName] = to_string(variable_as_number * comparison_variable_as_numer); else if(mAction == "divide") variables[mVariableName] = to_string(variable_as_number + comparison_variable_as_numer); // Report the result of the action cout << "Info@" << mPath << " - " << mVariableName << " = " << variables[mVariableName] << " [from (" << variable << ") by " << mAction << " " << mEffectorVariableName << "(" << effector_variable << ")]" << endl; }