static void writeEstimate(ostream& out, const ContigNode& id0, const ContigNode& id1, unsigned len0, unsigned len1, const Pairs& pairs, const PMF& pmf) { if (pairs.size() < opt::npairs) return; DistanceEst est; est.distance = estimateDistance(len0, len1, pairs, pmf, est.numPairs); est.stdDev = pmf.getSampleStdDev(est.numPairs); std::pair<ContigNode, ContigNode> e(id0, id1 ^ id0.sense()); if (est.numPairs >= opt::npairs) { if (opt::format == DOT) { #pragma omp critical(out) out << get(g_contigNames, e) << " [" << est << "]\n"; } else out << ' ' << get(g_contigNames, id1) << ',' << est; } else if (opt::verbose > 1) { #pragma omp critical(cerr) cerr << "warning: " << get(g_contigNames, e) << " [d=" << est.distance << "] " << est.numPairs << " of " << pairs.size() << " pairs fit the expected distribution\n"; } }
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 dxSAPSpace::collide (void *data, dNearCallback *callback) { dAASSERT (callback); lock_count++; cleanGeoms(); // by now all geoms are in GeomList, and DirtyList must be empty int geomSize = GeomList.size(); dUASSERT( geomSize == count, "geom counts messed up" ); // separate all geoms into infinite AABBs and normal AABBs TmpGeomList.setSize(0); TmpInfGeomList.setSize(0); int axis0max = SortAxes.mAxis0*2+1; for( int i = 0; i < geomSize; ++i ) { dxGeom* g =GeomList[i]; if( !GEOM_ENABLED(g) ) // skip disabled ones continue; const dReal& amax = g->aabb[axis0max]; if( amax == dInfinity ) // HACK? probably not... TmpInfGeomList.push( g ); else TmpGeomList.push( g ); } // do SAP on normal AABBs Pairs overlapBoxes; bool isok = complete_box_pruning( TmpGeomList.size(), (const dxGeom**)TmpGeomList.data(), overlapBoxes, SortAxes ); // collide overlapping udword overlapCount = overlapBoxes.GetNbPairs(); for( udword j = 0; j < overlapCount; ++j ) { const Pair* pair = overlapBoxes.GetPair(j); dxGeom* g1 = TmpGeomList[pair->id0]; dxGeom* g2 = TmpGeomList[pair->id1]; collideGeomsNoAABBs( g1, g2, data, callback ); } int infSize = TmpInfGeomList.size(); int normSize = TmpGeomList.size(); int m, n; for( m = 0; m < infSize; ++m ) { dxGeom* g1 = TmpInfGeomList[m]; // collide infinite ones for( n = m+1; n < infSize; ++n ) { dxGeom* g2 = TmpInfGeomList[n]; collideGeomsNoAABBs( g1, g2, data, callback ); } // collide infinite ones with normal ones for( n = 0; n < normSize; ++n ) { dxGeom* g2 = TmpGeomList[n]; collideGeomsNoAABBs( g1, g2, data, callback ); } } lock_count--; }
void mapHM::set(string key, int value){ int hash_value = myhash(&*key.begin(), key.length(), size_of_table); if (!(is_in(key))){ Pairs p; p.setPairs(key, value); arrayOfPairs[hash_value].add(p); } }
int main(void) { Pairs pairs; pairs.Run(); return 0; }
void Hand::SetPairSwaps( const ResultType& res, ValetEntryType& entry, unsigned& decl, unsigned& leader) { // This function takes care of assigning the scores to the right // players within a pair. pairNo is negative if the players are // internally stored in the opposite order to the one that happens // to be at the table. unsigned swapNS, swapEW; int pairNoNS = pairs.GetPairNumber(res.north, res.south); assert(pairNoNS != 0); if (pairNoNS < 0) { entry.pairNo = static_cast<unsigned>(-pairNoNS); swapNS = 1; } else { entry.pairNo = static_cast<unsigned>(pairNoNS); swapNS = 0; } int pairNoEW = pairs.GetPairNumber(res.east, res.west); assert(pairNoEW != 0); if (pairNoEW < 0) { entry.oppNo = static_cast<unsigned>(-pairNoEW); swapEW = 1; } else { entry.oppNo = static_cast<unsigned>(pairNoEW); swapEW = 0; } if (res.declarer == VALET_NORTH || res.declarer == VALET_SOUTH) { decl = Hswap[swapNS][res.declarer == VALET_SOUTH]; leader = Hswap[swapEW][res.declarer == VALET_SOUTH]; } else if (res.declarer == VALET_EAST || res.declarer == VALET_WEST) { decl = Hswap[swapEW][res.declarer == VALET_WEST]; leader = Hswap[swapNS][res.declarer == VALET_EAST]; } else { decl = 0; leader = 0; assert(false); } }
// 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; }
int main(int argc, char** argv) { FTAGArgs args; args.getArgs(argc, argv); srand48(args._seed); cout << "SEED=" << args._seed << endl; ofstream ofile(args._outFile.c_str()); if (!ofile) { cerr << "Specifiy output file with ofile=<path>" << endl; exit(1); } ofstream pfile(args._fpFileOut.c_str()); AxtReader ar; try { ar.read(args._inFile); const vector<AxtPair>& wholeThing = ar.getAlignments(); Pairs allAlignments; for (size_t i = 0; i < wholeThing.size(); ++i) { allAlignments.push_back(wholeThing[i].getAlignment()); } Pairs alignments = ar.sample(args._numPairs, args._maxLength / 2, args._maxLength, 0, false); FTAGParams parAll = estParams(allAlignments, args._symmetric); FTAGParams parInput = estParams(alignments, args._symmetric); cout << "From Whole File: " << parAll << endl; cout << "From input: " << parInput << endl; ofile << alignments; if (pfile.is_open()) { pfile << parInput; } } catch(string message) { cerr << message << endl; return 1; } return 0; }
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); } } } }
// 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; }
// 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; }
void findPairs( _Adapter& model, Pairs& pairs, double d_box ) { model.reset(); while( model.hasNext() ) { _TreeNode node = model.next(); std::pair<typename tree_type::const_iterator,double> found = kdtree.find_nearest(node, d_box); if( found.first != kdtree.end() && filter(node, *(found.first)) ) pairs.add((found.first)->point, node.point, found.second); } }
void Hand::SetPassout( const ResultType& res, const float totalIMPs, ValetEntryType& entry) { // Pass-out. int pairNoNS = pairs.GetPairNumber(res.north, res.south); assert(pairNoNS != 0); if (pairNoNS < 0) pairNoNS = -pairNoNS; // Doesn't matter for pass-out int pairNoEW = pairs.GetPairNumber(res.east, res.west); assert(pairNoEW != 0); if (pairNoEW < 0) pairNoEW = -pairNoEW; // Doesn't matter for pass-out entry.pairNo = static_cast<unsigned>(pairNoNS); entry.oppNo = static_cast<unsigned>(pairNoEW); entry.overall = totalIMPs; entry.bidScore = totalIMPs; }
/** performs a single alignment of the measurement to the model. * The model needs to be added using addToModel before this call. * * @param measurement - the mesh that needs to be matched * @param max_iter - maximum number of iterations * @param min_mse - minimum average square distance between points after which to stop * @param min_mse_diff - minimum difference in average square distance between points after which to stop * @param overlap - percentage of overlap, range between [0..1]. A value of * 0.95 will discard 5% of the pairs with the worst matches */ Result _align( _Adapter measurement, size_t max_iter, double min_mse, double min_mse_diff, double overlap ) { Result result; Pairs pairs; result.C_global2globalnew = Eigen::Affine3d::Identity(); result.iter = 0; result.overlap = overlap; result.d_box = std::numeric_limits<double>::infinity(); result.mse_diff = result.mse = std::numeric_limits<double>::infinity(); double old_mse = result.mse; while( result.iter < max_iter && result.mse > min_mse && result.mse_diff > min_mse_diff ) { old_mse = result.mse; pairs.clear(); findPairs.findPairs( measurement, pairs, result.d_box ); const size_t n_po = measurement.size() * result.overlap; result.d_box = pairs.trim( n_po ) * 2.0; result.pairs = pairs.size(); if( result.pairs < Pairs::MIN_PAIRS ) return result; Eigen::Affine3d C_globalprev2globalnew = pairs.getTransform(); result.C_global2globalnew = C_globalprev2globalnew * result.C_global2globalnew; measurement.setOffsetTransform( result.C_global2globalnew ); result.mse = pairs.getMeanSquareError(); result.mse_diff = old_mse - result.mse; result.iter++; // std::cout // << "points: " << measurement.size() // << "\titer: " << result.iter // << "\tpairs: " << pairs.size() // << "\tmse: " << result.mse // << "\tmse_diff: " << result.mse_diff // << "\td_box: " << result.d_box // << "\toverlap: " << result.overlap // << std::endl; } // std::cout // << std::endl; std::vector<double> pairs_distance; for( size_t i = 0; i < pairs.size(); i++ ) { pairs_distance.push_back( pairs.pairs[i].distance ); } result.pairs_distance = pairs_distance; return result; }
bool Opcode::BruteForceCompleteBoxTest(udword nb, const AABB** array, Pairs& pairs) { // Checkings if(!nb || !array) return false; // Brute-force n(n-1)/2 overlap tests for(udword i=0;i<nb;i++) { for(udword j=i+1;j<nb;j++) { if(array[i]->Intersect(*array[j])) pairs.AddPair(i, j); } } return true; }
bool Opcode::BruteForceBipartiteBoxTest(udword nb0, const AABB** array0, udword nb1, const AABB** array1, Pairs& pairs) { // Checkings if(!nb0 || !array0 || !nb1 || !array1) return false; // Brute-force nb0*nb1 overlap tests for(udword i=0;i<nb0;i++) { for(udword j=0;j<nb1;j++) { if(array0[i]->Intersect(*array1[j])) pairs.AddPair(i, j); } } return true; }
bool Opcode::BipartiteBoxPruning(udword nb0, const AABB** array0, udword nb1, const AABB** array1, Pairs& pairs, const Axes& axes) { // Checkings if(!nb0 || !array0 || !nb1 || !array1) return false; // Catch axes udword Axis0 = axes.mAxis0; udword Axis1 = axes.mAxis1; udword Axis2 = axes.mAxis2; // Allocate some temporary data float* MinPosList0 = new float[nb0]; float* MinPosList1 = new float[nb1]; // 1) Build main lists using the primary axis for(udword i=0;i<nb0;i++) MinPosList0[i] = array0[i]->GetMin(Axis0); for(udword i=0;i<nb1;i++) MinPosList1[i] = array1[i]->GetMin(Axis0); // 2) Sort the lists PRUNING_SORTER* RS0 = GetBipartitePruningSorter0(); PRUNING_SORTER* RS1 = GetBipartitePruningSorter1(); const udword* Sorted0 = RS0->Sort(MinPosList0, nb0).GetRanks(); const udword* Sorted1 = RS1->Sort(MinPosList1, nb1).GetRanks(); // 3) Prune the lists udword Index0, Index1; const udword* const LastSorted0 = &Sorted0[nb0]; const udword* const LastSorted1 = &Sorted1[nb1]; const udword* RunningAddress0 = Sorted0; const udword* RunningAddress1 = Sorted1; while(RunningAddress1<LastSorted1 && Sorted0<LastSorted0) { Index0 = *Sorted0++; while(RunningAddress1<LastSorted1 && MinPosList1[*RunningAddress1]<MinPosList0[Index0]) RunningAddress1++; const udword* RunningAddress2_1 = RunningAddress1; while(RunningAddress2_1<LastSorted1 && MinPosList1[Index1 = *RunningAddress2_1++]<=array0[Index0]->GetMax(Axis0)) { if(array0[Index0]->Intersect(*array1[Index1], Axis1)) { if(array0[Index0]->Intersect(*array1[Index1], Axis2)) { pairs.AddPair(Index0, Index1); } } } } //// while(RunningAddress0<LastSorted0 && Sorted1<LastSorted1) { Index0 = *Sorted1++; while(RunningAddress0<LastSorted0 && MinPosList0[*RunningAddress0]<=MinPosList1[Index0]) RunningAddress0++; const udword* RunningAddress2_0 = RunningAddress0; while(RunningAddress2_0<LastSorted0 && MinPosList0[Index1 = *RunningAddress2_0++]<=array1[Index0]->GetMax(Axis0)) { if(array0[Index1]->Intersect(*array1[Index0], Axis1)) { if(array0[Index1]->Intersect(*array1[Index0], Axis2)) { pairs.AddPair(Index1, Index0); } } } } DELETEARRAY(MinPosList1); DELETEARRAY(MinPosList0); return true; }
bool Opcode::CompleteBoxPruning(udword nb, const AABB** array, Pairs& pairs, const Axes& axes) { // Checkings if(!nb || !array) return false; // Catch axes udword Axis0 = axes.mAxis0; udword Axis1 = axes.mAxis1; udword Axis2 = axes.mAxis2; #ifdef ORIGINAL_VERSION // Allocate some temporary data // float* PosList = new float[nb]; float* PosList = new float[nb+1]; // 1) Build main list using the primary axis for(udword i=0;i<nb;i++) PosList[i] = array[i]->GetMin(Axis0); PosList[nb++] = MAX_FLOAT; // 2) Sort the list PRUNING_SORTER* RS = GetCompletePruningSorter(); const udword* Sorted = RS->Sort(PosList, nb).GetRanks(); // 3) Prune the list const udword* const LastSorted = &Sorted[nb]; const udword* RunningAddress = Sorted; udword Index0, Index1; while(RunningAddress<LastSorted && Sorted<LastSorted) { Index0 = *Sorted++; // while(RunningAddress<LastSorted && PosList[*RunningAddress++]<PosList[Index0]); while(PosList[*RunningAddress++]<PosList[Index0]); if(RunningAddress<LastSorted) { const udword* RunningAddress2 = RunningAddress; // while(RunningAddress2<LastSorted && PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0)) while(PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0)) { // if(Index0!=Index1) // { if(array[Index0]->Intersect(*array[Index1], Axis1)) { if(array[Index0]->Intersect(*array[Index1], Axis2)) { pairs.AddPair(Index0, Index1); } } // } } } } DELETEARRAY(PosList); #endif #ifdef JOAKIM // Allocate some temporary data // float* PosList = new float[nb]; float* MinList = new float[nb+1]; // 1) Build main list using the primary axis for(udword i=0;i<nb;i++) MinList[i] = array[i]->GetMin(Axis0); MinList[nb] = MAX_FLOAT; // 2) Sort the list PRUNING_SORTER* RS = GetCompletePruningSorter(); udword* Sorted = RS->Sort(MinList, nb+1).GetRanks(); // 3) Prune the list // const udword* const LastSorted = &Sorted[nb]; // const udword* const LastSorted = &Sorted[nb-1]; const udword* RunningAddress = Sorted; udword Index0, Index1; // while(RunningAddress<LastSorted && Sorted<LastSorted) // while(RunningAddress<LastSorted) while(RunningAddress<&Sorted[nb]) // while(Sorted<LastSorted) { // Index0 = *Sorted++; Index0 = *RunningAddress++; // while(RunningAddress<LastSorted && PosList[*RunningAddress++]<PosList[Index0]); // while(PosList[*RunningAddress++]<PosList[Index0]); //RunningAddress = Sorted; // if(RunningAddress<LastSorted) { const udword* RunningAddress2 = RunningAddress; // while(RunningAddress2<LastSorted && PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0)) // float CurrentMin = array[Index0]->GetMin(Axis0); float CurrentMax = array[Index0]->GetMax(Axis0); while(MinList[Index1 = *RunningAddress2] <= CurrentMax) // while(PosList[Index1 = *RunningAddress] <= CurrentMax) { // if(Index0!=Index1) // { if(array[Index0]->Intersect(*array[Index1], Axis1)) { if(array[Index0]->Intersect(*array[Index1], Axis2)) { pairs.AddPair(Index0, Index1); } } // } RunningAddress2++; // RunningAddress++; } } } DELETEARRAY(MinList); #endif return true; }
/** 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(); } }
void PairsView::_ReadRandomIcons() { Pairs* app = dynamic_cast<Pairs*>(be_app); if (app == NULL) // check if NULL to make Coverity happy return; // Create a copy of the icon map so we can erase elements from it as we // add them to the list eliminating repeated icons without altering the // orginal IconMap. IconMap tmpIconMap(app->GetIconMap()); size_t mapSize = tmpIconMap.size(); if (mapSize < (size_t)fCardsCount) { // not enough icons, we're screwed return; } // clean out any previous icons fSmallBitmapsList->MakeEmpty(); fMediumBitmapsList->MakeEmpty(); fLargeBitmapsList->MakeEmpty(); // pick bitmaps at random from the icon map for (int32 i = 0; i < fCardsCount; i++) { IconMap::iterator iter = tmpIconMap.begin(); if (mapSize < (size_t)fCardsCount) { // not enough valid icons, we're really screwed return; } std::advance(iter, rand() % mapSize); size_t key = iter->first; vector_icon* icon = iter->second; BBitmap* smallBitmap = new BBitmap( BRect(0, 0, kSmallIconSize - 1, kSmallIconSize - 1), B_RGBA32); status_t smallResult = BIconUtils::GetVectorIcon(icon->data, icon->size, smallBitmap); BBitmap* mediumBitmap = new BBitmap( BRect(0, 0, kMediumIconSize - 1, kMediumIconSize - 1), B_RGBA32); status_t mediumResult = BIconUtils::GetVectorIcon(icon->data, icon->size, mediumBitmap); BBitmap* largeBitmap = new BBitmap( BRect(0, 0, kLargeIconSize - 1, kLargeIconSize - 1), B_RGBA32); status_t largeResult = BIconUtils::GetVectorIcon(icon->data, icon->size, largeBitmap); if (smallResult + mediumResult + largeResult == B_OK) { fSmallBitmapsList->AddItem(smallBitmap); fMediumBitmapsList->AddItem(mediumBitmap); fLargeBitmapsList->AddItem(largeBitmap); } else { delete smallBitmap; delete mediumBitmap; delete largeBitmap; i--; } mapSize -= tmpIconMap.erase(key); // remove the element from the map so we don't read it again } }
bool LineToResult( const vector<string> tokens, ResultType& res, unsigned& rno, unsigned& bno, bool skipNameCheck) { if (! TokenToUnsigned(tokens[0], 1, 0, "round number", rno)) { error.no = RETURN_ROUND_NUMBER; return false; } if (! TokenToUnsigned(tokens[1], 1, 0, "board number", bno)) { error.no = RETURN_BOARD_NUMBER; return false; } res.north = tokens[2]; if (! skipNameCheck && ! pairs.TagExists(res.north)) { error.flag = true; error.no = RETURN_PLAYER_NORTH; error.message << "Got North player: '" << res.north << "' (not in name list)\n"; return false; } res.east = tokens[3]; if (! skipNameCheck && ! pairs.TagExists(res.east)) { error.flag = true; error.no = RETURN_PLAYER_EAST; error.message << "Got East player: '" << res.east << "' (not in name list)\n"; return false; } res.south = tokens[4]; if (! skipNameCheck && ! pairs.TagExists(res.south)) { error.flag = true; error.no = RETURN_PLAYER_SOUTH; error.message << "Got South player: '" << res.south << "' (not in name list)\n"; return false; } res.west = tokens[5]; if (! skipNameCheck && ! pairs.TagExists(res.west)) { error.flag = true; error.no = RETURN_PLAYER_WEST; error.message << "Got West player: '" << res.west << "' (not in name list)\n"; return false; } size_t cl = tokens[6].size(); if (cl == 0 || cl > 4) { error.flag = true; error.no = RETURN_CONTRACT_FORMAT_TEXT; error.message << "Got contract: '" << tokens[6].c_str() << "' (bad length)\n"; return false; } if (cl == 1) { if (tokens[6] != "P" && tokens[6] != "p") { error.flag = true; error.no = RETURN_CONTRACT_FORMAT_TEXT; error.message << "Got contract: '" << tokens[6].c_str() << "' (if length 1, must be P or p)\n"; return false; } res.level = 0; return true; } if (! CharToLevel(tokens[6][0], res.level)) { error.flag = true; error.no = RETURN_LEVEL; error.message << "Got contract: '" << tokens[6].c_str() << "' (can't find a level 1 .. 7)\n"; return false; } if (! CharToDenom(tokens[6][1], res.denom)) { error.flag = true; error.no = RETURN_DENOM; error.message << "Got contract: '" << tokens[6].c_str() << "' (can't find a denomination, want NSHDC/nshdc)\n"; return false; } if (cl == 3) { if (tokens[6][2] != 'X' && tokens[6][2] != 'x') { error.flag = true; error.no = RETURN_MULTIPLIER; error.message << "Got contract: '" << tokens[6].c_str() << "' (expected last letter to be X or x)\n"; return false; } res.multiplier = VALET_DOUBLED; } else if (cl == 4) { if ((tokens[6][2] != 'X' && tokens[6][2] != 'x')|| (tokens[6][3] != 'X' && tokens[6][3] != 'x')) { error.flag = true; error.no = RETURN_MULTIPLIER; error.message << "Got contract: '" << tokens[6].c_str() << "' (expected last letters to be XX or xx)\n"; return false; } res.multiplier = VALET_REDOUBLED; } else res.multiplier = VALET_UNDOUBLED; if (tokens[7].size() != 1 || ! CharToPlayer(tokens[7][0], res.declarer)) { error.flag = true; error.no = RETURN_DECLARER; error.message << "Got declarer: '" << tokens[7].c_str() << "' (expected NESW or nesw)\n"; return false; } if (! TokenToUnsigned(tokens[8], 0, 13, "tricks", res.tricks)) { error.flag = true; error.no = RETURN_TRICKS; return false; } if (tokens.size() == 9) { res.leadRank = 0; return true; } if (tokens[9].size() != 2) { error.flag = true; error.no = RETURN_LEAD_TEXT; error.message << "Got lead: '" << tokens[9].c_str() << "' (expected two characters)\n"; return false; } if (! CharToDenom(tokens[9][0], res.leadDenom)) { error.flag = true; error.no = RETURN_LEAD_DENOM; error.message << "Got lead: '" << tokens[9].c_str() << "' (can't find a denomination, want NSHDC/nshdc)\n"; return false; } if (! CharToRank(tokens[9][1], res.leadRank)) { error.flag = true; error.no = RETURN_LEAD_RANK; error.message << "Got lead: '" << tokens[9].c_str() << "' (can't find a rank, want AKQJT, akqjt or 2 .. 9)\n"; return false; } return true; }
inline void accumulate_pairs(AssocDest &table,Pairs const &source,AccumF accum_f) { accumulate_pairs(table,source.begin(),source.end(),accum_f); }
/** * Complete box pruning. * Returns a list of overlapping pairs of boxes, each box of the pair * belongs to the same set. * NOTE: code uses floats instead of dReals because Opcode's radix sort * is optimized for floats :) * * @param count [in] number of boxes. * @param geoms [in] geoms of boxes. * @param pairs [out] array of overlapping pairs. * @param axes [in] projection order (0,2,1 is often best). * @return true If success. */ static bool complete_box_pruning( int count, const dxGeom** geoms, Pairs& pairs, const Axes& axes ) { // Checks if (!count || !geoms) return false; // Catch axes udword Axis0 = axes.mAxis0; udword Axis1 = axes.mAxis1; udword Axis2 = axes.mAxis2; // Axis indices into geom's aabb are: min=idx, max=idx+1 udword ax0idx = Axis0*2; udword ax1idx = Axis1*2; udword ax2idx = Axis2*2; // Allocate some temporary data // TBD: persistent allocation between queries? float* PosList = new float[count+1]; // 1) Build main list using the primary axis for( int i = 0; i < count; ++i ) PosList[i] = (float)geoms[i]->aabb[ax0idx]; PosList[count++] = MAX_FLOAT; // 2) Sort the list PRUNING_SORTER* RS = get_pruning_sorter(); const udword* Sorted = RS->Sort(PosList, count).GetRanks(); // 3) Prune the list const udword* const LastSorted = &Sorted[count]; const udword* RunningAddress = Sorted; udword Index0, Index1; while( RunningAddress < LastSorted && Sorted < LastSorted ) { Index0 = *Sorted++; while( PosList[*RunningAddress++] < PosList[Index0] ) { // empty, the loop just advances RunningAddress } if( RunningAddress < LastSorted ) { const udword* RunningAddress2 = RunningAddress; float idx0ax0max = (float)geoms[Index0]->aabb[ax0idx+1]; float idx0ax1max = (float)geoms[Index0]->aabb[ax1idx+1]; float idx0ax2max = (float)geoms[Index0]->aabb[ax2idx+1]; while( PosList[Index1 = *RunningAddress2++] <= idx0ax0max ) { // if(Index0!=Index1) // { const dReal* aabb0 = geoms[Index0]->aabb; const dReal* aabb1 = geoms[Index1]->aabb; if( idx0ax1max < (float)aabb1[ax1idx] || (float)aabb1[ax1idx+1] < (float)aabb0[ax1idx] ) { // no intersection } else { if( idx0ax2max < (float)aabb1[ax2idx] || (float)aabb1[ax2idx+1] < (float)aabb0[ax2idx] ) { // no intersection } else { // yes! :) pairs.AddPair( Index0, Index1 ); } } // } } } } DELETEARRAY(PosList); return true; }
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); }
void SolvePairs() { Pairs *p = new Pairs(); cout << "Answer Is: "; cout << p->solve(); }
inline void accumulate_pairs(Map &table,Pairs const &source) { accumulate_pairs(table,source.begin(),source.end()); }
// 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(); }