void OnlineSearchBioRxiv::resultPageDone() { emit progress(++curStep, numSteps); QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (handleErrors(reply)) { /// ensure proper treatment of UTF-8 characters const QString htmlCode = QString::fromUtf8(reply->readAll().constData()); static const QRegExp highwireRegExp(QStringLiteral("/highwire/citation/\\d+/bibtex")); if (highwireRegExp.indexIn(htmlCode) > 0) { const QUrl url = QUrl(QStringLiteral("http://biorxiv.org") + highwireRegExp.cap(0)); QNetworkRequest request(url); QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request); InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply); connect(reply, &QNetworkReply::finished, this, &OnlineSearchBioRxiv::bibTeXDownloadDone); } else if (!d->resultPageUrls.isEmpty()) { const QUrl firstUrl = *d->resultPageUrls.constBegin(); d->resultPageUrls.remove(firstUrl); QNetworkRequest request(firstUrl); QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request); InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply); connect(reply, &QNetworkReply::finished, this, &OnlineSearchBioRxiv::resultPageDone); } else stopSearch(resultNoError); } }
void OnlineSearchBioRxiv::resultsPageDone() { emit progress(++curStep, numSteps); QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (handleErrors(reply)) { /// ensure proper treatment of UTF-8 characters const QString htmlCode = QString::fromUtf8(reply->readAll().constData()); static const QRegExp contentRegExp(QStringLiteral("/content/early/[12]\\d{3}/[01]\\d/\\d{2}/\\d+")); int p = -1; while ((p = contentRegExp.indexIn(htmlCode, p + 1)) > 0) { const QUrl url = QUrl(QStringLiteral("http://biorxiv.org") + contentRegExp.cap(0)); d->resultPageUrls.insert(url); } if (d->resultPageUrls.isEmpty()) stopSearch(resultNoError); else { const QUrl firstUrl = *d->resultPageUrls.constBegin(); d->resultPageUrls.remove(firstUrl); QNetworkRequest request(firstUrl); QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request); InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply); connect(reply, &QNetworkReply::finished, this, &OnlineSearchBioRxiv::resultPageDone); } } }
Kfind::~Kfind() { stopSearch(); dirlister->stop(); delete dirlister; kdDebug() << "Kfind::~Kfind" << endl; }
void EngineControl::startPonder(const Position& pos, const std::vector<Move>& moves, const SearchParams& sPar) { stopSearch(); setupPosition(pos, moves); computeTimeLimit(sPar); ponder = true; infinite = false; startThread(-1, -1, -1, -1); }
void DocumentListModel::rescan() { stopSearch(); beginResetModel(); m_allDocumentInfos.clear(); m_currentDocumentInfos.clear(); endResetModel(); qApp->processEvents(); startSearch(); }
void EngineControl::startSearch(const Position& pos, const std::vector<Move>& moves, const SearchParams& sPar) { stopSearch(); setupPosition(pos, moves); computeTimeLimit(sPar); ponder = false; infinite = (maxTimeLimit < 0) && (maxDepth < 0) && (maxNodes < 0); searchMoves = sPar.searchMoves; startThread(minTimeLimit, maxTimeLimit, maxDepth, maxNodes); }
//Worker Interaction void MainUI::startSearch(){ ui->listWidget->clear(); stopSearch(); //just in case a search is still running if(ui->line_search->text().isEmpty()){ updateDefaultStatusTip(); return; } //nothing to search for //emit the proper signal for the worker if(!workthread->isRunning()){ workthread->start(); } //make sure the thread is running emit SearchTerm(ui->line_search->text(), ui->radio_apps->isChecked()); ui->tool_stop->setVisible(true); ui->tool_configure->setVisible(false); }
void TripPlanner::sendRequest() { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_1); out << quint16(0) << quint8('B') << busID << busName; out.device()->seek(0); // Go to beginning of block. out << quint16(block.size() - sizeof(quint16)); this->write(block); stopSearch(); }
void SearchLineEdit::resetSearch() { // Stop the currently running search, if any stopSearch(); // Clear highlights if ( m_id != -1 ) m_document->resetSearch( m_id ); // Make sure that the search will be reset at the next one m_changed = true; // Reset input box color prepareLineEditForSearch(); }
void Display::insert(string str){ //insert into search string for (int i = 0; i < str.length(); i++){ if (str[i] == 10){ //if enter key, proceed with search int index = buffer->searchF(searchWord.c_str(), searchPoint); if (index != -1){ //if search succeeded resultTrue = true; buffer->setPointA(index, false); } stopSearch(); displayResult = true; break;// not needed as 'enter' will always be the last in the string } else searchWord += str[i]; } }
MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI) { ui->setupUi(this); //load the designer file //setupIcons(); ui->radio_apps->setChecked(true); //always default to starting here ui->tool_stop->setVisible(false); //no search running initially ui->tool_configure->setVisible(false); //app search initially set livetime = new QTimer(this); livetime->setInterval(300); //1/3 second for live searches livetime->setSingleShot(true); workthread = new QThread(this); workthread->setObjectName("Lumina Search Process"); searcher = new Worker(); searcher->moveToThread(workthread); closeShort = new QShortcut(QKeySequence(tr("Esc")), this); //Setup the connections connect(livetime, SIGNAL(timeout()), this, SLOT(startSearch()) ); connect(this, SIGNAL(SearchTerm(QString, bool)), searcher, SLOT(StartSearch(QString, bool)) ); connect(searcher, SIGNAL(FoundItem(QString)), this, SLOT(foundSearchItem(QString)) ); connect(searcher, SIGNAL(SearchUpdate(QString)), this, SLOT(searchMessage(QString)) ); connect(searcher, SIGNAL(SearchDone()), this, SLOT(searchFinished()) ); connect(ui->tool_stop, SIGNAL(clicked()), this, SLOT(stopSearch()) ); connect(ui->push_done, SIGNAL(clicked()), this, SLOT(closeApplication()) ); connect(ui->push_launch, SIGNAL(clicked()), this, SLOT(LaunchItem()) ); connect(ui->line_search, SIGNAL(textEdited(QString)), this, SLOT(searchChanged()) ); connect(ui->line_search, SIGNAL(returnPressed()), this, SLOT(LaunchItem()) ); connect(ui->radio_apps, SIGNAL(toggled(bool)), this, SLOT(searchTypeChanged()) ); connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(LaunchItem(QListWidgetItem*)) ); connect(ui->listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(LaunchItem(QListWidgetItem*)) ); connect(ui->tool_configure, SIGNAL(clicked()), this, SLOT(configureSearch()) ); connect(closeShort, SIGNAL(activated()), this, SLOT( close() ) ); //Setup the settings file QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); settings = new QSettings("LuminaDE", "lumina-search",this); searcher->startDir = settings->value("StartSearchDir", QDir::homePath()).toString(); searcher->skipDirs = settings->value("SkipSearchDirs", QStringList()).toStringList(); updateDefaultStatusTip(); this->show(); workthread->start(); QTimer::singleShot(0,this, SLOT(setupIcons()) ); }
Kfind::Kfind(QWidget *parent, const char *name) : QWidget(parent, name) { kdDebug() << "Kfind::Kfind " << this << endl; QBoxLayout *mTopLayout = new QBoxLayout(this, QBoxLayout::LeftToRight, KDialog::marginHint(), KDialog::spacingHint()); // create tabwidget tabWidget = new KfindTabWidget(this); mTopLayout->addWidget(tabWidget); /* * This is ugly. Might be a KSeparator bug, but it makes a small black * pixel for me which is visually distracting (GS). // create separator KSeparator * mActionSep = new KSeparator( this ); mActionSep->setFocusPolicy( QWidget::ClickFocus ); mActionSep->setOrientation( QFrame::VLine ); mTopLayout->addWidget(mActionSep); */ // create button box QVBox *mButtonBox = new QVBox(this); QVBoxLayout *lay = (QVBoxLayout *)mButtonBox->layout(); lay->addStretch(1); mTopLayout->addWidget(mButtonBox); mSearch = new KPushButton(KGuiItem(i18n("&Find"), "find"), mButtonBox); mButtonBox->setSpacing((tabWidget->sizeHint().height() - 4 * mSearch->sizeHint().height()) / 4); connect(mSearch, SIGNAL(clicked()), this, SLOT(startSearch())); mStop = new KPushButton(KGuiItem(i18n("Stop"), "stop"), mButtonBox); connect(mStop, SIGNAL(clicked()), this, SLOT(stopSearch())); mSave = new KPushButton(KStdGuiItem::saveAs(), mButtonBox); connect(mSave, SIGNAL(clicked()), this, SLOT(saveResults())); KPushButton *mClose = new KPushButton(KStdGuiItem::close(), mButtonBox); connect(mClose, SIGNAL(clicked()), this, SIGNAL(destroyMe())); // react to search requests from widget connect(tabWidget, SIGNAL(startSearch()), this, SLOT(startSearch())); mSearch->setEnabled(true); // Enable "Search" mStop->setEnabled(false); // Disable "Stop" mSave->setEnabled(false); // Disable "Save..." dirlister = new KDirLister(); }
void Kfind::newSearch() { // re-init buffer if(iBuffer) iBuffer[0] = 0; // printf("Prepare for New Search\n"); win->hide(); // !!!!! win->clearList(); winsize=1; tabDialog->setDefaults(); emit enableStatusBar(false); emit haveResults(false); emit resultSelected(false); stopSearch(); tabDialog->endSearch(); };
TripPlanner::TripPlanner(QWidget *parent) : QDialog(parent) { setupUi(this); searchButton = buttonBox->addButton(tr("&Search"), QDialogButtonBox::ActionRole); stopButton = buttonBox->addButton(tr("S&top"), QDialogButtonBox::ActionRole); stopButton->setEnabled(false); buttonBox->button(QDialogButtonBox::Close)->setText(tr("&Quit")); QDateTime dateTime = QDateTime::currentDateTime(); dateEdit->setDate(dateTime.date()); timeEdit->setTime(QTime(dateTime.time().hour(), 0)); progressBar->hide(); progressBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored); tableWidget->verticalHeader()->hide(); tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(searchButton, SIGNAL(clicked()), this, SLOT(connectToServer())); connect(stopButton, SIGNAL(clicked()), this, SLOT(stopSearch())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(&tcpSocket, SIGNAL(connected()), this, SLOT(sendRequest())); connect(&tcpSocket, SIGNAL(disconnected()), this, SLOT(connectionClosedByServer())); connect(&tcpSocket, SIGNAL(readyRead()), this, SLOT(updateTableWidget())); connect(&tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error())); }
void OnlineSearchBioRxiv::bibTeXDownloadDone() { emit progress(++curStep, numSteps); QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (handleErrors(reply)) { /// ensure proper treatment of UTF-8 characters const QString bibTeXcode = QString::fromUtf8(reply->readAll().constData()); if (!bibTeXcode.isEmpty()) { FileImporterBibTeX importer; File *bibtexFile = importer.fromString(bibTeXcode); if (bibtexFile != NULL) { for (File::ConstIterator it = bibtexFile->constBegin(); it != bibtexFile->constEnd(); ++it) { QSharedPointer<Entry> entry = (*it).dynamicCast<Entry>(); publishEntry(entry); } delete bibtexFile; } else { qCWarning(LOG_KBIBTEX_NETWORKING) << "No valid BibTeX file results returned on request on" << reply->url().toDisplayString(); } } } if (d->resultPageUrls.isEmpty()) stopSearch(resultNoError); else { const QUrl firstUrl = *d->resultPageUrls.constBegin(); d->resultPageUrls.remove(firstUrl); QNetworkRequest request(firstUrl); QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request); InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply); connect(reply, &QNetworkReply::finished, this, &OnlineSearchBioRxiv::resultPageDone); } }
void StopSearchAction::actionTriggered(QAction *sender, bool) { auto search = qobject_cast<SearchWindow *>(sender->parentWidget()); if (search) search->stopSearch(); }
DocumentListModel::~DocumentListModel() { stopSearch(); }
void KfindTop::toolBarInit() { KIconLoader *loader = kapp->getIconLoader(); QPixmap icon; icon = loader->loadIcon("search.xpm"); _toolBar->insertButton( icon, 0, SIGNAL(clicked()), _kfind, SLOT(startSearch()), TRUE, i18n("Start Search")); icon = loader->loadIcon("reload.xpm"); _toolBar->insertButton( icon, 1, SIGNAL(clicked()), _kfind, SLOT(newSearch()), TRUE, i18n("New Search")); icon = loader->loadIcon("stop.xpm"); _toolBar->insertButton( icon, 2, SIGNAL(clicked()), _kfind, SLOT(stopSearch()), FALSE, i18n("Stop Search")); _toolBar->insertSeparator(); icon = loader->loadIcon("openfile.xpm"); _toolBar->insertButton( icon, 3,SIGNAL(clicked()), _kfind,SIGNAL(open()), FALSE, i18n("Open")); icon = loader->loadIcon("archive.xpm"); _toolBar->insertButton( icon, 4,SIGNAL(clicked()), _kfind,SIGNAL(addToArchive()), FALSE, i18n("Add to archive")); icon = loader->loadIcon("delete.xpm"); _toolBar->insertButton( icon, 5,SIGNAL(clicked()), _kfind,SIGNAL(deleteFile()), FALSE, i18n("Delete")); icon = loader->loadIcon("info.xpm"); _toolBar->insertButton( icon, 6,SIGNAL(clicked()), _kfind,SIGNAL(properties()), FALSE, i18n("Properties")); icon = loader->loadIcon("fileopen.xpm"); _toolBar->insertButton( icon, 7,SIGNAL(clicked()), _kfind,SIGNAL(openFolder()), FALSE, i18n("Open Containing Folder")); icon = loader->loadIcon("save.xpm"); _toolBar->insertButton( icon, 8,SIGNAL(clicked()), _kfind,SIGNAL(saveResults()), FALSE, i18n("Save Search Results")); _toolBar->insertSeparator(); icon = loader->loadIcon("contents.xpm"); _toolBar->insertButton( icon, 9, SIGNAL( clicked() ), kapp, SLOT( appHelpActivated() ), TRUE, i18n("Help")); icon = loader->loadIcon("exit.xpm"); _toolBar->insertButton( icon, 10, SIGNAL( clicked() ), KApplication::getKApplication(), SLOT( quit() ), TRUE, i18n("Quit")); };
PolkaView::PolkaView(QWidget *parent) : QWidget( parent ) { m_model = new PolkaModel( this ); connect( m_model, SIGNAL( dataWritten() ), SIGNAL( dataWritten() ) ); QBoxLayout *topLayout = new QVBoxLayout( this ); QBoxLayout *buttonLayout = new QHBoxLayout; topLayout->addLayout( buttonLayout ); // FIXME: Use proper icon m_backButton = new QPushButton( "<" ); buttonLayout->addWidget( m_backButton ); connect( m_backButton, SIGNAL( clicked() ), SLOT( goBack() ) ); m_backButton->setEnabled( false ); buttonLayout->addStretch( 1 ); m_groupNameLabel = new QLabel; buttonLayout->addWidget( m_groupNameLabel ); buttonLayout->addStretch( 1 ); m_searchEdit = new SearchEdit; buttonLayout->addWidget( m_searchEdit ); connect( m_searchEdit, SIGNAL( search( const QString & ) ), SLOT( showSearch( const QString & ) ) ); connect( m_searchEdit, SIGNAL( stopSearch() ), SLOT( stopSearch() ) ); QPushButton *button = new QPushButton( i18n("...") ); buttonLayout->addWidget( button ); connect( button, SIGNAL( clicked() ), SLOT( showOverview() ) ); button->setFocus(); QBoxLayout *viewLayout = new QHBoxLayout; topLayout->addLayout( viewLayout ); m_groupWidget = new QWidget; viewLayout->addWidget( m_groupWidget ); m_listLayout = new QStackedLayout( m_groupWidget ); m_overview = new Overview; m_listLayout->addWidget( m_overview ); connect( m_overview, SIGNAL( showGroupView() ), SLOT( showGroupView() ) ); connect( m_overview, SIGNAL( showListView() ), SLOT( showListView() ) ); connect( m_overview, SIGNAL( showHistory() ), SLOT( showHistory() ) ); m_groupListView = new GroupListView( m_model ); m_listLayout->addWidget( m_groupListView ); connectGroupView( m_groupListView ); m_groupGraphicsView = new GroupGraphicsView( m_model ); m_listLayout->addWidget( m_groupGraphicsView ); connectGroupView( m_groupGraphicsView ); connect( m_groupGraphicsView, SIGNAL( newGroup() ), SLOT( newSubGroup() ) ); connect( m_groupGraphicsView, SIGNAL( removeIdentity( const Polka::Identity &, const Polka::Identity & ) ), SLOT( removeIdentity( const Polka::Identity &, const Polka::Identity & ) ) ); connect( m_groupGraphicsView, SIGNAL( cloneGroup( const Polka::Identity & ) ), SLOT( cloneGroup( const Polka::Identity & ) ) ); connect( m_groupGraphicsView, SIGNAL( removeGroup( const Polka::Identity & ) ), SLOT( removeGroup( const Polka::Identity & ) ) ); connect( m_groupGraphicsView, SIGNAL( morphedToCompact() ), SLOT( finishShowPerson() ) ); connect( m_groupGraphicsView, SIGNAL( closeRequested() ), SLOT( closePersonView() ) ); m_personView = new PersonView( m_model ); viewLayout->addWidget( m_personView ); connect( m_personView, SIGNAL( closeRequested() ), SLOT( closePersonView() ) ); m_historyView = new HistoryView( m_model ); m_listLayout->addWidget( m_historyView ); m_searchResultView = new SearchResultView( m_model ); m_listLayout->addWidget( m_searchResultView ); m_settingsWidget = new SettingsWidget( m_model ); topLayout->addWidget( m_settingsWidget ); connect( m_settingsWidget, SIGNAL( showView() ), SLOT( showView() ) ); m_settingsWidget->hide(); readConfig(); readData(); }
int Engine::startSearch() { if (isVerbose()) { Rprintf("Starting...\n"); } double temQa; double visit, a, b; int itNew = 0, itDev; double s1, s, t1, t2, r, pqa, pqa1; bool inConstraint = false; bool eMini_NotChanged = true; double eMiniMarkov = 0; int indexNoEminiUpdate = 0; int indexTolEminiUpdate = 1000; dVec xMiniMarkov(x_.size()); if (getIsSimpleFunction()) { indexTolEminiUpdate = x_.size(); } // if (x_.size() <= 2) // { // indexTolEminiUpdate = 3; // } // else if (x_.size() > 2 && x_.size() <= 4) // { // indexTolEminiUpdate = 4 * x_.size(); // } // else if (x_.size() > 4 && x_.size() <= 10) // { // indexTolEminiUpdate = 4 * x_.size(); // } startTime_ = clock(); eMini_ = etot_; xMini_ = x_; etot0_ = etot_; if (isVerbose()) { Rprintf("first time, ind_trace is: %i\n", indTrace_); } // Initialize etot0 and temp if (!lsEnd_) { etot_ = lsEnergy(x_); if (etot_ < eMini_) { eMini_ = etot_; xMini_ = x_; } ++indTrace_; // Do the tracing here tracer_.addValue("currentEnergy", etot0_); tracer_.addValue("minEnergy", eMini_); tracer_.addValue("nSteps", itNew); tracer_.addValue("temperature", temSta_); } if (etot_ < eMini_) { eMini_ = etot_; xMini_ = x_; } etot0_ = etot_; tem_ = temSta_; if (isVerbose()) { Rprintf("The transformed xinitial x: \n"); printVect(x_); Rprintf("The energy of transformed initial x = %.10g\n", etot_); } if (isVerbose()) { Rprintf("At the beginning, etot0= %.10g\n", etot0_); Rprintf("Emini= %.10g\n", eMini_); Rprintf("Current x: "); printVect(x_); Rprintf("Current xmini: "); printVect(xMini_); } if (checkStoping()) { stopSearch(); return 0; } if (isVerbose()) { Rprintf("Number of function call: %i\n", nbFctCall_); } int stepRecord = 0; L2435: // Main loop for (int i = 0; i < maxStep_; ++i) { itNew = i + 1; s1 = (double) itNew; s = s1 + 1.; t1 = exp((qv_ - 1.) * log(2.)) - 1.; t2 = exp((qv_ - 1.) * log(s)) - 1.; tem_ = temSta_ * t1 / t2; stepRecord += 1; if (stepRecord == maxStep_) { break; } if (tem_ < temRestart_) { //printf("*\n"); goto L2435; } temQa = tem_ / (double) itNew; indexNoEminiUpdate++; // Markov loop for (unsigned int j = 0; j < (unsigned) markovLength_; ++j) { if (j == 0) { eMini_NotChanged = true; } if (j == 0 && i == 0) { eMini_NotChanged = false; } xBackup_ = x_; inConstraint = false; while (!inConstraint) { // Loop on coordinates if (j < x_.size()) { for (unsigned int k = 0; k < x_.size(); ++k) { if (isVerbose()) { Rprintf("IDUM before visit: %d\n", idum_); } visit = visita(&qv_, &tem_, &idum_); if (visit > 1.e8) { visit = 1.e8 * Utils::ran2(&idum_); } else if (visit < -1.e8) { visit = -1.e8 * Utils::ran2(&idum_); } x_[k] = visit + xBackup_[k]; a = x_[k] - lower_[k]; b = Utils::dMod(&a, &xRange_[k]) + xRange_[k]; x_[k] = Utils::dMod(&b, &xRange_[k]) + lower_[k]; if (fabs(x_[k] - lower_[k]) < 1.e-10) { x_[k] += 1.e-10; } if (isVerbose()) { Rprintf( "visit: %.10g a: %.10g b: %.10g idum: %d x: %.10g\n", visit, a, b, idum_, x_[k]); } } // end coordinates loop } else { // Now change only one component at a time visit = visita(&qv_, &tem_, &idum_); if (visit > 1.e8) { visit = 1.e8 * Utils::ran2(&idum_); } else if (visit < -1.e8) { visit = -1.e8 * Utils::ran2(&idum_); } int index = j - x_.size(); x_[index] = visit + xBackup_[index]; a = x_[index] - lower_[index]; b = Utils::dMod(&a, &xRange_[index]) + xRange_[index]; x_[index] = Utils::dMod(&b, &xRange_[index]) + lower_[index]; if (fabs(x_[index] - lower_[index]) < 1.e-10) { x_[index] += 1.e-10; } } if (isVerbose()) { Rprintf("\ntem: %.10g temqa: %.10g itnew: %d markov j=%d\n", tem_, temQa, itNew, j); Rprintf("fx are: "); printVect(xBackup_); Rprintf("x are: "); printVect(x_); } if (hasConstraint_) { inConstraint = judgeConstraint(); } else { inConstraint = true; } if (inConstraint) { if (lsEnd_) { if (isVerbose()) { Rprintf("Calling energy\n"); } energy(x_); } else { if (isVerbose()) { Rprintf("Calling lsEnergy\n"); } etot_ = lsEnergy(x_); } if (isVerbose()) { Rprintf("Before judge, etot0= %.10g etot= %.10g\n", etot0_, etot_); } if (etot_ < etot0_) { etot0_ = etot_; if (isVerbose()) { Rprintf("etot is smaller than etot0\n"); } if (etot_ < eMini_) { eMini_ = etot_; xMini_ = x_; eMini_NotChanged = false; indexNoEminiUpdate = 0; } } else { r = Utils::ran2(&idum_); pqa1 = (qa_ - 1.) * (etot_ - etot0_) / temQa + 1.; /* write(*,*)' etot0=',etot0,', etot=',etot,', pqa1=',pqa1 ! r */ if (pqa1 < 0.) { pqa = 0.; } else { pqa = exp(log(pqa1) / (1. - qa_)); } if (isVerbose()) { Rprintf("pqa= %.10g r= %.10g \n", pqa, r); } if (r > pqa) { x_ = xBackup_; } else { etot0_ = etot_; } } // endif etot_ < eMini_ tracer_.addValue("currentEnergy", etot0_); tracer_.addValue("minEnergy", eMini_); tracer_.addValue("nSteps", itNew); tracer_.addValue("temperature", tem_); if (checkStoping()) { stopSearch(); return 0; } } // end else hasConstraint } // end while !inconstraint if (indexNoEminiUpdate >= indexTolEminiUpdate - 1) { if (j == 0) { eMiniMarkov = etot0_; std::copy(x_.begin(), x_.end(), xMiniMarkov.begin()); } else { if (etot0_ < eMiniMarkov) { eMiniMarkov = etot0_; std::copy(x_.begin(), x_.end(), xMiniMarkov.begin()); } } } } // end markov chain loop if (lsEnd_) { if (!eMini_NotChanged) { dVec temp(x_.size()); std::copy(xMini_.begin(), xMini_.end(), temp.begin()); //Rprintf("Xmini:\n"); //printVect(xMini_); // if (isUserVerbose()) // { // Rprintf("Before lsEnergy, itNew: %d eTemp: %.15g x: %.15g %15g\n", itNew, eMini_, temp[0], temp[1]); // } double eTemp = lsEnergy(temp); // if (isUserVerbose()) // { // Rprintf("lsEnergy called, itNew: %d eTemp: %.15g x: %.15g %.15g\n", itNew, eTemp, temp[0], temp[1]); // } if (eTemp < eMini_) { if (isUserVerbose()) { Rprintf("It: %d, obj value: %.10g\n", itNew, eTemp); } std::copy(temp.begin(), temp.end(), xMini_.begin()); eMini_ = eTemp; indexNoEminiUpdate = 0; tracer_.updateLastValue("currentEnergy", etot0_); tracer_.updateLastValue("minEnergy", eMini_); tracer_.updateLastValue("nSteps", itNew); tracer_.updateLastValue("temperature", tem_); } } if (indexNoEminiUpdate >= indexTolEminiUpdate) { //Rprintf("Before lsEnergy, itNew: %d x: %.15g %.15g\n", itNew, xMiniMarkov[0], xMiniMarkov[1]); eMiniMarkov = lsEnergy(xMiniMarkov); //Rprintf("lsEnergy called, itNew: %d eMiniMarkov: %.15g x: %.15g %.15g\n", itNew, eMiniMarkov, xMiniMarkov[0], xMiniMarkov[1]); if (isUserVerbose()) { Rprintf("."); } indexNoEminiUpdate = 0; indexTolEminiUpdate = x_.size(); if (eMiniMarkov < eMini_) { std::copy(xMiniMarkov.begin(), xMiniMarkov.end(), xMini_.begin()); eMini_ = eMiniMarkov; tracer_.updateLastValue("currentEnergy", etot0_); tracer_.updateLastValue("minEnergy", eMini_); tracer_.updateLastValue("nSteps", itNew); tracer_.updateLastValue("temperature", tem_); if (isUserVerbose()) { Rprintf("\nIt: %d, obj value: %.10g\n", itNew, eMini_); } if (checkStoping()) { stopSearch(); return 0; } } } } itDev = itNew % interval_; if (0 == itDev) { if (isVerbose()) { Rprintf(">After one search %d %.10g %.10g %.10g <-- Emini\n", itNew, tem_, etot0_, eMini_); Rprintf("Current x: "); printVect(x_); Rprintf("\nCurrent xmini: "); printVect(xMini_); Rprintf( "\n__________________________________________________\n"); } } } // end step loop stopSearch(); return 0; }
void TripPlanner::sendRequest() { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_1); qDebug() << "Bus Name is " << busName; // Bus has arrived at a station - Check if last station if (floor(station) != floor(lastStation)) { bool reached = false; int arrivedStation = (int) station; qDebug() << "Bus has arrived at station" << station; if (station != 0.0) { if (busName.startsWith("A1") && arrivedStation == ROUTE_A1 - 1) reached = true; else if (busName.startsWith("A2") && arrivedStation == ROUTE_A2 - 1) reached = true; else if (busName.startsWith("B") && arrivedStation == ROUTE_B - 1) reached = true; else if (busName.startsWith("C") && arrivedStation == ROUTE_C - 1) reached = true; else if (busName.startsWith("D1") && arrivedStation == ROUTE_D1 - 1) reached = true; else if (busName.startsWith("D2") && arrivedStation == ROUTE_D2 - 1) reached = true; } // Reached last station if (reached == true) { qDebug() << "Bus arrived at last station"; finished = true; peopleGettingOff = BUS_SPACE - space; out << quint16(0) << quint8('E') << busID << busName << station << peopleGettingOff << space; out.device()->seek(0); // Go to beginning of block. out << quint16(block.size() - sizeof(quint16)); this->write(block); stopSearch(); } // Not reached last station else { if (space != BUS_SPACE) peopleGettingOff = qrand() % (BUS_SPACE - space); peopleGettingOn = stationRemove(station,busName,space); // Decrement space on bus space = space - peopleGettingOn; space = space + peopleGettingOff; qDebug() << "space = " << space; //statusLabel->setText(tr("Sending request...")); qDebug() << "Sending request..."; qDebug() << "Message is " << quint16(0) << quint8('B') << busID << busName << station << peopleGettingOff << space; out << quint16(0) << quint8('B') << busID << busName << station << peopleGettingOff << space; out.device()->seek(0); // Go to beginning of block. out << quint16(block.size() - sizeof(quint16)); this->write(block); } } // Bus has not arrived at a station yet else { peopleGettingOn = 0; peopleGettingOff = 0; qDebug() << "Bus is not at a station, currently at " << station; out << quint16(0) << quint8('N') << busID << busName << station << peopleGettingOff << space; out.device()->seek(0); // Go to beginning of block. out << quint16(block.size() - sizeof(quint16)); this->write(block); } // Store lastStation (to check if the bus is at a new station) lastStation = station; // Increment station station = station + BUS_INCREMENT; stopSearch(); }
void KfindTop::menuInit() { KStdAccel stdAccel; _fileMenu = new QPopupMenu; _editMenu = new QPopupMenu; _optionMenu = new QPopupMenu; _helpMenu = new QPopupMenu; fileStart = _fileMenu->insertItem(i18n("&Start search"), _kfind, SLOT(startSearch()), stdAccel.find()); fileStop = _fileMenu->insertItem(i18n("S&top search"), _kfind, SLOT(stopSearch()), Key_Escape); _fileMenu->setItemEnabled(fileStop, FALSE); _fileMenu->insertSeparator(); openWithM = _fileMenu->insertItem(i18n("&Open"), this,SIGNAL(open()), stdAccel.open()); toArchM = _fileMenu->insertItem(i18n("&Add to archive"), this,SIGNAL(addToArchive())); _fileMenu ->insertSeparator(); deleteM = _fileMenu->insertItem(i18n("&Delete"), this,SIGNAL(deleteFile())); propsM = _fileMenu->insertItem(i18n("&Properties"), this,SIGNAL(properties())); _fileMenu ->insertSeparator(); openFldrM = _fileMenu->insertItem(i18n("Open Containing &Folder"), this,SIGNAL(openFolder())); _fileMenu ->insertSeparator(); saveSearchM= _fileMenu->insertItem(i18n("&Save Search"), this,SIGNAL(saveResults()),stdAccel.save()); _fileMenu ->insertSeparator(); quitM = _fileMenu->insertItem(i18n("&Quit"),qApp, SLOT(quit()),stdAccel.quit()); for(int i=openWithM;i>quitM;i--) _fileMenu->setItemEnabled(i,FALSE); int undo = _editMenu->insertItem(i18n("&Undo"), this, SIGNAL(undo()), stdAccel.undo() ); _editMenu ->insertSeparator(); int cut = _editMenu->insertItem(i18n("&Cut"), this, SIGNAL(cut()), stdAccel.cut() ); editCopy = _editMenu->insertItem(i18n("&Copy"), this, SLOT(copySelection()), stdAccel.copy() ); _editMenu->insertSeparator(); editSelectAll = _editMenu->insertItem(i18n("&Select All"), this,SIGNAL(selectAll()) ); editUnselectAll = _editMenu->insertItem(i18n("Unse&lect All"), this,SIGNAL(unselectAll()) ); editInvertSelection = _editMenu->insertItem(i18n("&Invert Selection"), this,SIGNAL(invertSelection()) ); _editMenu->setItemEnabled( undo , FALSE ); _editMenu->setItemEnabled( cut , FALSE ); _editMenu->setItemEnabled( editCopy , FALSE ); _editMenu->setItemEnabled( editSelectAll, FALSE ); _editMenu->setItemEnabled( editUnselectAll, FALSE ); _editMenu->setItemEnabled( editInvertSelection, FALSE ); CHECK_PTR( _optionMenu ); _optionMenu->insertItem(i18n("&Preferences ..."), this,SLOT(prefs())); //_optionMenu->insertItem("Configure key bindings",this,SIGNAL(keys())); QString tmp; tmp.sprintf(i18n("KFind %s\nFrontend to find utility\nMiroslav FlĂdr <*****@*****.**>\n\nSpecial thanks to Stephan Kulow\n<*****@*****.**>"), KFIND_VERSION); _helpMenu=kapp->getHelpMenu( true, tmp ); _mainMenu = new KMenuBar(this, "_mainMenu"); _mainMenu->insertItem( i18n("&File"), _fileMenu); _mainMenu->insertItem( i18n("&Edit"), _editMenu); _mainMenu->insertItem( i18n("&Options"), _optionMenu); _mainMenu->insertSeparator(); _mainMenu->insertItem( i18n("&Help"), _helpMenu ); };