void DanceTrackerFrame::onNewCapture() { if(m_iStartFrame > 2 && m_pCapture) { int f = m_pCapture->setFrameNumber(m_iStartFrame-2); doStep(); doStep(); } }
void check_and_compute() { compute_kernel(); // calculate error // not being done right now since we are doing a fixed no. of iterations double *tmp; tmp = temperature; temperature = new_temperature; new_temperature = tmp; constrainBC(); if (iterations % CKP_FREQ == 0 || iterations > MAX_ITER) { #ifdef CMK_MEM_CHECKPOINT contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy)); #elif CMK_MESSAGE_LOGGING if(iterations > MAX_ITER) contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy)); else AtSync(); #else contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy)); #endif } else { doStep(); } }
void MainWindow::on_pushButton_3_clicked() { while ( !this->_multiplicationDone ) { if ( !doStep() ) break; } }
void Engine::doMainLogic() { init(); do { doStep(); meets(); for (IListener* listener : listeners) listener->onStep(robots); } while (!isAllKnownMaze()); }
void Stepper_2BYJ48::makeRevolutions(int revs){ int n = abs(revs); int m; if(revs > 0) m = 512; else m = -512; for(int i = 0; i < n; i++) doStep(m); }
void Evolver::doSteps(int stepCount) { for (int i = 0; i < stepCount; i++) { doStep(); genIdx ++; if (genIdx % 10 == 0) { std::cout << "Currently at step: " << genIdx << std::endl; } } }
void ConductanceBasedNeuron::evolve() { double Iinj, v; // externally applied current plus leak current Iinj = CBN_IEXT + CBN_GL_NS * (CBN_EL - VM); // (pA) // sum all the ionic currents for(uint i=0; i<m_inputs.size(); i++) Iinj += m_inputs[i]; // (pA) CBN_VM_PREV = VM; VM = doStep(VM, GetGlobalDt(), Iinj, CBN_C, CBN_AREA); if (VM >= CBN_SPIKE_THRESH && CBN_VM_PREV < CBN_SPIKE_THRESH) emitSpike(); }
void IzhikevichNeuron::evolve() { double v = VM, u = IZH_U, Iinj = IZH_IEXT; for (int i=0; i<m_inputs.size(); i++) Iinj += m_inputs[i]; doStep(&v, &u, GetGlobalDt()*1e3, IZH_IEXT, IZH_A, IZH_B); VM = v; IZH_U = u; if(VM >= IZH_VSPK) { VM = IZH_C; IZH_U += IZH_D; emitSpike(); } }
//============================================================================= // METHOD : SPELLcontroller::doSkip //============================================================================= void SPELLcontroller::doSkip() { switch(getStatus()) { case STATUS_PAUSED: // Allowed status case STATUS_INTERRUPTED: // Allowed status break; default: return; } if (m_error) return; // Do not continue on error if (!SPELLexecutor::instance().canSkip()) { LOG_WARN("[C] Cannot skip current line"); return; } DEBUG("[C] Do skip"); bool waitAborted = SPELLexecutor::instance().getScheduler().abortWait( false ); // Either we skip a proc line, or we abort a wait condition (then we dont want to actually skip a line) if (waitAborted) { SPELLexecutor::instance().getCIF().warning("Wait condition aborted", LanguageConstants::SCOPE_SYS ); setStatus(STATUS_PAUSED); } else { if (SPELLexecutor::instance().goNextLine()) { m_skipping = not waitAborted; doContinue(); } else { /** \todo Should try to go to upper frame instead of stepping. // This is the issue that obligues us to put a return statement // at the end of each function. */ doStep(false); } } }
Testbench::Testbench() : QWidget() { m_ui = new Ui::Testbench; m_ui->setupUi(this); connect(m_ui->startButton, SIGNAL(clicked()), SLOT(start())); connect(m_ui->stopButton, SIGNAL(clicked()), SLOT(stop())); m_timer = new QTimer(this); m_timer->setInterval(20); connect(m_timer, SIGNAL(timeout()), SLOT(doStep())); m_repTimer = new QTimer(this); m_repTimer->setInterval(4000); m_repTimer->setSingleShot(true); connect(m_repTimer, SIGNAL(timeout()), SLOT(start())); m_traj = new CompositeTrajectory; }
bool SimulatorInterface::step() { const int agtCount = static_cast<int>(getNumAgents()); if (_isRunning) { if (_scbWriter) _scbWriter->writeFrame(_fsm); if (_globalTime >= _maxDuration) { _isRunning = false; } else { for (size_t i = 0; i <= SUB_STEPS; ++i) { try { // TODO: doStep for FSM is a *bad* name; it should be "evaluate". _isRunning = !_fsm->doStep(); doStep(); _fsm->doTasks(); } catch (BFSM::FSMFatalException& e) { logger << Logger::ERR_MSG << "Error in updating the finite state "; logger << "machine -- stopping!\n"; logger << "\t" << e.what() << "\n"; _isRunning = false; } } } } return _isRunning; }
void MainWindow::on_stepForwardButton_clicked() { doStep(1); }
void MainWindow::on_pushButton_2_clicked() { doStep(); }
void Stepper_2BYJ48::rotateOnAngle(double angle){ int steps = int(angle / (0.703125)); // 0.703125 = 360 / 512 doStep(steps); }
void WD177x::writeCommandRegister(uint8_t n) { if ((statusRegister & 0x01) != 0 && (n & 0xF0) != 0xD0) { // ignore command if wd177x is busy, and the command is not // force interrupt return; } if ((statusRegister & 0x01) == 0) // store new command commandRegister = n; if ((n & 0x80) == 0) { // ---- Type I commands ---- uint8_t r = n & 3; // step rate (ignored) bool v = ((n & 0x04) != 0); // verify flag bool h = ((n & 0x08) != 0); // disable spin-up (ignored) bool u = ((n & 0x10) != 0); // update flag (void) r; (void) h; // set busy flag; reset CRC, seek error, data request, and IRQ dataRequestFlag = false; statusRegister = 0x21; if (interruptRequestFlag) { interruptRequestFlag = false; clearInterruptRequest(); } if ((n & 0xF0) == 0) { // RESTORE trackRegister = currentTrack; dataRegister = 0; if (dataRegister < trackRegister) { steppingIn = false; do { doStep(true); } while (trackRegister != dataRegister); } } else if ((n & 0xF0) == 0x10) { // SEEK if (dataRegister > trackRegister) { steppingIn = true; do { doStep(true); } while (trackRegister != dataRegister); } else { steppingIn = false; do { doStep(true); } while (trackRegister != dataRegister); } } else { // STEP if ((n & 0xE0) == 0x40) // STEP IN steppingIn = true; else if ((n & 0xE0) == 0x60) // STEP OUT steppingIn = false; doStep(u); } // command done: update flags and trigger interrupt if (writeProtectFlag) statusRegister = statusRegister | 0x40; if (v && (imageFile == (std::FILE *) 0 || currentTrack >= nTracks || currentTrack != trackRegister)) statusRegister = statusRegister | 0x10; // seek error if (imageFile) { if (currentTrack == 0) statusRegister = statusRegister | 0x04; statusRegister = statusRegister | 0x02; // index pulse } statusRegister = statusRegister & 0xFE; // clear busy flag if (!interruptRequestFlag) { interruptRequestFlag = true; interruptRequest(); } } else if ((n & 0xC0) == 0x80) { // ---- Type II commands ---- bool a0 = ((n & 0x01) != 0); // write deleted data mark (ignored) bool pc = ((n & 0x02) != 0); // disable write precompensation // / enable side compare bool e = ((n & 0x04) != 0); // settling delay (ignored) bool hs = ((n & 0x08) != 0); // disable spin-up / side select bool m = ((n & 0x10) != 0); // multiple sectors (void) a0; (void) e; (void) m; // set busy flag; reset data request, lost data, record not found, // and interrupt request dataRequestFlag = false; statusRegister = 0x01; if (interruptRequestFlag) { interruptRequestFlag = false; clearInterruptRequest(); } // select side (if enabled) if (isWD1773) { if (pc) currentSide = uint8_t(hs ? 1 : 0); } bufPos = 512; if ((n & 0x20) == 0) { // READ SECTOR if (!setFilePosition()) statusRegister = statusRegister | 0x10; // record not found else if (std::fread(&(buf[0]), 1, 512, imageFile) != 512) statusRegister = statusRegister | 0x08; // CRC error else { dataRequestFlag = true; statusRegister = statusRegister | 0x02; bufPos = 0; } } else { // WRITE SECTOR if (writeProtectFlag) statusRegister = statusRegister | 0x40; // disk is write protected else if (!setFilePosition()) statusRegister = statusRegister | 0x10; // record not found else { dataRequestFlag = true; statusRegister = statusRegister | 0x02; bufPos = 0; } } if (bufPos >= 512) { // on error: clear busy flag, and trigger interrupt statusRegister = statusRegister & 0xFE; if (!interruptRequestFlag) { interruptRequestFlag = true; interruptRequest(); } } } else if ((n & 0xF0) != 0xD0) { // ---- Type III commands ---- bool p = ((n & 0x02) != 0); // disable write precompensation bool e = ((n & 0x04) != 0); // settling delay (ignored) bool h = ((n & 0x08) != 0); // disable spin-up (ignored) (void) p; (void) e; (void) h; // set busy flag; reset data request, lost data, record not found, // and interrupt request dataRequestFlag = false; statusRegister = 0x01; if (interruptRequestFlag) { interruptRequestFlag = false; clearInterruptRequest(); } bufPos = 512; if ((n & 0x20) == 0) { // READ ADDRESS if (imageFile != (std::FILE *) 0 && currentTrack < nTracks && currentSide < nSides) { buf[506] = currentTrack; buf[507] = currentSide; buf[508] = 0x01; // assume first sector of track buf[509] = 0x02; // 512 bytes per sector uint16_t tmp = calculateCRC(&(buf[506]), 4, 0xB230); buf[510] = uint8_t(tmp >> 8); // CRC high byte buf[511] = uint8_t(tmp & 0xFF); // CRC low byte bufPos = 506; dataRequestFlag = true; statusRegister = statusRegister | 0x02; } else
void MainWindow::pumpCPU() { // doStep(1000); doStep(1); //doStep(100000); }
/** * Train the SVM using several cross validation iterations * @param pNorm Normalization object */ void CrossValidation::train(Normalizer * pNorm) { if (VERB > 0) { cerr << "---Training with Cpos"; if (selectedCpos_ > 0) { cerr << "=" << selectedCpos_; } else { cerr << " selected by cross validation"; } cerr << ", Cneg"; if (selectedCneg_ > 0) { cerr << "=" << selectedCneg_; } else { cerr << " selected by cross validation"; } cerr << ", fdr=" << selectionFdr_ << endl; } // iterate int foundPositivesOldOld = 0, foundPositivesOld = 0, foundPositives = 0; for (unsigned int i = 0; i < niter_; i++) { if (VERB > 1) { cerr << "Iteration " << i + 1 << " :\t"; } bool updateDOC = true; foundPositives = doStep(updateDOC); if (VERB > 1) { cerr << "After the iteration step, " << foundPositives << " target PSMs with q<" << testFdr_ << " were estimated by cross validation" << endl; } if (VERB > 2) { cerr << "Obtained weights" << endl; printAllWeights(cerr, pNorm); } if (foundPositives > 0 && foundPositivesOldOld > 0 && quickValidation_ && (static_cast<double>(foundPositives - foundPositivesOldOld) <= foundPositivesOldOld * requiredIncreaseOver2Iterations_)) { if (VERB > 1) { std::cerr << "Performance increase over the last two iterations " << "indicate that the algorithm has converged\n" << "(" << foundPositives << " vs " << foundPositivesOldOld << ")" << std::endl; } break; } foundPositivesOldOld = foundPositivesOld; foundPositivesOld = foundPositives; } if (VERB == 2) { cerr << "Obtained weights (only showing weights of first cross validation set)" << endl; printSetWeights(cerr, 0, pNorm); } foundPositives = 0; for (size_t set = 0; set < numFolds_; ++set) { if (DataSet::getCalcDoc()) { testScores_[set].getDOC().copyDOCparameters(trainScores_[set].getDOC()); testScores_[set].setDOCFeatures(); } foundPositives += testScores_[set].calcScores(w_[set], testFdr_); } if (VERB > 0) { std::cerr << "After all training done, " << foundPositives << " target PSMs with q<" << testFdr_ << " were found when measuring on the test set" << std::endl; } }
void MainWindow::on_stepBackwardButton_clicked() { doStep(-1); }
void VehicleSim::update(double dt) { for (b2Body* body = _physWorld.GetBodyList(); body; body = body->GetNext()) { // Simulate rolling resistance // Simple version of rolling resistance using formula given by spec // Frr = -Crr * v // A better implementation of rolling resistance would // counteract the movement due to other forces // such that a coefficient of 1 would equal no movement // To calculate this, you could resolve the forces on the body into the direction of // the vector perpendicular to the normal of the contact and then multiply that // by the coefficient of friction of the contact for (b2ContactEdge* contactEdge = body->GetContactList(); contactEdge; contactEdge = contactEdge->next) { b2Contact* contact = contactEdge->contact; // Get fixtures b2Fixture* fixA = contact->GetFixtureA(); b2Fixture* fixB = contact->GetFixtureB(); b2Fixture* bodyFix = (fixA->GetBody() == body ? fixA : fixB); if (bodyFix->GetShape()->GetType() == b2Shape::e_circle) { // Get friction of fixtures float ca = fixA->GetFriction(); float cb = fixB->GetFriction(); // Calculate coefficient of friction for this contact // (average of both coefficients of friction) float c = contact->GetFriction(); // Calculate force due to rolling resistance // F_rr = v * -c_rr b2Vec2 F_rr = -c * body->GetLinearVelocity(); // Apply rolling resistance body->ApplyForceToCenter(F_rr, true); } } // Simple aerodynamic drag, calculated using the formula // Fad = -Cad * v|v| // Where Cad = the cross sectional area of the car // And v is the velocity // The cross sectional area is scaled down from world coordinates // by a factor of 1000 to produce nice results // A more complicated form of aerodynamic drag can be calculated // the mass density p of the air (dependent on its temperature and pressure), // and the drag coefficient Cd calculated using the object's geometry // The formula for this would be Fd = 0.5 * p * v|v| * Cd * Cad // But this is beyond the scope of this simulation b2Fixture* fixtures = body->GetFixtureList(); if (fixtures != nullptr) { b2AABB aabb = fixtures->GetAABB(0); for (b2Fixture* fix = fixtures; fix; fix = fix->GetNext()) { // The cross sectional area is estimated using the AABB of each shape aabb.Combine(fix->GetAABB(0)); } b2Vec2 size = 0.001f * (aabb.upperBound - aabb.lowerBound); // Reverse size to get an approximation of cross sectional area float temp = size.x; size.x = size.y; size.y = temp; // Calculate v|v| b2Vec2 vsquared = body->GetLinearVelocity().Length() * body->GetLinearVelocity(); // Calculate force of aerodynamic drag b2Vec2 Fad(-size.x * vsquared.x, -size.y * vsquared.y); // Apply force to body body->ApplyForceToCenter(Fad, true); } } // Update physics system double time = glfwGetTime(); float stepTime = (1.0f / _timeStep); while (_lastPhysicsUpdate + stepTime < time) { if (_simulationRunning) doStep(); _lastPhysicsUpdate += stepTime; } // Update options if (!_worldOptionsTabButton->Hidden()) { for (auto it = _updatableOptions.begin(); it != _updatableOptions.end(); ++it) { (*it)->update(); } } // Do frame update doFrameInput(dt); // Get inner area of dock Gwen::Rect innerBounds = _guiDock->GetInnerBounds(); // Update camera's viewport _camera.setViewport(innerBounds.x, innerBounds.y, innerBounds.w, innerBounds.h); // Update camera's matrix if (innerBounds.h > 0) { float aspect = (float)innerBounds.w / innerBounds.h; _camera.orthographic(_orthoScale, aspect); } // Handle motor for each joint for (auto joint = _physWorld.GetJointList(); joint; joint = joint->GetNext()) { MotorInput* motorInput = (MotorInput*)joint->GetUserData(); if (motorInput != nullptr) { motorInput->update(_window, joint); } } // Set window title const int TITLE_LEN = 1024; char title[1024]; sprintf(title, VEHICLESIM_TITLE_FORMAT, getFPS()); glfwSetWindowTitle(_window, title); }
void ResumeFromSync() { doStep(); }
//============================================================================= // METHOD : SPELLcontroller::executeCommand() //============================================================================= void SPELLcontroller::executeCommand( const ExecutorCommand& cmd ) { // If a (repeatable) command is being executed, discard this one if (isCommandPending() && (cmd.id != CMD_ABORT) && (cmd.id != CMD_FINISH) && (cmd.id != CMD_INTERRUPT) && (cmd.id != CMD_PAUSE) && (cmd.id != CMD_CLOSE)) { LOG_WARN("Discarding command " + cmd.id); return; } LOG_INFO("Now executing command " + cmd.id); startCommandProcessing(); if (cmd.id == CMD_ABORT) { doAbort(); } else if (cmd.id == CMD_FINISH) { doFinish(); } else if (cmd.id == CMD_ACTION) { doUserAction(); } else if (cmd.id == CMD_STEP) { doStep( false ); } else if (cmd.id == CMD_STEP_OVER) { doStep( true ); } else if (cmd.id == CMD_RUN) { doPlay(); } else if (cmd.id == CMD_SKIP) { doSkip(); } else if (cmd.id == CMD_GOTO) { if (cmd.earg == "line") { DEBUG("[C] Processing go-to-line " + cmd.arg); try { int line = STRI(cmd.arg); doGoto( line ); } catch(...) {}; } else if (cmd.earg == "label") { DEBUG("[C] Processing go-to-label " + cmd.arg); doGoto( cmd.arg ); } else { SPELLexecutor::instance().getCIF().error("Unable to process Go-To command, no target information", LanguageConstants::SCOPE_SYS ); } } else if (cmd.id == CMD_PAUSE) { doPause(); } else if (cmd.id == CMD_INTERRUPT) { doInterrupt(); } else if (cmd.id == CMD_SCRIPT) { /** \todo determine when to override */ doScript(cmd.arg,false); } else if (cmd.id == CMD_CLOSE) { m_recover = false; m_reload = false; doClose(); } else if (cmd.id == CMD_RELOAD) { doReload(); } else if (cmd.id == CMD_RECOVER) { doRecover(); } else { LOG_ERROR("[C] UNRECOGNISED COMMAND: " + cmd.id) } m_mailbox.commandProcessed(); // The command has finished, release the dispatcher setCommandFinished(); DEBUG("[C] Command execution finished " + cmd.id); //TEMPORARILY DISABLED: it creates deadlocks. // notifyCommandToCore( cmd.id ); }