void FdmArithmeticAverageCondition::applyTo(Array& a, Time t) const { const std::vector<Time>::const_iterator iter = std::find(averageTimes_.begin(), averageTimes_.end(), t); const Size nTimes = std::count(averageTimes_.begin(), averageTimes_.end(), t); if (nTimes > 0) { Array aCopy(a); const Size iT = iter - averageTimes_.begin() + 1 + pastFixings_; const Size averageDirection = equityDirection_ == 0 ? 1 : 0; const Size xSpacing = mesher_->layout()->spacing()[equityDirection_]; const Size aSpacing = mesher_->layout()->spacing()[averageDirection]; Array tmp(a_.size()); for (Size i=0; i<x_.size(); ++i) { for (Size j=0; j<a_.size(); ++j) { Size index = i*xSpacing + j*aSpacing; tmp[j] = aCopy[index]; } MonotonicCubicNaturalSpline interp(a_.begin(), a_.end(), tmp.begin()); for (Size j=0; j<a_.size(); ++j) { Size index = i*xSpacing + j*aSpacing; a[index] = interp((iT-nTimes)/(double)(iT)*a_[j] + nTimes/(double)(iT)*x_[i], true); } } } }
std::vector<Image> Image::copies(int num) { std::vector<Image> clones; for(int i=0; i<num; i++) { Image aCopy( img ); clones.push_back( aCopy ); } return clones; }
void FdmDividendHandler::applyTo(Array& a, Time t) const { Array aCopy(a); std::vector<Time>::const_iterator iter = std::find(dividendTimes_.begin(), dividendTimes_.end(), t); if (iter != dividendTimes_.end()) { const Real dividend = dividends_[iter - dividendTimes_.begin()]; if (mesher_->layout()->dim().size() == 1) { LinearInterpolation interp(x_.begin(), x_.end(), aCopy.begin()); for (Size k=0; k<x_.size(); ++k) { a[k] = interp(std::max(x_[0], x_[k]-dividend), true); } } else { Array tmp(x_.size()); Size xSpacing = mesher_->layout()->spacing()[equityDirection_]; for (Size i=0; i<mesher_->layout()->dim().size(); ++i) { if (i!=equityDirection_) { Size ySpacing = mesher_->layout()->spacing()[i]; for (Size j=0; j<mesher_->layout()->dim()[i]; ++j) { for (Size k=0; k<x_.size(); ++k) { Size index = j*ySpacing + k*xSpacing; tmp[k] = aCopy[index]; } LinearInterpolation interp(x_.begin(), x_.end(), tmp.begin()); for (Size k=0; k<x_.size(); ++k) { Size index = j*ySpacing + k*xSpacing; a[index] = interp( std::max(x_[0], x_[k]-dividend), true); } } } } } } }
RouteView::RouteView(QObject* parent ) { m_parent = parent; config = Configuration::instance(); //sql.setConfig(config); //headers << "" << "Item" << "Name" << "1 way" << "Next" << "Prev" << "Dir" << "Seq" << "RSeq" << "StartDate" << "EndDate"; mainWindow* myParent = qobject_cast<mainWindow*>(m_parent); ui = myParent->ui->tblRouteView; connect(ui->verticalHeader(), SIGNAL(sectionCountChanged(int,int)), this, SLOT(Resize(int,int))); //ui->setColumnCount(headers.count()); //ui->setHorizontalHeaderLabels(headers); ui->resizeColumnsToContents(); ui->setAlternatingRowColors(true); ui->setColumnWidth(0,25); //m_myParent = myParent; ui->setSelectionBehavior(QAbstractItemView::SelectRows ); ui->setSelectionMode( QAbstractItemView::SingleSelection ); //create contextmenu copyAction = new QAction(tr("&Copy"), this); copyAction->setStatusTip(tr("Copy Table Location")); copyAction->setShortcut(tr("Ctrl+C")); connect(copyAction, SIGNAL(triggered()), this, SLOT(aCopy())); pasteAction = new QAction(tr("&Paste"), this); pasteAction->setStatusTip(tr("Paste")); pasteAction->setShortcut(tr("Ctrl+V")); connect(pasteAction, SIGNAL(triggered()), this, SLOT(aPaste())); reSequenceAction = new QAction(tr("&Start route here"), this); reSequenceAction->setStatusTip(tr("Start route at this segment")); reSequenceAction->setShortcut(tr("Alt_Ctrl+S")); connect(reSequenceAction, SIGNAL(triggered()), this, SLOT(reSequenceRoute())); startTerminalStartAct = new QAction(tr("Start at start"), this); startTerminalStartAct->setStatusTip(tr("Start terminal is at start of segment")); connect(startTerminalStartAct, SIGNAL(triggered()), this, SLOT(StartRoute_S())); startTerminalEndAct = new QAction(tr("Start at end"), this); startTerminalEndAct->setStatusTip(tr("Start terminal is at end of segment")); connect(startTerminalEndAct, SIGNAL(triggered()), this, SLOT(StartRoute_E())); endTerminalStartAct = new QAction(tr("End terminal at start"), this); endTerminalStartAct->setStatusTip(tr("End terminal is at start of segment")); connect(endTerminalStartAct, SIGNAL(triggered()), this, SLOT(EndRoute_S())); endTerminalEndAct = new QAction(tr("End terminal at end"), this); endTerminalEndAct->setStatusTip(tr("End terminal is at end of segment")); connect(endTerminalEndAct,SIGNAL(triggered()), this, SLOT(EndRoute_E())); deleteSegmentAct = new QAction(tr("Remove from route"), this); deleteSegmentAct->setStatusTip(tr("Delete the segment from the route")); connect(deleteSegmentAct, SIGNAL(triggered()), this, SLOT(deleteSegment())); unDeleteSegmentAct = new QAction(tr("Undo delete of segment"), this); unDeleteSegmentAct->setStatusTip(tr("Don't delete the segment from the route")); connect(unDeleteSegmentAct, SIGNAL(triggered()), this, SLOT(unDeleteSegment())); selectSegmentAct = new QAction(tr("Select segment"),this); selectSegmentAct->setToolTip(tr("Select segment on map.")); connect(selectSegmentAct, SIGNAL(triggered()), this, SLOT(on_selectSegment_triggered())); editSegmentAct = new QAction(tr("Edit segment"), this); editSegmentAct->setStatusTip(tr("Edit this segment's properties")); connect(editSegmentAct, SIGNAL(triggered(bool)), this, SLOT(editSegment())); ui->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui, SIGNAL(customContextMenuRequested( const QPoint& )), this, SLOT(tablev_customContextMenu( const QPoint& ))); sourceModel = new RouteViewTableModel(route, name, QDate::fromString(startDate, "yyyy/MM/dd"), QDate::fromString(endDate, "yyyy/MM/dd"), segmentInfoList); saveChangesAct = new QAction(tr("Commit changes"),this); saveChangesAct->setStatusTip(tr("Save any uncommitted changes")); //connect(saveChangesAct, SIGNAL(triggered()), sourceModel, SLOT(commitChanges())); connect(saveChangesAct, SIGNAL(triggered(bool)), this, SLOT(commitChanges())); myParent->proxyModel = proxymodel = new RouteViewSortProxyModel(this); myParent->proxyModel->setSourceModel(sourceModel); ui->setModel(myParent->proxyModel); connect(this, SIGNAL(sendRows(int, int)), sourceModel, SLOT(getRows(int,int))); //connect(ui, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(itemChanged(QTableWidgetItem*))); //connect(ui, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(handleSelectionChanged(QTableWidgetItem *))); connect(ui, SIGNAL(clicked(QModelIndex)), this, SLOT(itemSelectionChanged(QModelIndex))); connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), ui, SLOT(dataChanged(QModelIndex,QModelIndex))); //connect(myParent->saveChangesAct, SIGNAL(triggered()), sourceModel, SLOT(commitChanges())); connect(webViewBridge::instance(), SIGNAL(segmentSelected(qint32,qint32)), this, SLOT(on_segmentSelected(int,int))); myParent->ui->tabWidget->setTabText(0, "Route Segments"); startTerminal = NULL; startSegment = -1; endSegment = -1; }
lab1_4::LamVec* lab1_4::system::getResult() { LamVec *str = new LamVec; std::vector<double> *res = new std::vector<double>(this->size, 0); std::vector<std::vector<std::vector<double> >*> vecU; double exz = 1000; std::vector<std::vector<double> > aNew((*(this->a))); while (exz > this->eps) { std::vector<std::vector<double> > aCopy(aNew); std::vector<std::vector<double> > *u = new std::vector<std::vector<double> >(this->size, std::vector<double>(size, 0)); for (int i = 0; i < this->size; ++i) (*(u))[i][i] = 1; double max = aCopy[0][1]; int iMax = 0; int jMax = 1; for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { if (i == j) continue; if (max < fabs(aCopy[i][j])) { max = fabs(aCopy[i][j]); iMax = i; jMax = j; } } } (*(u))[iMax][jMax] = -sin(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax]))); (*(u))[jMax][iMax] = sin(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax]))); (*(u))[iMax][iMax] = cos(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax]))); (*(u))[jMax][jMax] = cos(0.5 * atan(2 * aCopy[iMax][jMax] / (aCopy[iMax][iMax] - aCopy[jMax][jMax]))); /*for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { std::cout << (*(u))[i][j] << " "; } std::cout << "\n"; } std::cout << iMax << " " << jMax << "\n";*/ std::vector<std::vector<double> > tmpA(aCopy); for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { double tmp = 0; for (int z = 0; z < this->size; ++z) { tmp += (*(u))[z][i] * aCopy[z][j]; } tmpA[i][j] = tmp; } } for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { double tmp = 0; for (int z = 0; z < this->size; ++z) { tmp += tmpA[i][z] * (*(u))[z][j]; } aNew[i][j] = tmp; } } exz = 0; for (int i = 0; i < this->size; ++i) { for (int j = 0; j < i; ++j) { exz += pow(aNew[i][j], 2); } } exz = pow(exz, 0.5); std::cout << exz << " -exz\n"; /*for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { std::cout << aNew[i][j] << " "; } std::cout << "\n"; } std::cout << "\n"; std::cout << "=============\n"; std::cout << "\n"; _sleep(1000);*/ vecU.push_back(u); } str->vec = new std::vector<std::vector<double> >((*(vecU[0]))); for (int k = 1; k < vecU.size(); ++k) { std::vector<std::vector<double> > tmpV((*(str->vec))); for (int i = 0; i < this->size; ++i) { for (int j = 0; j < this->size; ++j) { double tmp = 0; for (int z = 0; z < this->size; ++z) { tmp += tmpV[i][z] * (*(vecU[k]))[z][j]; } (*(str->vec))[i][j] = tmp; } } } for (int i = 0; i < vecU.size(); ++i) { delete vecU[i]; } for (int i = 0; i < this->size; ++i) { (*(res))[i] = aNew[i][i]; } str->lambda = res; return str; }