コード例 #1
0
ファイル: franzi-gb.cpp プロジェクト: ChristineJost/M2
// 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;
}
コード例 #2
0
ファイル: file_download.cpp プロジェクト: 2asoft/tdesktop
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();
				}
			}
		}
	}
}
コード例 #3
0
ファイル: pspecific_mac.cpp プロジェクト: jubalh/tdesktop
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);
			}
		}
	}
}
コード例 #4
0
ファイル: franzi-gb.cpp プロジェクト: ChristineJost/M2
// generate list of index pairs for a new index and an intermediate basis
Pairs makeNewPairs(int newIndex, const IntermediateBasis &F, int n) {
  Pairs B;
  Pairs::iterator position = B.begin();
  for(int i=-n; i<0; i++) {
    Pair pair = Pair(i, newIndex, F);
    position = B.insert(position, pair);
  }
  IntermediateBasis::const_iterator end = F.end();
  end--;
  for(IntermediateBasis::const_iterator iter = F.begin(); iter != end; ++iter) {
    int j = iter->first;
    Pair pair = Pair(newIndex, j, F);
    if (pair.good) {
      position = B.insert(position, pair);
    }
  }
  return B;
}
コード例 #5
0
ファイル: franzi-gb.cpp プロジェクト: ChristineJost/M2
// generate list of index pairs for given intermediate basis
// first insert all pairs with FPs, then insert pairs of all other polynomials
// the list of indeces was ordered by increasingly
Pairs makeList(const IntermediateBasis &F, int n) {
  Pairs B;
  Pairs::iterator position = B.begin();
  IntermediateBasis::const_iterator end = F.end();
  for(IntermediateBasis::const_iterator iter = F.begin(); iter != end; ++iter) {
    int j = iter->first;
    for(int i=-n; i<0; i++) {
      Pair pair = Pair(i, j, F);
      position = B.insert(position, pair);
    }
    for(int i=0; i<j; i++) {
      Pair pair = Pair(i, j, F);
      if (pair.good) {
        position = B.insert(position, pair);
      }
    }
  }
  return B;
}
コード例 #6
0
inline void accumulate_pairs(AssocDest &table,Pairs const &source,AccumF accum_f)
{
    accumulate_pairs(table,source.begin(),source.end(),accum_f);
}
コード例 #7
0
inline void accumulate_pairs(Map &table,Pairs const &source)
{
    accumulate_pairs(table,source.begin(),source.end());
}
コード例 #8
0
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);
}
コード例 #9
0
ファイル: DistanceEst.cpp プロジェクト: JaapSuter/abyss
/** 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();
	}
}