/** * clear() tests */ void testClear() { IntVector v; v.push(0); v.push(1); v.push(2); v.clear(); assert(v.size() == 0); // test empty v.clear(); assert(v.size() == 0); }
int main(int argc, char* argv[]) { if (argc != 2) { std::cerr<<"Usage: ./coin <number>\n"; return -1; } coins.push_back(1); //coins.push_back(2); //coins.push_back(5); coins.push_back(10); coins.push_back(25); std::sort(coins.begin(), coins.end()); unsigned long number = boost::lexical_cast<unsigned long>(std::string(argv[1])); if (number < 25) { clock_t ticks = clock(); IntVector cset; generateBacktrack(cset, number); printVector(solution); std::cout << "Back: "<< clock() - ticks << std::endl; } { //not working good solution.clear(); computeCoins(number); std::cout<<"Greedy: "; printVector(solution); } if (number < 100) { //another solution //change(n)= 1+ min({change(n-1),change(n-2),change(n-5)}) solution.clear(); unsigned n = computeRecursive(number); std::cout<<"recursive n: "<<n<<"\n"; } { solution.clear(); computeDynamic(number); } return 0; }
void IntMatrix::MakeVec(IntVector& v) const { v.clear(); for(int j=0; j<GetHeight(); j++) for(int i=0; i<GetWidth(); i++) v.push_back((*this)[j][i]); }
void TimeWarp::extendForwardAlignmentPath(int endX, IntMatrix* backPath, int anchorPointX, int anchorPointY){ //andchor points are the starting index so if we have already done up to int forwardsIndex = forwardsAlignmentPath.size(); int indexX = (*backPath)[0].size() - 1; if (forwardsIndex == 0){ printf("initialise forwards path..\n"); IntVector v; v.push_back((*backPath)[0][indexX]);//chromaMatrix.size()-1 forwardsAlignmentPath.push_back(v); v.clear(); //v.push_back(forwardsAlignmentPath[0][indexX]);//secondMatrix v.push_back((*backPath)[1][indexX]);//new forwardsAlignmentPath.push_back(v); indexX--; printf("FORWARDS PATH STARTED AS %i, %i\n", forwardsAlignmentPath[0][0], forwardsAlignmentPath[1][0]); } else{ //forwards path has been started and we need anchor point } while ((*backPath)[0][indexX] <= endX){ addNewForwardsPath(indexX, backPath, anchorPointX, anchorPointY); // printf("Forwards path from index %i:: path %i : %i\n", indexX, forwardsAlignmentPath[0][forwardsIndex], forwardsAlignmentPath[1][forwardsIndex]); indexX--; forwardsIndex++; } }
static IntVector& calc_fasta_multi_digest_fragments ( const string& peptideFormula ) { static IntVector cleavageIndex; int numAA = peptideFormula.length (); cleavageIndex.reserve ( numAA ); cleavageIndex.clear (); if ( numAA ) { int penultimateAA = numAA - 1; for ( int i = 0 ; i < penultimateAA ; i++ ) { for ( int j = 0 ; j < numDigests ; j++ ) { char break_test_aa = ( digestSpecificityArray [j] == 'C' ) ? peptideFormula [i] : peptideFormula [i+1]; if ( aa_composition_mask [break_test_aa] & break_mask_array [j] ) { char exclude_test_aa = ( digestSpecificityArray [j] == 'C' ) ? peptideFormula [i+1] : peptideFormula [i]; if ( (aa_composition_mask [exclude_test_aa] & exclude_mask_array [j]) == 0 ) { cleavageIndex.push_back ( i ); break; } } } } cleavageIndex.push_back ( penultimateAA ); } return ( cleavageIndex ); }
void GeneralIgnorePrioritizationPlugin::fillSelection(IntVector& selected, size_t size) { for (; m_nofElementsReady < size && !(m_priorityQueue->empty()); m_nofElementsReady++) { m_elementsReady->push_back((m_priorityQueue->back()).testcaseId); m_priorityQueue->pop_back(); } selected.clear(); for (size_t i = 0; i < size && i < m_nofElementsReady; i++) { selected.push_back((*m_elementsReady)[i]); } }
int OBJ::LoadMesh(const char *fname) { int ret = 0; mVerts.clear(); mTriIndices.clear(); InPlaceParser ipp(fname); ipp.Parse(this); return ret; }
void TimeWarp::calculateMinimumAlignmentPathRow(DoubleMatrix* alignmentMatrix, IntMatrix* backPath, bool pickMinimumFlag){ //this requires one pass of the DTW algorithm and then works backwards from (N,M) //to find the optimal path to (0,0), where N and M are the lengths of the two chromoVectors respectively (*backPath).clear(); // printf("Finding minimum Path %i vs sim size %i\n", (int)chromaMatrix.size(), (int)similarityMatrix.size() ); //printf("Finding minimum ROW Path of alignment matrix %i vs sim size %i\n", (int)(*alignmentMatrix).size(), (int)(*alignmentMatrix)[0].size() ); // printf("compares to sim %ix%i\n", similarityMatrix.size()-1, similarityMatrix[0].size()-1); IntVector v; // v.push_back(similarityMatrix.size()-1);//chromaMatrix.size()-1 - old way int endIndex = (*alignmentMatrix).size()-1; if (pickMinimumFlag){ endIndex = getMinimumIndexOfRowFromMatrix((int)((*alignmentMatrix)[0].size()-1), *alignmentMatrix); // printf("minimum of row is %i\n", endIndex); } v.push_back(endIndex); // printf("ROW PUSH end index %i ", endIndex); (*backPath).push_back(v); v.clear(); v.push_back((*alignmentMatrix)[0].size()-1); // printf("by %i ", (int)(*alignmentMatrix).size()-1); (*backPath).push_back(v); // printf("\nROW: backwards path initialised to %i : %i \n", (*backPath)[0][0], (*backPath)[1][0]); int indexOfBackwardsPath = 0; while (!findPreviousMinimumInBackwardsPath(alignmentMatrix, backPath)) { // if (indexOfBackwardsPath < (*backPath)[0].size()){ // printf("(*backPath) [ %i]: path: %i : %i \n", // indexOfBackwardsPath, (*backPath)[0][indexOfBackwardsPath], (*backPath)[1][indexOfBackwardsPath]); // } indexOfBackwardsPath++; } // int tmpSize = (int) (*backPath)[0].size()-1; // printf("ROW_final index of backwards path is %i \n", (int) (*backPath)[0].size()-1); // printf("ROW PATHends[%i] and i is %i , %i \n", tmpSize, (*backPath)[0][tmpSize], (*backPath)[1][tmpSize]); // printBackwardsPath(0, (*backPath)[0].size(), backPath); // if (backwardsAlignmentPath.size() > 0) // backwardsAlignmentIndex = backwardsAlignmentPath[0].size()-1;//remember that this goes backwards! }
void TimeWarp::calculateMinimumAlignmentPathColumn(DoubleMatrix* alignmentMatrix, IntMatrix* backPath, bool pickMinimumFlag){ //this requires one pass of the DTW algorithm and then works backwards from (N,M) //to find the optimal path to (0,0), where N and M are the lengths of the two chromoVectors respectively (*backPath).clear(); // printf("Finding minimum Path %i vs sim size %i\n", (int)chromaMatrix.size(), (int)similarityMatrix.size() ); printf("Finding minimum Path of alignment matrix %i vs sim size %i\n", (int)(*alignmentMatrix).size(), (int)(*alignmentMatrix)[0].size() ); // printf("compares to sim %ix%i\n", similarityMatrix.size()-1, similarityMatrix[0].size()-1); IntVector v; // v.push_back(similarityMatrix.size()-1);//chromaMatrix.size()-1 - old way //here we start at the corner of the alignment matrix //could change to greedy? - i.e. the best / minimum of the last vector v.push_back((*alignmentMatrix).size()-1); (*backPath).push_back(v); v.clear(); //v.push_back(similarityMatrix[0].size()-1);//secondMatrix int endIndex = (*alignmentMatrix)[(*alignmentMatrix).size()-1].size()-1; if (pickMinimumFlag){ endIndex = getMinimumIndexOfColumnFromMatrix((int)(*alignmentMatrix).size()-1, alignmentMatrix); //i.e. get index of minimum in the last column } v.push_back(endIndex);//and the y size printf("CALUCLATE MINIMUM PUSHED BACK %i\n", endIndex); (*backPath).push_back(v); //so now backwards path[0][0] = size(chroma) and path[1][0] = size(secondMatrix) printf("COLUMN: backwards path initialised to %i : %i \n", (*backPath)[0][0], (*backPath)[1][0]); int indexOfBackwardsPath = 0; while (!findPreviousMinimumInBackwardsPath(alignmentMatrix, backPath)) { indexOfBackwardsPath++; // printf("backwards path index %i: path: %i : %i \n", //dindexOfBackwardsPath, backwardsAlignmentPath[0][indexOfBackwardsPath], backwardsAlignmentPath[1][indexOfBackwardsPath]); } // printf("final index of backwards path is %i and i is %i \n", (int) (*backPath)[0].size()-1, indexOfBackwardsPath); // backwardsAlignmentIndex = backwardsAlignmentPath[0].size()-1;//remember that this goes backwards! }
int main() { while(true) { scanf("%d%d", &n, &m); if(n == 0) break; edges.clear(); edgeNums.clear(); for(int i = 0; i < m; i++) { int a, b, w; scanf("%d%d%d", &a, &b, &w); Edge e = {a - 1, b - 1, w}; edges.push_back(e); edgeNums.push_back(i); } runcase(); } return 0; }
static IntVector& calc_fasta_n_term_fragments ( const string& peptideFormula ) { static IntVector cleavageIndex; int numAA = peptideFormula.length (); cleavageIndex.reserve ( numAA ); cleavageIndex.clear (); if ( numAA ) { int penultimateAA = numAA - 1; for ( int i = 0 ; i < penultimateAA ; i++ ) { if ( aa_composition_mask [peptideFormula [i+1]] & break_mask ) { if ( (aa_composition_mask [peptideFormula [i]] & exclude_mask ) == 0 ) { cleavageIndex.push_back ( i ); } } } cleavageIndex.push_back ( penultimateAA ); } return ( cleavageIndex ); }
void TimeWarp::extendForwardAlignmentPathToYanchor(int endY, IntMatrix* backPath, int anchorPointX, int anchorPointY){ //andchor points are the starting index so if we have already done up to int forwardsIndex = forwardsAlignmentPath.size(); // int indexX = (*backPath)[0].size() - 1; int indexY = (*backPath)[1].size() - 1; if (forwardsIndex == 0){ // printf("Y_AnchorExtend_initialise forwards path.(%i).\n", indexY); IntVector v; //printf("aim to start with %i and %i, anchors %i,%i\n", (*backPath)[0][indexX], (*backPath)[1][indexX], anchorPointX, anchorPointY); v.push_back((*backPath)[0][indexY]);//chromaMatrix.size()-1 forwardsAlignmentPath.push_back(v); v.clear(); //v.push_back(forwardsAlignmentPath[0][indexX]); v.push_back((*backPath)[1][indexY]); forwardsAlignmentPath.push_back(v); indexY--; //printf("FORWARDS PATH STARTED AS %i, %i\n", forwardsAlignmentPath[0][0], forwardsAlignmentPath[1][0]); } else{ //forwards path has been started and we need anchor point // printf("backpath index %i x %i y %i\n", indexY, (*backPath)[0][indexY], (*backPath)[1][indexY]); } // printf("about to pop %i vs %i\n", (int) (*backPath)[1][indexY], endY); // printBackwardsPath(0, (*backPath)[1].size()-1, backPath); // printf("back path to pop above!"); while ((*backPath)[1][indexY] <= endY){ addNewForwardsPathFromYindex(indexY, backPath, anchorPointX, anchorPointY); // printf("Forwards path from index %i:: path %i : %i\n", indexY, forwardsAlignmentPath[0][forwardsIndex], forwardsAlignmentPath[1][forwardsIndex]); indexY--; forwardsIndex++; } // printf("\n\nEND POPPING %i\n\n", endY); }
void TimeWarp::copyForwardsPathToBackwardsPath(){ backwardsAlignmentPath.clear(); int index = forwardsAlignmentPath[0].size()-1; // printf("COPY FORWARDS INDEX %i\n", index); IntVector d; d.push_back(forwardsAlignmentPath[0][index]); backwardsAlignmentPath.push_back(d); d.clear(); d.push_back(forwardsAlignmentPath[1][index]); backwardsAlignmentPath.push_back(d); while (index > 0){ index--; // IntVector d; // d.push_back(forwardsAlignmentPath[0][index]); // d.push_back(forwardsAlignmentPath[1][index]); backwardsAlignmentPath[0].push_back(forwardsAlignmentPath[0][index]); backwardsAlignmentPath[1].push_back(forwardsAlignmentPath[1][index]); } //printf("bxckweards path size ids %i\n", (int) backwardsAlignmentPath[0].size()); }
// Clearing a standard container using clear() is treated as a // re-initialization. void standardContainerClearIsReinit() { { std::string container; std::move(container); container.clear(); container.empty(); } { std::vector<int> container; std::move(container); container.clear(); container.empty(); } { std::deque<int> container; std::move(container); container.clear(); container.empty(); } { std::forward_list<int> container; std::move(container); container.clear(); container.empty(); } { std::list<int> container; std::move(container); container.clear(); container.empty(); } { std::set<int> container; std::move(container); container.clear(); container.empty(); } { std::map<int> container; std::move(container); container.clear(); container.empty(); } { std::multiset<int> container; std::move(container); container.clear(); container.empty(); } { std::multimap<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_set<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_map<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_multiset<int> container; std::move(container); container.clear(); container.empty(); } { std::unordered_multimap<int> container; std::move(container); container.clear(); container.empty(); } // This should also work for typedefs of standard containers. { typedef std::vector<int> IntVector; IntVector container; std::move(container); container.clear(); container.empty(); } // But it shouldn't work for non-standard containers. { // This might be called "vector", but it's not in namespace "std". struct vector { void clear() {} } container; std::move(container); container.clear(); // CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'container' used after it was // CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here } // An intervening clear() on a different container does not reinitialize. { std::vector<int> container1, container2; std::move(container1); container2.clear(); container1.empty(); // CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'container1' used after it was // CHECK-MESSAGES: [[@LINE-4]]:5: note: move occurred here } }
inline void IndexedList::clear(void) { _list.clear(); _element.assign(max_size(), max_size()); }
inline void IndexedList::reset(size_t const & s) { _element.assign(s, s); _list.clear(); _list.reserve(max_size()); }
/** Probe values at specified locations */ int Prepare::probe(vector<string>& fields,Int start_index) { /*probe points*/ IntVector probes; ofstream of("probes"); /*probe at each time step*/ for(Int step = start_index;;step++) { if(LoadMesh(step,(step == start_index),true)) { createFields(fields,step); probes.clear(); getProbeFaces(probes); } if(!readFields(fields,step)) break; /*Interpolate*/ forEachCellField(interpolateVertexAll()); /*write probes*/ #define ADD(v,value,weight) { \ dist = magSq((v) - probeP); \ dist = weight / (dist + 1.0f); \ sum += (value) * dist; \ sumd += dist; \ } #define SUM(X) { \ Cell& c = gCells[X]; \ forEach(c,m) { \ Facet& f = gFacets[c[m]]; \ forEach(f,j) { \ ADD(gVertices[f[j]],(*it)[f[j]],1.0); \ } \ } \ } #define WRITE(T) { \ std::list<MeshField<T,CELL>*>::iterator it1 = \ MeshField<T,CELL>::fields_.begin(); \ for(MeshField<T,CELL>::vertexFieldsType::iterator it = \ (MeshField<T,CELL>::vf_fields_)->begin(); it != \ (MeshField<T,CELL>::vf_fields_)->end(); ++it,++it1) { \ T sum(0.0); \ Scalar sumd(0.0); \ ADD(cC[c1],(*(*it1))[c1],2.0); \ ADD(cC[c2],(*(*it1))[c2],2.0); \ SUM(sc); \ of << (sum/sumd) << " "; \ } \ } forEach(probes,i) { Int fi = probes[i]; Int c1 = FO[fi]; Int c2 = FN[fi]; Vector probeP = probePoints[i]; Scalar dir = ((fC[fi] - probeP) & fN[fi]),dist; Int sc = (dir >= 0) ? c1 : c2; of << step << " " << i << " " << probePoints[i] << " "; WRITE(Scalar); WRITE(Vector); WRITE(STensor); WRITE(Tensor); of << endl; } #undef WRITE #undef SUM #undef ADD }
void ConvertXml::calcDivisions() { // cout << "ConvertXml::calcDivisions()" << endl; // init integers.clear(); primes.clear(); integers.append(120); // quarter note length primes.append(2); primes.append(3); primes.append(5); primes.append(7); // initialize with required prime numbers // need to use note and rest duration as exported to MusicXML // thus match ConvertXml::write's main loop // loop over all tracks for (auto row = 0; row < song->rowCount(); row++) { TabTrack* trk = song->index(row, 0).data(TabSong::TrackPtrRole).value<TabTrack*>(); trk->calcVoices(); // LVIFIX: is this necessary ? // cout << "part id=P" << it+1 << endl; // loop over all bars for (int ib = 0; ib < trk->bars().size(); ib++) { // cout << "measure number=" << ib + 1 << endl; // loop over all voices in this bar for (int i = 0; i < 2; i++) { // write only voice 1 in single voice tracks, // write all voices in multi voice tracks if ((i == 1) || trk->hasMultiVoices()) { // cout << "voice number=" << i + 1 << endl; // loop over all columns in this bar for (int x = trk->bars()[ib].start; x <= trk->lastColumn(ib); /* nothing */) { /* int tp; int dt; bool tr; bool res; res = trk->getNoteTypeAndDots(x, i, tp, dt, tr); // LVIFIX: error handling ? // false means no note in this column/voice // LVIFIX: add rest handling (see writecol) cout << "x=" << x << " res=" << res << " tp=" << tp << " dt=" << dt << " tr=" << tr << endl; */ QTextStream dummy; x += writeCol(dummy, trk, x, i, false); } // end for (uint x = 0; .... } // end if ((i == 1) || ... } // end for (int i = 0; ... } // end for (uint ib = 0; ... } // end for (unsigned int it = 0; ... // do it: divide by all primes as often as possible for (auto& u : primes) { while (canDivideBy(u)) { divideBy(u); } } // cout << "res=" << integers[0] << endl; divisions = integers[0]; }