// complete algorithm to compute a Groebner basis F void gb( IntermediateBasis &F, int n) { int nextIndex = F.size(); rearrangeBasis(F, -1); interreduction(F); Pairs B = makeList(F, n); //unsigned int countAddPoly = 0; //unsigned int numSPoly= 0; int interreductionCounter = 0; while (!B.empty()) { Pair pair = *(B.begin()); B.erase(B.begin()); if (isGoodPair(pair,F,B,n)) { //numSPoly++; BRP S = sPolynomial(pair,F,n); reduce(S,F); if ( ! S.isZero() ) { //countAddPoly++; F[nextIndex] = S; if(interreductionCounter == 5) { interreductionCounter = 0; interreduction(F); B = makeList(F, n); } else { interreductionCounter++; Pairs newList = makeNewPairs(nextIndex, F, n); B.insert(newList.begin(), newList.end()); } nextIndex++; } } } interreduction(F); //cout << "we computed " << numSPoly << " S Polynomials and added " << countAddPoly << " of them to the intermediate basis." << endl; }
void WebLoadManager::onMeta() { QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender()); if (!reply) return; Replies::iterator j = _replies.find(reply); if (j == _replies.cend()) { // handled already return; } webFileLoaderPrivate *loader = j.value(); typedef QList<QNetworkReply::RawHeaderPair> Pairs; Pairs pairs = reply->rawHeaderPairs(); for (Pairs::iterator i = pairs.begin(), e = pairs.end(); i != e; ++i) { if (QString::fromUtf8(i->first).toLower() == "content-range") { QRegularExpressionMatch m = QRegularExpression(qsl("/(\\d+)([^\\d]|$)")).match(QString::fromUtf8(i->second)); if (m.hasMatch()) { loader->setProgress(qMax(qint64(loader->data().size()), loader->already()), m.captured(1).toLongLong()); if (!handleReplyResult(loader, WebReplyProcessProgress)) { _replies.erase(j); _loaders.remove(loader); delete loader; reply->abort(); reply->deleteLater(); } } } } }
void PsUpdateDownloader::partMetaGot() { typedef QList<QNetworkReply::RawHeaderPair> Pairs; Pairs pairs = reply->rawHeaderPairs(); for (Pairs::iterator i = pairs.begin(), e = pairs.end(); i != e; ++i) { if (QString::fromUtf8(i->first).toLower() == "content-range") { QRegularExpressionMatch m = QRegularExpression(qsl("/(\\d+)([^\\d]|$)")).match(QString::fromUtf8(i->second)); if (m.hasMatch()) { { QMutexLocker lock(&mutex); full = m.captured(1).toInt(); } emit App::app()->updateDownloading(already, full); } } } }
inline void accumulate_pairs(AssocDest &table,Pairs const &source,AccumF accum_f) { accumulate_pairs(table,source.begin(),source.end(),accum_f); }
inline void accumulate_pairs(Map &table,Pairs const &source) { accumulate_pairs(table,source.begin(),source.end()); }
template <class Vector,class Pairs,class AccumF> inline void accumulate_at_pairs(Vector &table,Pairs const &source,AccumF accum_f) { accumulate_at_pairs(table,source.begin(),source.end(),accum_f); }
// return true if pair (i,j) is in the list of indeces bool inList(int i, int j, const Pairs &B, const IntermediateBasis &F) { Pair p = Pair(i, j, F); return B.find(p) != B.end(); }
/** Estimate the distance between two contigs. * @param numPairs [out] the number of pairs that agree with the * expected distribution * @return the estimated distance */ static int estimateDistance(unsigned len0, unsigned len1, const Pairs& pairs, const PMF& pmf, unsigned& numPairs) { // The provisional fragment sizes are calculated as if the contigs // were perfectly adjacent with no overlap or gap. typedef vector<pair<int, int> > Fragments; Fragments fragments; fragments.reserve(pairs.size()); for (Pairs::const_iterator it = pairs.begin(); it != pairs.end(); ++it) { int a0 = it->targetAtQueryStart(); int a1 = it->mateTargetAtQueryStart(); if (it->isReverse()) a0 = len0 - a0; if (!it->isMateReverse()) a1 = len1 - a1; fragments.push_back(opt::rf ? make_pair(a1, len1 + a0) : make_pair(a0, len0 + a1)); } // Remove duplicate fragments. unsigned orig = fragments.size(); sort(fragments.begin(), fragments.end()); fragments.erase(unique(fragments.begin(), fragments.end()), fragments.end()); numPairs = fragments.size(); assert((int)orig - (int)numPairs >= 0); stats.total_frags += orig; stats.dup_frags += orig - numPairs; if (numPairs < opt::npairs) return INT_MIN; vector<int> fragmentSizes; fragmentSizes.reserve(fragments.size()); unsigned ma = opt::minAlign; for (Fragments::const_iterator it = fragments.begin(); it != fragments.end(); ++it) { int x = it->second - it->first; if (!opt::rf && opt::method == MLE && x <= 2 * int(ma - 1)) { unsigned align = x / 2; if (opt::verbose > 0) #pragma omp critical(cerr) cerr << PROGRAM ": warning: The observed fragment of " "size " << x << " bp is shorter than 2*l " "(l=" << opt::minAlign << ").\n"; ma = min(ma, align); } fragmentSizes.push_back(x); } #pragma omp critical(g_recMA) g_recMA = min(g_recMA, ma); switch (opt::method) { case MLE: // Use the maximum likelihood estimator. return maximumLikelihoodEstimate(ma, opt::minDist, opt::maxDist, fragmentSizes, pmf, len0, len1, opt::rf, numPairs); case MEAN: // Use the difference of the population mean // and the sample mean. return estimateDistanceUsingMean( fragmentSizes, pmf, numPairs); default: assert(false); abort(); } }