SPxId SPxFastRT::minDelta( int& nr, Real& max, Real& maxabs) { /* The following cause side effects on coPvec and pVec - both changes may be needed later in minSelect(). We can therefore not move the first function after the (indp >= 0) check. */ iscoid = true; const int indc = minDelta(max, maxabs, thesolver->coPvec(), thesolver->lcBound(), thesolver->ucBound(), 0, 1); iscoid = false; const int indp = minDelta(max, maxabs, thesolver->pVec(), thesolver->lpBound(), thesolver->upBound(), 0, 1); if (indp >= 0) { nr = indp; return thesolver->id(indp); } if (indc >= 0) { nr = indc; return thesolver->coId(indc); } nr = -1; return SPxId(); }
int SPxFastRT::minDelta( Real& val, Real& maxabs) { return minDelta(val, maxabs, thesolver->fVec(), thesolver->lbBound(), thesolver->ubBound(), 0, 1); }
int Perseus::getTrimera(vector<seqData>& sequences, vector<vector<int> >& leftDiffs, int& leftParent, int& middleParent, int& rightParent, int& breakPointA, int& breakPointB, vector<int>& singleLeft, vector<int>& bestLeft, vector<int>& singleRight, vector<int>& bestRight, vector<bool> restricted){ try { int numRefSeqs = leftDiffs.size(); int alignLength = leftDiffs[0].size(); int bestTrimeraMismatches = PERSEUSMAXINT; leftParent = -1; middleParent = -1; rightParent = -1; breakPointA = -1; breakPointB = -1; vector<vector<int> > minDelta(alignLength); vector<vector<int> > minDeltaSeq(alignLength); for(int i=0;i<alignLength;i++){ if (m->getControl_pressed()) { return 0; } minDelta[i].assign(alignLength, PERSEUSMAXINT); minDeltaSeq[i].assign(alignLength, -1); } for(int x=0;x<alignLength;x++){ for(int y=x;y<alignLength-1;y++){ for(int i=0;i<numRefSeqs;i++){ if (m->getControl_pressed()) { return 0; } if(!restricted[i]){ int delta = leftDiffs[i][y] - leftDiffs[i][x]; if(delta < minDelta[x][y] || (delta == minDelta[x][y] && sequences[i].frequency > sequences[minDeltaSeq[x][y]].frequency)){ minDelta[x][y] = delta; minDeltaSeq[x][y] = i; } } } minDelta[x][y] += singleLeft[x] + singleRight[alignLength - y - 2]; if(minDelta[x][y] < bestTrimeraMismatches){ bestTrimeraMismatches = minDelta[x][y]; breakPointA = x; breakPointB = y; leftParent = bestLeft[x]; middleParent = minDeltaSeq[x][y]; rightParent = bestRight[alignLength - y - 2]; } } } return bestTrimeraMismatches; } catch(exception& e) { m->errorOut(e, "Perseus", "getTrimera"); exit(1); } }
int SPxFastRT::selectLeave(Real& val, SPxId) { Real maxabs, max, sel; int leave = -1; int cnt = 0; assert( m_type == SPxSolver::ENTER ); resetTols(); if (val > epsilon) { do { // phase 1: max = val; maxabs = 0.0; leave = maxDelta(max, maxabs); if (max == val) return -1; if (!maxShortLeave(sel, leave, maxabs)) { // phase 2: Real stab, bestDelta; stab = 100.0 * minStability(maxabs); leave = maxSelect(sel, stab, bestDelta, max); if (bestDelta < DELTA_SHIFT*TRIES) cnt++; else cnt += TRIES; } if (!maxReLeave(sel, leave, maxabs)) break; relax(); } while (cnt < TRIES); } else if (val < -epsilon) { do { max = val; maxabs = 0; leave = minDelta(max, maxabs); if (max == val) return -1; /**@todo Here is a ; above is none. * In a first try the version with the ; runs better. * minShortLeave changes sel. Have a look what happens * if we drop the if above also. * @todo Check whether minShortLeave() should be called at all. */ // if (! minShortLeave(sel, leave, maxabs); // ); { // phase 2: Real stab, bestDelta; stab = 100.0 * minStability(maxabs); leave = minSelect(sel, stab, bestDelta, max); if (bestDelta < DELTA_SHIFT*TRIES) cnt++; else cnt += TRIES; } if (!minReLeave(sel, leave, maxabs)) break; relax(); } while (cnt < TRIES); } else return -1; MSG_DEBUG( if (leave >= 0) spxout << "DFSTRT01 " << thesolver->basis().iteration() << "(" << std::setprecision(6) << thesolver->value() << "," << std::setprecision(2) << thesolver->basis().stability() << "):" << leave << "\t" << std::setprecision(4) << sel << " " << std::setprecision(4) << thesolver->fVec().delta()[leave] << " " << std::setprecision(6) << maxabs << std::endl; else spxout << "DFSTRT02 " << thesolver->basis().iteration() << ": skipping instable pivot" << std::endl; ) if (leave >= 0 || minStab > 2*solver()->epsilon())
/** Here comes our implementation of the Harris procedure improved by shifting bounds. The basic idea is to used the tolerated infeasibility within solver()->entertol() for searching numerically stable pivots. The algorithms operates in two phases. In a first phase, the maximum \p val is determined, when infeasibility within solver()->entertol() is allowed. In the second phase, between all variables with values < \p val the one is selected which gives the best step forward in the simplex iteration. However, this may not allways yield an improvement. In that case, we shift the variable toward infeasibility and retry. This avoids cycling in the shifted LP. */ int SPxHarrisRT::selectLeave(Real& val, SPxId enterId) { int i, j; Real stab, x, y; Real max; Real sel; Real lastshift; Real useeps; int leave = -1; Real maxabs = 1; Real epsilon = solver()->epsilon(); Real degeneps = degenerateEps(); SSVector& upd = solver()->fVec().delta(); Vector& vec = solver()->fVec(); const Vector& up = solver()->ubBound(); const Vector& low = solver()->lbBound(); assert(delta > epsilon); assert(epsilon > 0); assert(solver()->maxCycle() > 0); max = val; lastshift = solver()->shift(); solver()->fVec().delta().setup(); if (max > epsilon) { // phase 1: maxDelta( &maxabs, /* max abs value in upd */ &max, /* initial and chosen value */ upd.size(), /* # of indices in upd */ upd.indexMem(), /* nonzero indices in upd */ upd.values(), /* update vector for vec */ vec.get_const_ptr(), /* current vector */ low.get_const_ptr(), /* lower bounds for vec */ up.get_const_ptr(), /* upper bounds for vec */ epsilon); /* what is 0? */ if (max == val) return -1; // phase 2: stab = 0; sel = -infinity; useeps = maxabs * epsilon * 0.001; if (useeps < epsilon) useeps = epsilon; for (j = upd.size() - 1; j >= 0; --j) { i = upd.index(j); x = upd[i]; if (x > useeps) { y = up[i] - vec[i]; if (y < -degeneps) solver()->shiftUBbound(i, vec[i]); // ensure simplex improvement else { y /= x; if (y <= max && y > sel - epsilon && x > stab) { sel = y; leave = i; stab = x; } } } else if (x < -useeps) { y = low[i] - vec[i]; if (y > degeneps) solver()->shiftLBbound(i, vec[i]); // ensure simplex improvement else { y /= x; if (y <= max && y > sel - epsilon && -x > stab) { sel = y; leave = i; stab = -x; } } } else upd.clearNum(j); } } else if (max < -epsilon) { // phase 1: minDelta( &maxabs, /* max abs value in upd */ &max, /* initial and chosen value */ upd.size(), /* # of indices in upd */ upd.indexMem(), /* nonzero indices in upd */ upd.values(), /* update vector for vec */ vec.get_const_ptr(), /* current vector */ low.get_const_ptr(), /* lower bounds for vec */ up.get_const_ptr(), /* upper bounds for vec */ epsilon); /* what is 0? */ if (max == val) return -1; // phase 2: stab = 0; sel = infinity; useeps = maxabs * epsilon * 0.001; if (useeps < epsilon) useeps = epsilon; for (j = upd.size() - 1; j >= 0; --j) { i = upd.index(j); x = upd[i]; if (x < -useeps) { y = up[i] - vec[i]; if (y < -degeneps) solver()->shiftUBbound(i, vec[i]); // ensure simplex improvement else { y /= x; if (y >= max && y < sel + epsilon && -x > stab) { sel = y; leave = i; stab = -x; } } } else if (x > useeps) { y = low[i] - vec[i]; if (y > degeneps) solver()->shiftLBbound(i, vec[i]); // ensure simplex improvement else { y /= x; if (y >= max && y < sel + epsilon && x > stab) { sel = y; leave = i; stab = x; } } } else upd.clearNum(j); } } else return -1; if (lastshift != solver()->shift()) return selectLeave(val, enterId); assert(leave >= 0); val = sel; return leave; }