TreeOutput DecisionTree::decide(std::vector<std::pair<States, bool>> states){ //Check if current node is not a leaf if (!m_currentNode->getIsLeaf()){ bool stateCondition = NULL; if (m_currentNode->getStateID() != States::DEFAULTSTATE){ stateCondition = getStates(states, m_currentNode->getStateID()); } bool leftCondition = NULL; if (m_currentNode->getLeftNode()->getCondition() != NULL){ leftCondition = m_currentNode->getLeftNode()->getCondition(); } bool rightCondition = NULL; if (m_currentNode->getRightNode()->getCondition() != NULL){ rightCondition = m_currentNode->getRightNode()->getCondition(); } if (stateCondition == leftCondition){ m_currentNode = m_currentNode->getLeftNode(); return decide(states); } else if (stateCondition == rightCondition){ m_currentNode = m_currentNode->getRightNode(); return decide(states); } else { } } TreeOutput target = m_currentNode->getTarget(); m_currentNode = m_rootNode; return target; }
void zombie::encounter_human(human h) { chasing=false; if(decide(nest->strength, h.colony->strength)==1) { if(decide(nest->infection_rate, h.colony->strength)==1) { die(); } else { h.infect(*it_zombie); die(); } } else { if(decide(nest->strength, nest->infection_rate)==1) { h.infect(*it_zombie); } else { h.die(); } } }
EnumType decide(const Datum &datum, Node *tree) { if(tree->left == nullptr && tree->right == nullptr) return tree->result; if(util_datajudge(tree->statement,datum)) return decide(datum,tree->right); else return decide(datum,tree->left); }
int decide(int A[], int Li, int Ls){ if (Li>Ls) return -1; else{ int md = (Li+Ls)/2; if(A[md] == md) return md; else if (A[md] < md) return decide(A, md+1, Ls); else return decide(A,Li, Ls-1); return 0; } }
void _exchange_resend(x4s_ike_exchange * xchg, bval dejavu) { uint (* decide)(void * , uint , uint , bval ); /* */ x4_assert(xchg); /* determine the next pause */ decide = xchg->on_resend ? xchg->on_resend : _exchange_resend_default; xchg->out.timeout = decide(xchg->userdata, xchg->seqno, xchg->out.retry, dejavu); if (! xchg->out.timeout) { /* this signals the end for incomplete exchanges */ if (xchg->seqno != x4c_ike_state_completed) x4_ike_exchange_die(xchg); /* .. otherwise it just stops packet retransmissions */ return; } x4_assert(xchg->on_packet); if (! xchg->on_packet(xchg->userdata, &xchg->out.pkt)) { x4_error("xchg_resend: failed\n"); x4_ike_exchange_die(xchg); return; } /* update schedule */ xchg->out.timestamp = x4_time(); xchg->out.retry++; }
ErrorStruct StrongClassifier::errorForFeatures(const TrainingData &features, bool printStats) const { ErrorStruct e; for (int i=0; i<features.size(); i++) { FeatureVector feature = *(features.feature(i)); if (decide(feature)) { feature.val() == POS ? e.true_pos++ : e.false_pos++;//it is really positive } else { feature.val() == NEG ? e.true_neg++ : e.false_neg++;//it is really negative } } // if all 10 samples, 3 is misclassified, error is 3/10 e.error = (e.false_pos + e.false_neg) / ((float)features.size()); if (printStats) { std::cout << e.true_pos << " true positives" << std::endl; std::cout << e.false_pos << " false positives" << std::endl; std::cout << e.true_neg << " true negatives" << std::endl; std::cout << e.false_neg << " false negatives" << std::endl; std::cout << e.error * 100 << "% error" << std::endl; std::cout << std::endl; } return e; }
int main() { int count =0; int i; int start, end; do { printf("Set START, and END : "); scanf_s("%d %d", &start, &end); } while (start < 1 || start >= end); for (i = start; i <= end; i++) { if (i % 3 == 0) count++; else count += decide(i); //printf("%d ", i); //printf("Clap count : %d\n", count); } printf("Clap count : %d\n", count); return 0; }
bool uksat::DpllSolver::querystep() { bool keepgoing = true; if (isstarted() && intime()) { ncalls++; //printdecisions(std::cerr); propagate(); if (issatisfied()) { keepgoing = false; } else if (isconflicting()) { //std::cerr << "!!!CONFLICTING!!!" << std::endl; if (!backtrack()) { keepgoing = false; //std::cerr << "!!!NO BACKTRACK!!!" << std::endl; } } else { int nextvar = decide(); if (!nextvar) { //std::cerr << "!!!NO DECIDE!!!" << std::endl; finish(watchinglits ? -1 : 0); keepgoing = false; } } } else { keepgoing = false; } return keepgoing; }
void ComputationManager::optimize(Computation &c) { updateStats(c); if (optUnsatCheckInterval.getValue() > 0) { optUnsatCheckCounter++; optUnsatCheckCounter %= optUnsatCheckInterval.getValue(); if (optUnsatCheckCounter == 0) { RESULT result = decide(c); if (result == RESULT::UNSAT) { throw AbortException("Intermediate unsat check successful", RESULT::UNSAT); } } } if (optOptimizeInterval.getValue() > 0) { optIntervalCounter++; optIntervalCounter %= optOptimizeInterval.getValue(); if (optIntervalCounter == 0) { while ((maxGlobalNSFSizeEstimation < optMaxGlobalNSFSize.getValue()) || (optMaxGlobalNSFSize.getValue() <= -1)) { unsigned int oldLeavesCount = c.leavesCount(); // divideGlobalNSFSizeEstimation(c.leavesCount()); if (!(c.optimize(left))) { break; } left = !left; divideGlobalNSFSizeEstimation(oldLeavesCount); multiplyGlobalNSFSizeEstimation(c.leavesCount()); } } } updateStats(c); }
main(){ /* Vector de pruebas */ int A[10]={-1, 0, 1, 2, 4, 8, 9}; printf("*Buscar posición: %d\n", decide(A, 0, 6)); }
int init(char s[],int k,int p,char t1[],char t2[]) { if(p==k) decide(s,k,t1,t2); else { int j; if((s[p]-'0')%2) return 0; else { t1[p]=(s[p]-'0')/2+'0'; t2[p]=t1[p]; init(s,k,p-1,t1,t2); t1[p]=(s[p]-'0'+10)/2+'0'; t2[p]=t1[p]; j=p-1; while(j>0&&s[j]=='0') s[j--]+=9; s[j]-=1; init(s,k,p-1,t1,t2); } } return 0; }
bool StrongClassifier::decide(const FeatureVector &featureVector) const { std::vector<float> features(featureVector.size()); for (int i=0; i<featureVector.size(); i++) { features[i] = featureVector.at(i); } return decide(features); }
bool TailPlacer::try_point(int name) { add_red(name); bool doable = decide(); if(!doable) remove_red(name); return doable; }
void loop(){ if (irrecv.decode(&results)){ //Check if the remote control is sending a signal if(results.value==0xFF6897){ //If an '1' is received, turn on robot power=1; } if(results.value==0xFF4AB5){ //If a '0' is received, turn off robot stopmove(); power=0; } if(results.value==0xFF42BD){ //If an '*' is received, switch operating mode from automatic robot to remote control (press also "*" to return to automatic robot mode) modecontrol=1; // Activate remote control operating mode stopmove(); //The robot stops and starts responding to the user's directions } irrecv.resume(); // receive the next value } while(modecontrol==1){ //The system gets into this loop during the remote control mode until modecontrol=0 (with '*') if (irrecv.decode(&results)){ //If something is being received translateIR();//Do something depending on the signal received irrecv.resume(); // receive the next value } } if(power==1){ go(); // if nothing is wrong go forward using go() function above. ++numcycles; if(numcycles>130){ //Watch if something is around every certain number of cycles while moving forward watchsurrounding(); if(leftscanval<sidedistancelimit || ldiagonalscanval<distancelimit){ turnright(turntime); } if(rightscanval<sidedistancelimit || rdiagonalscanval<distancelimit){ turnleft(turntime); } numcycles=0; //Restart count of cycles } distance = watch(); // use the watch() function to see if anything is ahead (when the robot is just moving forward and not looking around it will test the distance in front) if (distance<distancelimit){ // The robot will just stop if it is completely sure there's an obstacle ahead (must test 25 times) (needed to ignore ultrasonic sensor false signals) ++thereis;} if (distance>distancelimit){ thereis=0;} //Count is restarted if (thereis > 25){ stopmove(); // Since something is ahead, stop moving. turndirection = decide(); //Decide which direction to turn. switch (turndirection){ case 'l': turnleft(turntime); break; case 'r': turnright(turntime); break; case 'f': ; //Do not turn if there was really nothing ahead break; } thereis=0; } } }
//-------------------------------------------------------------- void elevator::car_tick1() //tick 1 for each car { car_display(); //display elevator box dests_display(); //display destinations if(loading_timer) //count down load time --loading_timer; if(unloading_timer) //count down unload time --unloading_timer; decide(); //decide what to do } //end car_tick()
int main() { setup(); printf("Hello World! \n I'm Martha and you're about to get rekt. \n"); printf("To the poms! \n"); move(1500,2); system("clear"); printf("Munch munch munch... \n"); turn(1,1); // swing around to gather poms sweeper(-1,10); system("clear"); printf("To the poms! \n"); move(800,5); system("clear"); printf("Munch munch munch... \n"); turn(2,-1); // swing around to gather poms sweeper(-1,10); system("clear"); printf("To the line! \n"); move(800,5); system("clear"); lift(); move(100,1); system("clear"); printf("Sorting... \n"); decide(); decide(); decide(); decide(); // eight times because eight poms decide(); decide(); decide(); decide(); system("clear"); printf("Backing up... \n"); move(-500,1); // back up to avoid vertical projection of bins msleep(1000); mav(leftWheel,0); mav(rightWheel,0); return 0; }
void makeStack(OPNDType *top1, OPTRType *top2) { OPNDType *Np, *Nq; OPTRType *Tp, *Tq; char ch, operator; char save[20] = {0}; int i, f, k = 0, k1; double a, b; PushStack2(top2, '#'); //先给运算栈低存入 # 起始标识符 ch = getchar(); while( 1 ){ if( !decide(ch) ) //若 非运算符运算数 则转换成 # 结束标识符 ch = '#'; i = 0, f = 0, k1 = 0; //i和f辅助存入 n 位数字 k1 辅助存入负数 if( (ch >= '0' && ch <= '9') || ch == '.') f = 1; if( (k == '#' || k == '(') && !f && ch == '-'){ //判断减号是否为负号 ch = getchar(), k1 = 1; if( ch >= '0' && ch <= '9' ) f = 1; } while( (ch >= '0' && ch <= '9') || ch == '.') save[i++] = ch, ch = getchar(); //将字符型数字存到数组中 if( f ){ save[i] = '\0'; if( k1 ) PushStack1(top1, atof(save)*-1); //将字符串转换成双精度 else PushStack1(top1, atof(save)); continue ; } k = ch; //辅助存入负数 switch(Precede(GetTop(top2), ch)){ case 1 : return ; //运算完毕 case '<' : PushStack2(top2, ch); ch = getchar(); break; //进栈继续接收 case '=' : PopStack2(top2, &operator); ch = getchar(); break; //出栈继续接收 case '>' : //运算 不接收 PopStack2(top2, &operator); PopStack1(top1, &a), PopStack1(top1, &b); PushStack1(top1, Operate(b, operator, a)); break ; } if( ch == '#' && !top2->next) return ; } }
int main(int argc, char** argv) { int rank; int cpu_id; double timeout; int rank_per_node = 0; geopm::PlatformImp *plat = NULL; geopm::ProfileSampler *sampler = NULL;; geopm_time_s start, stop; std::vector<std::pair<uint64_t, struct geopm_prof_message_s> > sample; size_t sample_length; const double LOOP_TIMEOUT = 8E-6; //8 ms loop MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (!rank) { // TODO: wrap this in a PlatformImp factory. cpu_id = read_cpuid(); if (cpu_id == 0x62D || cpu_id == 0x63E) { plat = (geopm::PlatformImp *)(new geopm::IVTPlatformImp); } else if (cpu_id == 0x63F) { plat = (geopm::PlatformImp *)(new geopm::HSXPlatformImp); } else { throw geopm::Exception("cpuid: " + std::to_string(cpu_id), GEOPM_ERROR_PLATFORM_UNSUPPORTED, __FILE__, __LINE__); } plat->initialize(); sampler = new geopm::ProfileSampler(4096); sampler->initialize(rank_per_node); sample.resize(sampler->capacity()); while (!sampler->do_shutdown()) { geopm_time(&start); sampler->sample(sample, sample_length); decide(plat, sample, sample_length); timeout = 0.0; while (timeout < LOOP_TIMEOUT) { geopm_time(&stop); timeout = geopm_time_diff(&start, &stop); } } } MPI_Barrier(MPI_COMM_WORLD); if (!rank) { delete sampler; delete plat; } return 0; }
bool btParallelNode::run(btCharacter *self) { qDebug() << "Parallel Execution Started"; foreach(Worker* w,workers){ w->start(); } foreach(Worker* w,workers){ w->wait(); } return decide(); }
AzResponseContext* SimpleConcreteDummyService::queryVerbose(string scope, AzRequestContext* azRequestContext) { OpenAzResourceQueryBuilder* qb = new OpenAzResourceQueryBuilder(); azRequestContext = qb->getScopedAzRequestContext(scope, azRequestContext); // Submit the request and process the results AzResponseContext* azResponseContext = decide(azRequestContext); delete qb; return azResponseContext; }
void step() { int i, j; for(j=1; j<grid_h-1; ++j) { for(i=1; i<grid_w-1; ++i) { int * const old_grid_ptr = old_grid + i + j * grid_w; int * const new_grid_ptr = new_grid + i + j * grid_w; int neighbors[NUM_STATES] = {0, 0, 0}; /* count neighbors, each state separately: */ ++neighbors[*(old_grid_ptr-1)]; ++neighbors[*(old_grid_ptr+1)]; ++neighbors[*(old_grid_ptr-grid_w)]; ++neighbors[*(old_grid_ptr+grid_w)]; *new_grid_ptr = *old_grid_ptr; /* decide state transition randomly: */ switch(*old_grid_ptr) { case SUSCEPTIBLE: if(decide(p_infect * neighbors[INFECTED])) { *new_grid_ptr = INFECTED; } break; case INFECTED: if(decide(p_remove)) { *new_grid_ptr = REMOVED; } break; case REMOVED: if(decide(p_reinsert * neighbors[SUSCEPTIBLE])) { *new_grid_ptr = SUSCEPTIBLE; } break; default: break; } } } }
int check (int low, int high, int N, int K, int *a) { int med, output; if (high == low) return low; else { med = (low+high)/2; output = decide(med, N, K, a); if (output!=0) return check(low, med, N, K, a); else return check(med+1, high, N, K, a); } }
const encoding encoding::decide(ref <const contentHandler> data, const charset& chset, const EncodingUsage usage) { if (usage == USAGE_TEXT) { encoding recEncoding; if (chset.getRecommendedEncoding(recEncoding)) { recEncoding.setUsage(usage); return recEncoding; } } return decide(data, usage); }
int faildistillations::decideAndStore(double failprob, numberandcoordinate& circIOs, int IOIndex, numberandcoordinate& boxIOs, int& lastpos, std::vector<pinpair>& toconn) { int currlastpos = NOBOXESAVAIL; currlastpos = decide(failprob, boxIOs, IOIndex, lastpos); if (currlastpos != NOBOXESAVAIL) storeConnectEntry(circIOs, IOIndex, boxIOs, currlastpos, toconn); //if not the original distillation box, but an additional one //if (currlastpos != transformIOIndexToDistIndex(IOIndex)) if (currlastpos != IOIndex) lastpos = currlastpos; return currlastpos; }
vector<AzResourceActionAssociation>* SimpleConcreteDummyService::query(string scope, AzRequestContext* azRequestContext, bool allowedNotAllowed) { OpenAzResourceQueryBuilder* qb = new OpenAzResourceQueryBuilder(); azRequestContext = qb->getScopedAzRequestContext(scope, azRequestContext); // Submit the request and process the results AzResponseContext* azResponseContext = decide(azRequestContext); // Pull the ResourceAction associations out of the response vector<AzResourceActionAssociation>* azResActAssoc = new vector<AzResourceActionAssociation>; vector<AzResult>* azResults; if (azResponseContext != NULL) { azResults = azResponseContext->getResults(); if ((*azResults).size() > 0) { azResActAssoc = new vector<AzResourceActionAssociation>(); for (unsigned int x = 0; x < (*azResults).size(); x++) { // if want only permits only add permits to set if (allowedNotAllowed) { if ((*azResults)[x].getAzDecision() == AZ_PERMIT) { azResActAssoc->push_back(*((*azResults)[x].getAzResourceActionAssociation())); } // otherwise only add denies to the set } else { if ((*azResults)[x].getAzDecision() == AZ_DENY) { azResActAssoc->push_back(*((*azResults)[x].getAzResourceActionAssociation())); } } } } } delete qb; return azResActAssoc; }
void AGAdult::tryToWork(SUMOReal rate, std::vector<AGWorkPosition>* wps) { if (decide(rate)) { // Select the new work position before giving up the current one. // This avoids that the current one is the same as the new one. AGWorkPosition* newWork = randomFreeWorkPosition(wps); if (work != 0) { work->let(); } work = newWork; work->take(this); } else { if (work != 0) { // Also sets work = 0 with the call back lostWorkPosition work->let(); } } }
void simple_ai::move() { move_dir_ = DOWN; rotate_count_ = 0; if (wait_to_move_steps_.empty()) { generate_factors(origin_game_, origin_factors_); int max_score = -10000; for (int rotate_count = 0; rotate_count < 4; ++rotate_count) { for (int col = 0; col < origin_game_.get_map().width(); ++col) { tetris game_copy = origin_game_; int r; for (r = 0; r < rotate_count; ++r) game_copy.rotate(CLOCK); vector<int> steps; move_side_to_dest(game_copy, col, steps); int move_result = consecutive_move(game_copy, DOWN, steps); if (move_result == DEAD) continue; int score = decide(game_copy); if (score > max_score) { max_score = score; rotate_count_ = r; wait_to_move_steps_ = steps; } } } wait_to_move_steps_.push_back(DOWN); // for complete moving } move_dir_ = wait_to_move_steps_.front(); wait_to_move_steps_.erase(wait_to_move_steps_.begin()); return; }
bool CHttpServer::process(SOCKET sock) { m_sock = sock; // First of all, make socket non-blocking #if defined(WINDOWS_PLATFORM) unsigned long optval = 1; if(::ioctlsocket(m_sock, FIONBIO, &optval) == SOCKET_ERROR) { if (verbose) RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", RHO_NET_ERROR_CODE); return false; } #else int flags = fcntl(m_sock, F_GETFL); if (flags == -1) { if (verbose) RAWLOG_ERROR1("Can not get current socket mode: %d", errno); return false; } if (fcntl(m_sock, F_SETFL, flags | O_NONBLOCK) == -1) { if (verbose) RAWLOG_ERROR1("Can not set non-blocking socket mode: %d", errno); return false; } #endif // Read request from socket ByteVector request; String method, uri, query; HeaderList headers; String body; if (!parse_request(method, uri, query, headers, body)) { if (verbose) RAWLOG_ERROR("Parsing error"); send_response(create_response("500 Internal Error")); return false; } if ( !String_endsWith( uri, "js_api_entrypoint" ) ) if (verbose) RAWLOG_INFO1("Process URI: '%s'", uri.c_str()); return decide(method, uri, query, headers, body); }
static void traverse(htmlNodePtr root) { htmlNodePtr cur_node = root, next_node; int policy; while (cur_node) { next_node = cur_node->next; switch (cur_node->type) { case XML_COMMENT_NODE: cur_node = erase(cur_node); break; case XML_ELEMENT_NODE: policy = decide(cur_node->name); if (policy == STRIP) { // strip code is still buggy, disable for now // fprintf(stderr, "strip %s\n", cur_node->name); next_node = strip(cur_node); cur_node = NULL; } else if (policy == ERASE) { //fprintf(stderr, "erase %s\n", cur_node->name); cur_node = erase(cur_node); } else { wash(cur_node); } break; case XML_TEXT_NODE: break; default: fprintf(stderr, "%d %s \n", cur_node->type, cur_node->name); break; } if (cur_node && cur_node->children) traverse(cur_node->children); cur_node = next_node; } }
// // MAIN // task main() { calibrate(); //Start tasks StartTask(forage_task); StartTask(follow_line_task); StartTask(avoid_task); StartTask(observe_task); //Loops over their output and use it to control what actually happens to the robot. while(true){ switch(decide()){ case FORAGE: motor[motorC] = output_forage[0]; motor[motorA] = output_forage[1]; break; case LINE_FOLLOW: motor[motorC] = output_line_follow[0]; motor[motorA] = output_line_follow[1]; break; case AVOID: motor[motorC] = output_avoid[0]; motor[motorA] = output_avoid[1]; break; case OBSERVE: break; } } }