b2Vec2 Enemy::pursue(b2Vec2 target, b2Vec2 tVel, float dist) { b2Vec2 between = target - getPosition(); float distance = between.Length(); float speed = body_->GetLinearVelocity().Length(); int maxTimePrediction = 1000; int timePrediction = 1000; b2Vec2 steer(0, 0); if (speed <= distance / maxTimePrediction) { timePrediction = maxTimePrediction; steer = arrive(target, dist); } else { timePrediction = distance / speed; b2Vec2 newTarget(tVel); newTarget *= timePrediction; newTarget += target; steer = arrive(newTarget, dist); } return steer; }
TEST(suturo_manipulation_move_robot, interpolator_2d_arrive_0_0_at_once) { struct pose_2d rp; struct pose_2d tp; // Set start and goal rp.x_ = 0; rp.y_ = 0; rp.reference_ = "/base_link"; tp.x_ = 0; tp.y_ = 0; tp.reference_ = "/base_link"; struct interpolator_2d_params *inp_params = new interpolator_2d_params(); inp_params->robot_pose_ = rp; inp_params->target_pose_ = tp; inp_params->twist_.xdot_ = 0.0; inp_params->twist_.ydot_ = 0.0; struct interpolator_2d_init_params *init_params = new interpolator_2d_init_params(); init_params->cycle_time_ = 0.1; init_params->vel_limit_ = 0.2; init_params->acc_limit_ = 0.2; init_params->jerk_limit_ = 0.2; init_params->range_ = 0.0025; Suturo_Manipulation_2d_Interpolator *interpolator = new Suturo_Manipulation_2d_Interpolator(); struct interpolator_2d_result rv; interpolator->init(*init_params); while (rv.result_value_ != ReflexxesAPI::RML_FINAL_STATE_REACHED && !arrive(tp.x_, rv.int_pose_.x_, init_params->range_) && !arrive(tp.y_, rv.int_pose_.y_, init_params->range_)) // while (rv.result_value_ != ReflexxesAPI::RML_FINAL_STATE_REACHED) { rv = interpolator->interpolate(*inp_params); inp_params->robot_pose_ = rv.int_pose_; inp_params->twist_ = rv.twist_; } double arrive_range = init_params->range_ + 0.0025; ROS_INFO_STREAM("x: " << inp_params->robot_pose_.x_ << " x_target: " << tp.x_ << " = " << arrive(tp.x_, inp_params->robot_pose_.x_, arrive_range)); ROS_INFO_STREAM("y: " << inp_params->robot_pose_.y_ << " y_target: " << tp.y_ << " = " << arrive(tp.y_, inp_params->robot_pose_.y_, arrive_range)); ASSERT_TRUE(arrive(tp.x_, rv.int_pose_.x_, arrive_range) && arrive(tp.y_, rv.int_pose_.y_, arrive_range)); SUCCEED(); }
LogitechDevice::LogitechDevice( LH_LgLcdMan *drv, bool bw ) : LH_QtDevice(drv) { drv_ = drv; opened_ = false; bw_ = bw; buttonState_ = 0; if( bw_ ) { setDevid( "BW" ); setName( QObject::tr("Logitech B/W device") ); setSize( 160, 43 ); setDepth( 1 ); } else { setDevid( "QVGA" ); setName( QObject::tr("Logitech QVGA device") ); setSize( 320, 240 ); setDepth( 32 ); } arrive(); return; }
b2Vec2 Enemy::evade(b2Vec2 pursuer, b2Vec2 pVel, float dist) { b2Vec2 between = pursuer - getPosition(); float distance = between.Length(); float speed = body_->GetLinearVelocity().Length(); int maxTimePrediction = 1000; int timePrediction = 1000; b2Vec2 steer(0, 0); if (speed <= distance / maxTimePrediction) { timePrediction = maxTimePrediction; steer = arrive(pursuer, dist); } else { timePrediction = distance / speed; b2Vec2 newPursuer(pVel); newPursuer *= timePrediction; newPursuer += pursuer; steer = flee(newPursuer, dist); } return steer; }
void depart (void) /* Event function for departure of a job from a particular station. */ { int station, job_type_queue, task_queue; /* Determine the station from which the job is departing. */ job_type = transfer[3]; task = transfer[4]; station = route[job_type][task]; /* Check to see whether the queue for this station is empty. */ if (list_size[station] == 0) { /* The queue for this station is empty, so make a machine in this station idle. */ --num_machines_busy[station]; timest ((double) num_machines_busy[station], station); } else { /* The queue is nonempty, so start service on first job in queue. */ list_remove (FIRST, station); /* Tally this delay for this station. */ sampst (sim_time - transfer[1], station); /* Tally this same delay for this job type. */ job_type_queue = transfer[2]; task_queue = transfer[3]; sampst (sim_time - transfer[1], num_stations + job_type_queue); /* Schedule end of service for this job at this station. Note defining attributes beyond the first two for the event record before invoking event_schedule. */ transfer[3] = job_type_queue; transfer[4] = task_queue; event_schedule (sim_time + erlang (2, mean_service[job_type_queue][task_queue], STREAM_SERVICE), EVENT_DEPARTURE); } /* If the current departing job has one or more tasks yet to be done, send the job to the next station on its route. */ if (task < num_tasks[job_type]) { ++task; arrive (2); } }
void Vehicle::update( const Vec2f& mousePosition ) { arrive( mousePosition ); velocity += acceleration; velocity.limit( maxSpeed ); position += velocity; acceleration.set( Vec2f::zero() ); angle = toDegrees( atan2f( velocity.y, velocity.x ) ); }
void Goose::get(const QUrl &url) { QNetworkRequest request(url); m_geese->prepare(request); auto reply = m_geese->get(request); connect(reply, &QNetworkReply::finished, this, [ = ]() { emit arrive(QNetworkReply::NoError, reply->readAll()); }); connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, [ = ](QNetworkReply::NetworkError error) { qWarning() << "Goose: get" << reply->errorString(); emit arrive(error, reply->readAll()); }); }
void AIUnit::Update(Scalar delta_t,CharacterUnit& character,BlendedSteering* blender) //Updates the values for the character, with delta_t as //the amount of time passed since the last update and //character as the target for this character { int stateAction = fsm.update(delta_t); //update the state machine if(stateAction == 1) //If the action from the state machine is 1 dying = true; //Then the AI character should send a message that it needs to die if(stateAction == 2) //If the action from the state machine is 2 spawnNewAI = true; //Then the AI character should send a message that a new character should spawn Vector3D currentPos = kinematic.position; //the current position of the character //Create the different steering behavior objects Arrive arrive(*this,character); BlendedSteering* blend = blender; LookWhereYoureGoing look(*this); //Check each key to see which behavior to use and update the steering if (wanderer) steering = blend->GetSteering(); else steering = arrive.GetSteering(); kinematic.rotation = look.GetSteering().rotation; //Make sure the character looks where he is moving kinematic.Update(steering,delta_t); //Update the physics based on the steering Vector3D posDifference = kinematic.position - currentPos; //find the difference between the current position and the next position Translate(posDifference); //Translate the triangle that difference if (fast) { Translate(posDifference*0.75); kinematic.position += posDifference*0.75; } //Keep the character inside the game if (kinematic.position[X] < 20) kinematic.position[X] = 20; if (kinematic.position[X] > windowSize - 20) kinematic.position[X] = windowSize - 20; if (kinematic.position[Y] < 20) kinematic.position[Y] = 20; if (kinematic.position[Y] > windowSize - 20) kinematic.position[Y] = windowSize - 20; body = Triangle3D(Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation)), kinematic.position[Y]+(20*sin(kinematic.orientation)),0), Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation+2.5)), kinematic.position[Y]+(20*sin(kinematic.orientation+2.5)),0), Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation-2.5)), kinematic.position[Y]+(20*sin(kinematic.orientation-2.5)),0)); //Update the triangle to render //If the character gets too close to the player, it kills the player if (abs((character.kinematic.position - kinematic.position).Length()) <= 40) defeatPlayer = true; }
void Goose::post(const QUrl &url, const QByteArray &data) { QNetworkRequest request(url); m_geese->prepare(request); auto reply = m_geese->post(request, data); connect(reply, &QNetworkReply::finished, this, [ = ]() { QMimeDatabase mdb; auto contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); qDebug() << mdb.mimeTypeForName(contentType); emit arrive(QNetworkReply::NoError, reply->readAll()); }); connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, [ = ](QNetworkReply::NetworkError error) { qWarning() << "Goose: get" << reply->errorString(); emit arrive(error, reply->readAll()); }); }
int main() /* Main function. */ { /* Open input and output files. */ infile = fopen("mm1.in", "r"); outfile = fopen("mm1.out", "w"); /* Specify the number of events for the timing function. */ num_events = 2; /* Read input parameters. */ fscanf(infile, "%f %f %d", &mean_interarrival, &mean_service, &num_delays_required); /* Write report heading and input parameters. */ fprintf(outfile, "Single-server queueing system\n\n"); fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n",mean_interarrival); fprintf(outfile, "Mean service time%16.3f minutes\n\n", mean_service); fprintf(outfile, "Number of customers%14d\n\n", num_delays_required); /* Initialize the simulation. */ initialize(); /* Run the simulation while more delays are still needed. */ while (num_custs_delayed < num_delays_required) { /* Determine the next event. */ timing(); /* Update time-average statistical accumulators. */ update_time_avg_stats(); /* Invoke the appropriate event function. */ switch (next_event_type) { case 1: arrive(); break; case 2: depart(); break; } } /* Invoke the report generator and end the simulation. */ report(); fclose(infile); fclose(outfile); return 0; }
cocos2d::Vec2 SteeringBehaviors::calculate() { m_vSteeringForce.setPoint(0, 0); /** * 要知道每一种驱动力的优先级其实是不同的,比如需要首要保证人物之间不能重叠和 * 撞墙,然后才是arrive和seek */ if (On(WALL_AVOIDANCE) && !accumulateForce(m_vSteeringForce, wallAvoidance())) { return m_vSteeringForce; } if (On(SEPARATION) && !accumulateForce(m_vSteeringForce, separation())) { return m_vSteeringForce; } // @_@ 后来加入的外部牵引力,一般是不开放的 if (On(TRACTION) && !accumulateForce(m_vSteeringForce, m_traction)) { return m_vSteeringForce; } if (On(SEEK) && !accumulateForce(m_vSteeringForce, seek(m_vTarget))) { return m_vSteeringForce; } if (On(ARRIVE) && !accumulateForce(m_vSteeringForce, arrive(m_vTarget))) { return m_vSteeringForce; } if (On(PURSUIT) && !accumulateForce(m_vSteeringForce, pursuit(m_targetId))) { return m_vSteeringForce; } auto tmpFormation = m_pOwner->getTeam()->getTeamFormation(); auto tmpFormationPosId = m_pOwner->getMovingEntity().getFormationPosId(); if (On(KEEP_FORMATION) && !accumulateForce(m_vSteeringForce, keepFormation(tmpFormation, tmpFormationPosId))) { return m_vSteeringForce; } return m_vSteeringForce; }
BaseObject* GameObjectFactory::create(const pugi::xml_node& xml, GameSectorStorage* sect_storage) { auto it = m_object_creators.find(xml.attribute("type").value()); if (it == m_object_creators.end()) { throw ESearchItem(xml.attribute("type").value(), "GameObjectFactoryCreators"); } auto sector_name = xml.child("sector"); if (NULL == sector_name) { throw ESearchItem("no <sector> tag", "some object"); } auto target_sector = sect_storage->fetch_sector(sector_name.child_value()); BaseObject* result = it->second->create(xml, target_sector); target_sector->arrive(result); return result; }
Vector2d ComponentSteering::followLeader(GameObject* leader) { Vector2d tv = leader->velocity; Vector2d force; // Calculate the behind point tv *= -1; tv.normalize(); tv *= 10; Vector2d behindLeader = leader->position + tv; // Creates a force to arrive at the behind point force = force + arrive(behindLeader); return force; }
void ComponentSteering::update() { if(!isReached) { if(targetObject != NULL) { if(targetObject->isDead()) { targetObject = NULL; target = target - parent->position; target.normalize(); target *= 10000; //Deberian seguir en linea recta } else { target = targetObject->position; } } Vector2d movement; if(leader) { /*for(unsigned int i=0;i<mainPlayers.size();i++) { movement += evade(mainPlayers[i]); }*/ movement += arrive(this->target); move(movement); Vector2d distanceVector = this->target - parent->position; // Vector2d te permite calcular las distancias float distance = distanceVector.getLength(); // Entra en el rango del objetivo if(distance < 5) { isReached = true; Message message; message.type = Message::TARGET_REACHED; parent->broadcastMessage(message); } } } }
static void usage (int status) { if (status != EXIT_SUCCESS) { emit_try_help(); } else { printf(_("Usage: %s [OPTION]... <SOCKET_FILE>\n"), program_name); printf(_("\ Copy stdin to stdout, and also serve it to UNIX domain socket connections.\n\ Give new SOCKET_FILE connections the last %u lines arrived to stdin so far.\n\ Continue giving all new lines that arrive (just like 'tail -f' does).\n\ "), DEFAULT_N_LINES); emit_mandatory_arg_note (); fputs(_("\ -c, --bytes=K output the last K bytes\n\ "), stdout); printf(_("\ -n, --lines=K output the last K lines, instead of the last %u\n\ "), DEFAULT_N_LINES); fputs(_("\ -w, --wait postpone processing stdin until a client connects\n\ "), stdout); fputs(_("\ -d, --ditch-slow-tailers disconnect tailers who are slow at reading data\n\ "), stdout); fputs(_("\ -i, --ignore-interrupts ignore interrupt signals\n\ "), stdout); fputs(HELP_OPTION_DESCRIPTION, stdout); fputs(VERSION_OPTION_DESCRIPTION, stdout); fputs(_("\ \n\ K (the number of bytes or lines) may have a multiplier suffix:\n\ b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,\n\ GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.\n\ "), stdout); emit_ancillary_info(); } exit(status); }
void trxVehicle::arriveTarget(ofVec3f* _target){ arrive(* _target); }
int main () /* Main function. */ { /* Open input and output files. */ infile = fopen ("jobshop.in", "r"); outfile = fopen ("jobshop.out", "w"); /* Read input parameters. */ fscanf (infile, "%d %d %lg %lg", &num_stations, &num_job_types, &mean_interarrival, &length_simulation); for (j = 1; j <= num_stations; ++j) fscanf (infile, "%d", &num_machines[j]); for (i = 1; i <= num_job_types; ++i) fscanf (infile, "%d", &num_tasks[i]); for (i = 1; i <= num_job_types; ++i) { for (j = 1; j <= num_tasks[i]; ++j) fscanf (infile, "%d", &route[i][j]); for (j = 1; j <= num_tasks[i]; ++j) fscanf (infile, "%lg", &mean_service[i][j]); } for (i = 1; i <= num_job_types; ++i) fscanf (infile, "%lg", &prob_distrib_job_type[i]); /* Write report heading and input parameters. */ fprintf (outfile, "Job-shop model\n\n"); fprintf (outfile, "Number of work stations%21d\n\n", num_stations); fprintf (outfile, "Number of machines in each station "); for (j = 1; j <= num_stations; ++j) fprintf (outfile, "%5d", num_machines[j]); fprintf (outfile, "\n\nNumber of job types%25d\n\n", num_job_types); fprintf (outfile, "Number of tasks for each job type "); for (i = 1; i <= num_job_types; ++i) fprintf (outfile, "%5d", num_tasks[i]); fprintf (outfile, "\n\nDistribution function of job types "); for (i = 1; i <= num_job_types; ++i) fprintf (outfile, "%8.3f", prob_distrib_job_type[i]); fprintf (outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n", mean_interarrival); fprintf (outfile, "Length of the simulation%20.1f eight-hour days\n\n\n", length_simulation); fprintf (outfile, "Job type Work stations on route"); for (i = 1; i <= num_job_types; ++i) { fprintf (outfile, "\n\n%4d ", i); for (j = 1; j <= num_tasks[i]; ++j) fprintf (outfile, "%5d", route[i][j]); } fprintf (outfile, "\n\n\nJob type "); fprintf (outfile, "Mean service time (in hours) for successive tasks"); for (i = 1; i <= num_job_types; ++i) { fprintf (outfile, "\n\n%4d ", i); for (j = 1; j <= num_tasks[i]; ++j) fprintf (outfile, "%9.2f", mean_service[i][j]); } /* Initialize rndlib */ init_twister(); /* Initialize all machines in all stations to the idle state. */ for (j = 1; j <= num_stations; ++j) num_machines_busy[j] = 0; /* Initialize simlib */ init_simlib (); /* Set maxatr = max(maximum number of attributes per record, 4) */ maxatr = 4; /* NEVER SET maxatr TO BE SMALLER THAN 4. */ /* Schedule the arrival of the first job. */ event_schedule (expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL); /* Schedule the end of the simulation. (This is needed for consistency of units.) */ event_schedule (8 * length_simulation, EVENT_END_SIMULATION); /* Run the simulation until it terminates after an end-simulation event (type EVENT_END_SIMULATION) occurs. */ do { /* Determine the next event. */ timing (); /* Invoke the appropriate event function. */ switch (next_event_type) { case EVENT_ARRIVAL: arrive (1); break; case EVENT_DEPARTURE: depart (); break; case EVENT_END_SIMULATION: report (); break; } /* If the event just executed was not the end-simulation event (type EVENT_END_SIMULATION), continue simulating. Otherwise, end the simulation. */ } while (next_event_type != EVENT_END_SIMULATION); fclose (infile); fclose (outfile); return 0; }
/** * Arrive at sosi node. */ void arrive(int32_t n) { arrive(n, 0); }
cocos2d::Vec2 SteeringBehaviors::keepFormation( Formation& aFormation, int posId ) { return arrive(aFormation.getPositionByPosId(posId)); }
int main() /* Main function. */ { printf("Masukkan batas atas job 1 (default: 10): \n"); scanf("%d", &batasatasjob1); printf("\n\nMasukkan batas atas job 2 (default: 40): \n"); scanf("%d", &batasatasjob2); /* Open input and output files. */ infile = fopen("tscomp-tugas.in", "r"); outfile = fopen("tscomp-tugas.out", "w"); /* Read input parameters. */ fscanf(infile, "%d %d %d %d %f %f %f %f", &min_terms, &max_terms, &incr_terms, &num_responses_required, &mean_think, &mean_service, &quantum, &swap); /* Write report heading and input parameters. */ fprintf(outfile, "Time-shared computer model\n\n"); fprintf(outfile, "Number of terminals%9d to%4d by %4d\n\n", min_terms, max_terms, incr_terms); fprintf(outfile, "Mean think time %11.3f seconds\n\n", mean_think); fprintf(outfile, "Mean service time%11.3f seconds\n\n", mean_service); fprintf(outfile, "Quantum %11.3f seconds\n\n", quantum); fprintf(outfile, "Swap time %11.3f seconds\n\n", swap); fprintf(outfile, "Number of jobs processed%12d\n\n\n", num_responses_required); fprintf(outfile, "Number of Average Average"); fprintf(outfile, " Utilization CPU-num/\n"); fprintf(outfile, "terminals response time number in queue of CPU JOB-type"); /* Run the simulation varying the number of terminals. */ for (num_terms = min_terms; num_terms <= max_terms; num_terms += incr_terms) { /* Initialize simlib */ init_simlib(); /* Set maxatr = max(maximum number of attributes per record, 4) */ maxatr = 4; /* NEVER SET maxatr TO BE SMALLER THAN 4. */ /* Initialize the non-simlib statistical counter. */ num_responses = 0; /* Schedule the first arrival to the CPU from each terminal. */ for (term = 1; term <= num_terms; ++term) event_schedule(expon(mean_think, STREAM_THINK), EVENT_ARRIVAL); /* Run the simulation until it terminates after an end-simulation event (type EVENT_END_SIMULATION) occurs. */ do { /* Determine the next event. */ timing(); /* Invoke the appropriate event function. */ switch (next_event_type) { case EVENT_ARRIVAL: arrive(); break; case EVENT_END_CPU_1_RUN: end_CPU_run(LIST_CPU_1); break; case EVENT_END_CPU_2_RUN: end_CPU_run(LIST_CPU_2); break; case EVENT_END_CPU_3_RUN: end_CPU_run(LIST_CPU_3); break; case EVENT_END_SIMULATION: report(); break; } /* If the event just executed was not the end-simulation event (type EVENT_END_SIMULATION), continue simulating. Otherwise, end the simulation. */ } while (next_event_type != EVENT_END_SIMULATION); } fclose(infile); fclose(outfile); printf("\n\nOutput hasil eksekusi program dapat dilihat pada tscomp-tugas.out\n"); return 0; }
main() /* Main function. */ { /* Open input and output files. */ infile = fopen("mm1alt.in", "r"); outfile = fopen("mm1alt.out", "w"); /* Specify the number of events for the timing function. */ num_events = 3; /* Read input parameters. */ fscanf(infile, "%f %f %f", &mean_interarrival, &mean_service, &time_end); /* Write report heading and input parameters. */ fprintf(outfile, "Single-server queueing system with fixed run"); fprintf(outfile, " length\n\n"); fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n", mean_interarrival); fprintf(outfile, "Mean service time%16.3f minutes\n\n", mean_service); fprintf(outfile, "Length of the simulation%9.3f minutes\n\n", time_end); /* Initialize the simulation. */ initialize(); /* Run the simulation until it terminates after an end-simulation event (type 3) occurs. */ do { /* Determine the next event. */ timing(); /* Update time-average statistical accumulators. */ update_time_avg_stats(); /* Invoke the appropriate event function. */ switch (next_event_type) { case 1: arrive(); break; case 2: depart(); break; case 3: report(); break; } /* If the event just executed was not the end-simulation event (type 3), continue simulating. Otherwise, end the simulation. */ } while (next_event_type != 3); fclose(infile); fclose(outfile); return 0; }