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 ); }
/*Dynamic approach: * s[n] = coin[x], if coin[x] == i * min(s[j]) + 1, where exists a coin[x] = s[i] - s[j] */ void computeDynamic(unsigned n) { IntVector s; //s[n] = how many coins do we need to compute n s.push_back(0); //0 coins for 0 dyn_solution.push_back(IntVector()); for (unsigned i = 1; i <= n; ++i) { unsigned coin = getCoin(i); if (coin) //found a coin equal to i { s.push_back(1); dyn_solution.push_back(IntVector(1, coin)); } else { coin = getPreviousMin(s, i); if (!coin) { std::cerr<<"i: "<<i<<"\n"; throw std::logic_error("Cannot find a coin for current i"); } s.push_back(coin + 1); } } printVector(dyn_solution.back()); //printVector(s); }
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++; } }
// N以下の素数を生成する static void gen_prime(int N, IntVector &v) { v.push_back(2), v.push_back(3); for (int n = 5; n <= N; n += 2) { const int *s = &v[0]; int p, p2; while ((p2 = ((p = *++s) * p)) < n && (n % p) != 0) ; if (p2 > n) v.push_back(n); } }
double ImageUtils::estimateLineThickness(Image &bwimg, int grid) { int w = bwimg.getWidth(); int h = bwimg.getHeight(); int d = grid; IntVector lthick; if(w < d) d = std::max<int>(w >>1, 1) ; { int startseg = -1; for(int i = 0; i < w ; i += d) { for(int j = 0; j < h; j++) { byte val = bwimg.getByte(i, j); if(val == 0 && (startseg == -1)) startseg = j; if((val > 0 || j==(h-1)) && startseg != -1) { lthick.push_back(j - startseg + 1); startseg = -1; } } } } if(h > d) d = grid; else d = std::max<int>(h >>1, 1) ; { int startseg = -1; for(int j = 0; j< h; j+=d) { for(int i = 0; i < w; i++) { byte val = bwimg.getByte(i, j); if(val == 0 && (startseg == -1)) startseg = i; if((val > 0 || i==(w-1)) && startseg != -1) { lthick.push_back(i - startseg + 1); startseg = -1; } } } } std::sort(lthick.begin(), lthick.end()); double thickness = 0; if(lthick.size() > 0) thickness = StatUtils::interMean(lthick.begin(), lthick.end()); return thickness; }
IntVector FileSplit::getSendData ( int searchNumber, int index ) const { int numProcesses = startFraction.size () / numSerial; int i = searchNumber + ( index * numProcesses ); IntVector sendData; sendData.push_back ( startFraction [i] ); sendData.push_back ( startSpec [i] ); sendData.push_back ( endFraction [i] ); sendData.push_back ( endSpec [i] ); return sendData; }
int OBJ::ParseLine(int /*lineno*/,int argc,const char **argv) // return TRUE to continue parsing, return FALSE to abort parsing process { int ret = 0; if ( argc >= 1 ) { const char *foo = argv[0]; if ( *foo != '#' ) { if ( strcasecmp(argv[0],"v") == 0 && argc == 4 ) { float vx = (float) atof( argv[1] ); float vy = (float) atof( argv[2] ); float vz = (float) atof( argv[3] ); mVerts.push_back(vx); mVerts.push_back(vy); mVerts.push_back(vz); } else if ( strcasecmp(argv[0],"f") == 0 && argc >= 4 ) { int vcount = argc-1; int i1 = (int)atoi(argv[1])-1; int i2 = (int)atoi(argv[2])-1; int i3 = (int)atoi(argv[3])-1; mTriIndices.push_back(i3); mTriIndices.push_back(i2); mTriIndices.push_back(i1); if ( vcount >=3 ) // do the fan { for (int i=2; i<(vcount-1); i++) { i2 = i3; i3 = (int)atoi(argv[i+2])-1; mTriIndices.push_back(i3); mTriIndices.push_back(i2); mTriIndices.push_back(i1); } } } } } 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 KoAluruSuffixArray::sortLessType() { IntVector recursiveString; IntVector recursiveConnection; for (int i = 0; i < (int)string.size(); i++) { if (isLessType[i]) { recursiveConnection.push_back(i); recursiveString.push_back(lessType[i]); } } assert(recursiveString.size() * 2 < string.size() + 2); stringToSuffixArray(recursiveString, sortedLess); for (int i = 0; i < (int)sortedLess.size(); i++) sortedLess[i] = recursiveConnection[sortedLess[i]]; }
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; }
// Remove leaves that have an edit distance much higher than // the best leaf void StringThreader::cullLeavesByEdits() { STNodePtrList newLeaves; // Calculate the local error rate of the alignments to each new leaf // If it is less than threshold, add the leaf to the node int bestEdits = std::numeric_limits<int>::max(); IntVector editsVector; for(STNodePtrList::iterator iter = m_leaves.begin(); iter != m_leaves.end(); ++iter) { int edits = (*iter)->getEditDistance(); if(edits < bestEdits) bestEdits = edits; editsVector.push_back(edits); } int leafID = 0; int threshold = 1; for(STNodePtrList::iterator iter = m_leaves.begin(); iter != m_leaves.end(); ++iter) { if(editsVector[leafID] <= bestEdits + threshold) newLeaves.push_back(*iter); leafID += 1; } m_leaves = newLeaves; }
pair<DoubleVectorVector,IntVector> readJF(string filename) { igzstream is; is.open(filename.c_str()); if(!is.good()) { ERR << "Reading from " << filename << endl; exit(20); } DoubleVectorVector resultData; IntVector resultClasses; int maxCls; uint dim; int cls=0; DoubleVector *tmpDblVec; if(is.good() && is) { is >> maxCls >> dim; while(cls != -1) { double tmpDbl; tmpDblVec=new DoubleVector(dim); is >> cls; if(cls !=-1) { for(uint i=0;i<dim;++i) { is >> tmpDbl; (*tmpDblVec)[i]=tmpDbl; } resultClasses.push_back(cls); resultData.push_back(tmpDblVec); } } is.close(); }
void ParticleSystem::update() { mMonitor->addSample(mUsed.size()); typedef vector<int> IntVector; IntVector removeParticles; // Iterator over each particle, making its callback. If callback returns true, puts its index into the removeParticles list. for(uint32_t i = 0; i<mUsed.size(); ++i) { Particle* p = mUsed[i]; if(p->mCallback(p, this) == false) { removeParticles.push_back(i); } } // Now iterate over remove list and the particles. for(uint32_t i=0; i < removeParticles.size(); ++i) { // Get a reference the particle. Every iteratation is going to remove one particle. // Which means the indexes stored in removeParticles are wrong. // To adjust, subtract from the stored index the number of particels we have already removed. uint32_t indexInUsed = removeParticles[i] - i; Particle* p = mUsed[indexInUsed]; gImageLibrary->unreference(p->mImage.getImage()); mUsed.erase(mUsed.begin() + indexInUsed); mAvailable.push_back(p); } }
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 main(int argc,const char **argv) { IntVector v; v.push_back(1); v.push_back(2); }
bool Enemy::isFieldVisible(float x1, float z1, int i, int j, int x, int z, TerrainType** surroundings) { IntVector fields; int imin, imax, jmin, jmax; if (i < AI_VIEW_DISTANCE) { imin = i; imax = AI_VIEW_DISTANCE; } else { imax = i; imin = AI_VIEW_DISTANCE; } if (j < AI_VIEW_DISTANCE) { jmin = j; jmax = AI_VIEW_DISTANCE; } else { jmax = j; jmin = AI_VIEW_DISTANCE; } for (int ii = imin; ii < imax; ii++) { for (int jj = jmin; jj < jmax; jj++) { if (surroundings[ii][jj] == BUILDING) fields.push_back((z + jj - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + ii - AI_VIEW_DISTANCE)); } } return isVisible(x1, z1, x + i - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f, z + j - AI_VIEW_DISTANCE - FIELD_SIZE / 2 + 0.5f, fields); }
int main(int argc, char *argv[]) { // Test array-array inner product double v1 [5] = {0, 1, 2, 3, 4}; double v2 [5] = {4, 3, 2, 1, 0}; double result = 10; int len = 5; assert(innerProduct(v1,v2,len)==result && "tools - innerProduct, array-array gave an unexpected result"); // Test vector-vector inner product std::vector<double> vv1, vv2; for (int i=0;i<len;i++) { vv1.push_back(v1[i]); vv2.push_back(v2[i]); } assert(innerProduct(vv1,vv2)==result && "tools - innerProduct, vector-vector gave an unexpected result"); // Test Vector-Vector inner product Vector vvv1, vvv2; for (int i=0;i<len;i++) { vvv1.push_back(vv1); vvv2.push_back(vv2); } assert(innerProduct(vvv1,vvv2)==(len*result) && "tools - innerProduct, Vector-Vector gave an unexpected result"); // Test sparse Vector-Vector inner product IntVector sparse; for (int i=0;i<len;i++) { sparse.push_back(std::vector<int>()); sparse[i].push_back(i); } assert(innerProduct(vvv1,vvv2,sparse)==result && "tools - innerProduct, sparse Vector-Vector gave an unexpected result"); return 0; }
void generateBacktrack(IntVector& current_set, unsigned n) { unsigned csum = std::accumulate(current_set.begin(), current_set.end(), 0); if (csum > n) { //discard this solution return; } if (csum == n) //if solution, print it { processSolution(current_set); } else { IntVector candidates = getCandidates(current_set, n, csum); for (unsigned i =0; i < candidates.size(); ++i) { current_set.push_back(candidates.at(i)); generateBacktrack(current_set, n); current_set.pop_back(); } } }
IntVector CJsonReader::getIntVectorFromProperty(String property) { IntVector tmp; BOOST_FOREACH(ptree::value_type &v, m_data.get_child(property)) tmp.push_back(boost::lexical_cast<int>(v.second.data())); return tmp; }
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! }
void chain(const IntVector &path) { chain_lengths_.push_back(path.size()-1); for(IntVector::size_type position=0; position<path.size(); ++position) { IntVector::const_reference node = path[position]; counts_[node][position] += 1; } }
IntVector NIVissimConnection::getWithin(const AbstractPoly &poly) { IntVector ret; for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) { if ((*i).second->crosses(poly)) { ret.push_back((*i).second->myID); } } return ret; }
std::vector<int> OSArgument::domainAsInteger() const { if (!hasDomain()) { LOG_AND_THROW("No domain set for OSArgument '" << name() << "'."); } IntVector result; for (const QVariant& value : m_domain) { result.push_back(value.toInt()); } return result; }
IntVector tokenize(const std::string& str, char delim, char group) { IntVector tokens; if(str.empty()) { return tokens; } int curr = 0; int start = 0; start = curr = static_cast<int>(str.find_first_not_of(delim)); while(str[curr]) { if(str[curr] == group) { curr = static_cast<int>(str.find_first_of(group, curr+1)); if((size_t)curr == std::string::npos) { return IntVector(); } std::string token = str.substr(start+1, curr-start-1); tokens.push_back(makeInt32(token)); start = curr + 1; } else if(str[curr] == delim) { if(str[curr-1] != delim && str[curr-1] != group) { std::string token = str.substr(start, curr-start); tokens.push_back(makeInt32(token)); } start = curr + 1; } ++curr; } if(tokens.size() == 0) { tokens.push_back(makeInt32(str)); return tokens; } if(str[curr-1] != delim && str[curr-1] != group) { std::string token = str.substr(start, curr - 1); tokens.push_back(makeInt32(token)); } return tokens; }
FeedForwardNetwork& addNodePtr(NodeType *nodePtr) { mNodes.emplace_back(nodePtr); // TODO: Throw exception of node.getOutSizes() has >1 length int size = nodePtr->getOutSizes()[0]; mNodeSizes.push_back(size); this->setOutSizes(1, &size); return *this; }
void readIntVector( ContainerNode &node, const string &array_name, IntVector &v) throw(Error) { ContainerNode array_node = node.readArray(array_name); v.resize(0); while (array_node.hasUnread()) { v.push_back((int)array_node.readNumber()); } }
IntVector DijkstraPlanner::Plan(int start, int goal, const PlanningGraph &graph) const { IntVector path; int num_vertices = graph.num_vertices(); if (start < 0 || start >= num_vertices || goal < 0 || goal >= num_vertices) { throw std::invalid_argument("Invalid vertex id."); } IndexPriorityQueue<double> prique; std::map<int, int> came_from; std::map<int, std::list<EdgeNode*> > adjlist = graph.adjlist(); RealVector dist(graph.num_vertices()); dist[start] = 0.0; for (int i = 0; i < num_vertices; ++i) { if (i != start) { dist[i] = std::numeric_limits<double>::max(); } prique.Push(i, dist[i]); } while (!prique.Empty()) { int current = prique.Pop(); for (std::list<EdgeNode*>::iterator iter = adjlist[current].begin(); iter != adjlist[current].end(); ++iter) { int neighbor = static_cast<PlanningEdgeNode*>(*iter)->target(); double temp_dist = dist[current] + graph.EdgeWeight(current, neighbor); if (temp_dist < dist[neighbor]) { dist[neighbor] = temp_dist; came_from[neighbor] = current; prique.Update(neighbor, dist[neighbor]); } } } int current = goal; path.push_back(current); while (current != start) { current = came_from[current]; path.push_back(current); } std::reverse(path.begin(), path.end()); return path; }
void generateBacktrack(IntVector& current_set, unsigned n) { if (current_set.size() == n) //if solution, print it { processSolution(current_set); } else { IntVector candidates; candidates.push_back(0); candidates.push_back(1); for (unsigned i =0; i < candidates.size(); ++i) { current_set.push_back(candidates.at(i)); generateBacktrack(current_set, n); current_set.pop_back(); } } }
std::vector<int> MeasureGroup_Impl::validValues(bool selectedOnly) const { IntVector result; if (selectedOnly) { int index(0); for (const Measure& measure : measures(false)) { if (measure.isSelected()) { result.push_back(index); } ++index; } } else { for (int i = 0, n = numMeasures(false); i < n; ++i) { result.push_back(i); } } return result; }
inline void IndexedList::insert(size_t const&e) { /// si l'element n'est pas deja dans la liste if (!contains(e)) { // DEBUG_TRACE("add "<<e<<std::endl); _element[e] = size(); _list.push_back(e); } // check(); // TRACE_N(size()); // TRACE_N(max_size()); // DEBUG_ASSERT("NO REALLOCATION ALLOWED"&&size()<=max_size()); }