void AutoMatrix::removeRow ( const size_t row ) { const size_t rows = countRows(), cols = countColumns(); for ( size_t i = row + 1; i < rows; ++i ) { const Vector rowSource = rowVector( i ); Vector rowTarget = rowVector( i - 1 ); rowTarget.copy( rowSource ); } upSize( rows - 1, cols ); }
void SPxSolver::qualSlackViolation(Real& maxviol, Real& sumviol) const { maxviol = 0.0; sumviol = 0.0; DVector solu( nCols() ); DVector slacks( nRows() ); getPrimal( solu ); getSlacks( slacks ); for( int row = 0; row < nRows(); ++row ) { const SVector& rowvec = rowVector( row ); Real val = 0.0; for( int col = 0; col < rowvec.size(); ++col ) val += rowvec.value( col ) * solu[rowvec.index( col )]; Real viol = spxAbs(val - slacks[row]); if (viol > maxviol) maxviol = viol; sumviol += viol; } }
void SPxSolver::qualConstraintViolation(Real& maxviol, Real& sumviol) const { maxviol = 0.0; sumviol = 0.0; DVector solu( nCols() ); getPrimal( solu ); for( int row = 0; row < nRows(); ++row ) { const SVector& rowvec = rowVector( row ); Real val = 0.0; for( int col = 0; col < rowvec.size(); ++col ) val += rowvec.value( col ) * solu[rowvec.index( col )]; Real viol = 0.0; assert(lhs( row ) <= rhs( row )); if (val < lhs( row )) viol = spxAbs(val - lhs( row )); else if (val > rhs( row )) viol = spxAbs(val - rhs( row )); if (viol > maxviol) maxviol = viol; sumviol += viol; } }
Vector AutoMatrix::newRow () { const size_t row = countRows(); upSize( row + 1, countColumns() ); return rowVector( row ); }
/* method that checks if the save file already exists, * if not it will create it else it will read it out * and fill the array */ void Levels::getLevelAmount() { QString path = QDir::currentPath() + "/levels.txt"; QFile * newFile = new QFile(path); QFile * file = new QFile(":/assets/Levels/levels.txt"); QTextStream stream(newFile); QString line; QStringList list; /* boolean gets set if the newFile already exists*/ bool fileExists = newFile->exists(); vector <int> rowVector(2); int row = 0; if(!file->open(QIODevice::ReadOnly| QIODevice::Text)) { qDebug()<< "error opening levels"; return; } if(newFile->open(QIODevice::ReadWrite | QIODevice::Text)) { /*write all the content of file in newFile*/ if(!fileExists){ QTextStream in(file); QString leaderPath; while (!in.atEnd()) { line = in.readLine(); stream << line; stream << endl; row++; /* create leaderboard file for each level */ leaderPath= QDir::currentPath() + "/leaderboard"+QString::number(row)+ ".txt"; QFile * leaderBoard = new QFile(leaderPath); /* opening a file that doesn't exist yet will creat this file */ if(!leaderBoard->open(QIODevice::ReadWrite| QIODevice::Text)) { qDebug()<< leaderBoard->errorString(); return; } leaderBoard->close(); } } stream.seek(0); row = 0; /*add the content of newFile to the levelArray*/ while (!stream.atEnd()) { line = stream.readLine(); if (!line.isEmpty()&&!line.isNull()){ list=line.split(" "); levelArray.push_back(rowVector); for(int col = 0; col < 2; col++){ levelArray[row][col] = list.at(col).toInt(); } row++; } } } amountOfLevels = row; file->close(); newFile->close(); }