void processNode(Knapsack* ks, Heap* h, Node* n) { //printf("Process: value=%d, weight=%d, total value %d\n", item->_value, item->_weight, n->_value); char* x = (char*)malloc(sizeof(char)*(n->_depth+2)); int i; for (i=0; i<=n->_depth; i++) { x[i] = n->_x[i]; } Item* nextItem = ks->_items[n->_depth+1]; x[n->_depth+1] = 0; double est = upperBound(ks, n->_depth+2, n->_capacity); // Following the convention that choosing (x_i = 0) means "branch to the right" // Rounding up. double rightUB = n->_value + est; Node* rightNode = initNode(n->_value, n->_depth+1, rightUB, n->_capacity, x); inspectNode(ks, h, rightNode); if (nextItem->_weight <= n->_capacity) { x = (char*)malloc(sizeof(char)*(n->_depth+2)); for (i=0; i<=n->_depth; i++) { x[i] = n->_x[i]; } x[n->_depth+1] = 1; int leftValue = n->_value + nextItem->_value; int leftCapacity = n->_capacity - nextItem->_weight; est = upperBound(ks, n->_depth+2, leftCapacity); double leftUB = leftValue + est; Node* leftNode = initNode(leftValue, n->_depth+1, leftUB, leftCapacity, x); inspectNode(ks, h, leftNode); } destroyNode(n); }
bool EpidemicDataSet::copyVariableToNewTimeStep(std::string varName) { if(variables_.count(varName) == 0) { put_flog(LOG_ERROR, "no such variable %s", varName.c_str()); return false; } // get current shape of variable blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> shape = variables_[varName].shape(); // add a time step shape(0) = shape(0) + 1; // resize variable for the new shape variables_[varName].resizeAndPreserve(shape); // copy data to the new time step // the full domain blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> lowerBound = variables_[varName].lbound(); blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> upperBound = variables_[varName].ubound(); // domain for previous time and new time lowerBound(0) = upperBound(0) = variables_[varName].extent(0) - 2; blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain0(lowerBound, upperBound); lowerBound(0) = upperBound(0) = variables_[varName].extent(0) - 1; blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain1(lowerBound, upperBound); // make the copy variables_[varName](subdomain1) = variables_[varName](subdomain0); return true; }
float EpidemicDataSet::getValue(const std::string &varName, const int &time, const int &nodeId, const std::vector<int> &stratificationValues) { // handle derived variables if(derivedVariables_.count(varName) > 0) { return derivedVariables_[varName](time, nodeId, stratificationValues); } if(variables_.count(varName) == 0) { put_flog(LOG_ERROR, "no such variable %s (nodeId = %i)", varName.c_str(), nodeId); return 0.; } else if(nodeId != NODES_ALL && nodeIdToIndex_.count(nodeId) == 0) { put_flog(LOG_ERROR, "could not map nodeId %i to an index (varName = %s)", nodeId, varName.c_str()); return 0.; } // the variable we're getting blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> variable = variables_[varName]; // the full domain blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> lowerBound = variable.lbound(); blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> upperBound = variable.ubound(); // make sure this variable is valid for the specified time if(time < lowerBound(0) || time > upperBound(0)) { put_flog(LOG_WARN, "variable %s not valid for time %i", varName.c_str(), time); return 0.; } // limit by time lowerBound(0) = upperBound(0) = time; // limit by node if(nodeId != NODES_ALL) { lowerBound(1) = upperBound(1) = nodeIdToIndex_[nodeId]; } // limit by stratification values for(unsigned int i=0; i<stratificationValues.size(); i++) { if(stratificationValues[i] != STRATIFICATIONS_ALL) { lowerBound(2+i) = upperBound(2+i) = stratificationValues[i]; } } // the subdomain blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain(lowerBound, upperBound); // return the sum of the array over the subdomain return blitz::sum(variable(subdomain)); }
int upperBound(int left, int right, const int value, vector<int> const& container) { if(left >= right) { return left; } int mid = left + (right - left) / 2; if(value < container[mid]) { return upperBound(left, mid, value, container); } else if(value >= container[mid]) { return upperBound(mid + 1, right, value, container); } }
double Master::guarantee() const { double lb = lowerBound(); if (fabs(lb) < machineEps()) { if (fabs(upperBound()) < machineEps()) return 0.0; else { Logger::ifout() << "Master::guarantee(): cannot compute guarantee with lower bound 0\n"; OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::AlgorithmFailureCode::IllegalParameter); } } return fabs((upperBound() - lb)/lb * 100.0); }
double QwtAbstractSlider::alignedValue( double value ) const { if ( d_data->totalSteps == 0 ) return value; double stepSize; if ( scaleMap().transformation() == NULL ) { stepSize = ( maximum() - minimum() ) / d_data->totalSteps; if ( stepSize > 0.0 ) { value = lowerBound() + qRound( ( value - lowerBound() ) / stepSize ) * stepSize; } } else { stepSize = ( scaleMap().p2() - scaleMap().p1() ) / d_data->totalSteps; if ( stepSize > 0.0 ) { double v = scaleMap().transform( value ); v = scaleMap().p1() + qRound( ( v - scaleMap().p1() ) / stepSize ) * stepSize; value = scaleMap().invTransform( v ); } } if ( qAbs( stepSize ) > 1e-12 ) { if ( qFuzzyCompare( value + 1.0, 1.0 ) ) { // correct rounding error if value = 0 value = 0.0; } else { // correct rounding error at the border if ( qFuzzyCompare( value, upperBound() ) ) value = upperBound(); else if ( qFuzzyCompare( value, lowerBound() ) ) value = lowerBound(); } } return value; }
void AngleMap::getGmaIndexes( const Range& rgeGma, const std::vector<int>*& indexes, int& minIndex, int& maxIndex) const { indexes = &gmaIndexes_; minIndex = lowerBound(gmas_, rgeGma.min, 0, gmas_.size()); maxIndex = upperBound(gmas_, rgeGma.max, 0, gmas_.size()); }
void Box<DATA>::adjust ( int a_rows, int a_cols ) { INVARIANT((a_rows>=0) && (a_cols>=0),"non negative bbox size"); int old_rows(lowerBound.rows()); int old_cols(lowerBound.cols()); if ((old_rows==a_rows) && (old_cols==a_cols)) return; lowerBound.adjust(a_rows,a_cols); upperBound.adjust(a_rows,a_cols); // if size grows, set constants for (int r=0;r<lowerBound.rows();++r) { for (int c=0;c<lowerBound.cols();++c) { if ((r>=old_rows) || (c>=old_cols)) { lowerBound(r,c) = Constants<typename DATA::value_type>().max(); upperBound(r,c) = Constants<typename DATA::value_type>().min(); } } } // for r }
int VeloList::nextVelo(int tick) const { if (empty()) return 80; VeloList::const_iterator i = upperBound(tick); return i.value().val; }
int AbstractArray::isEqual( const Object& obj ) const { PRECONDITION( isA() == obj.isA() ); AbstractArray& test = (AbstractArray&)obj; if( lowerBound() != test.lowerBound() || upperBound() != test.upperBound() ) return 0; ContainerIterator& iter1 = initIterator(); ContainerIterator& iter2 = test.initIterator(); while( iter1 && iter2 ) if( iter1.current() != iter2.current() ) { delete &iter1; delete &iter2; return 0; } else { iter1++; iter2++; } delete &iter1; delete &iter2; return 1; }
rocksdb::Iterator* RocksRecoveryUnit::NewIteratorNoSnapshot(rocksdb::DB* db, std::string prefix) { std::unique_ptr<rocksdb::Slice> upperBound(new rocksdb::Slice()); rocksdb::ReadOptions options; options.iterate_upper_bound = upperBound.get(); auto iterator = db->NewIterator(options); return new PrefixStrippingIterator(std::move(prefix), iterator, nullptr, std::move(upperBound)); }
double RTBSS<M>::simulate(const Belief & b, unsigned horizon) { if ( horizon == 0 ) return 0; std::vector<size_t> actionList(A); // Here we use no heuristic to sort the actions. If you want one // add it here! std::iota(std::begin(actionList), std::end(actionList), 0); double max = -std::numeric_limits<double>::infinity(); for ( auto a : actionList ) { double rew = beliefExpectedReward(model_, b, a); double uBound = rew + upperBound(b, a, horizon - 1); if ( uBound > max ) { for ( size_t o = 0; o < O; ++o ) { double p = beliefObservationProbability(model_, b, a, o); // Only work if it makes sense if ( checkDifferentSmall(p, 0.0) ) rew += model_.getDiscount() * p * simulate(updateBelief(model_, b, a, o), horizon - 1); } } if ( rew > max ) { max = rew; if ( horizon == maxDepth_ ) maxA_ = a; } } return max; }
// ----------------------------------------------------------------------------- // UnicodeTextUtil::ConvertASCIIInPlace // Converts all ASCII *in-place* from either Half to Full-width or vice versa, // depending on the direction specified by aDirection. // Returns: The total number of characters converted. // ----------------------------------------------------------------------------- // TInt UnicodeTextUtil::ConvertASCIIInPlace( TConvDirection aDirection, TDes16& aUnicodeText ) { TInt totalConverted( 0 ); TText lowerBound( ( aDirection == EHalfToFullWidth ) ? KHalfWidthASCIILowerBound : KFullWidthASCIILowerBound ); TText upperBound( ( aDirection == EHalfToFullWidth ) ? KHalfWidthASCIIUpperBound : KFullWidthASCIIUpperBound ); TInt offset( ( aDirection == EHalfToFullWidth ) ? KHalfToFullWidthASCIIOffset : -KHalfToFullWidthASCIIOffset ); for( TInt i( 0 ); i < aUnicodeText.Length(); ++i ) { const TText uniChar( aUnicodeText[i] ); if( uniChar >= lowerBound && uniChar <= upperBound ) { TText convertedChar( static_cast<TText>( uniChar + offset ) ); aUnicodeText[i] = convertedChar; totalConverted++; } } return totalConverted; }
void Box<DATA>::include ( const DATA& ar_DataVector ) { // enlarge bbox if necessary adjust(max(rows(),ar_DataVector.rows()),max(cols(),ar_DataVector.cols())); typename DATA::value_type value; for (int r=0;r<ar_DataVector.rows();++r) { for (int c=0;c<ar_DataVector.cols();++c) { value = ar_DataVector(r,c); if (lowerBound(r,c) > value) { lowerBound(r,c) = value; } if (upperBound(r,c) < value) { upperBound(r,c) = value; } } // for c } // for r }
bool Master::guaranteed() const { if (fabs(lowerBound()) < machineEps() && fabs(upperBound()) > machineEps()) return false; if (guarantee() + machineEps() < requiredGuarantee_) return true; else return false; }
ClefTypeList ClefList::clef(int tick) const { if (empty()) return ClefTypeList(CLEF_G, CLEF_G); ciClefEvent i = upperBound(tick); if (i == begin()) return ClefTypeList(CLEF_G, CLEF_G); --i; return i.value(); }
void Master::printGuarantee() const // warning: this should only be called if it has already been ensured that logging allows this output! { double lb = lowerBound(); double ub = upperBound(); if (lb == -infinity() || ub == infinity() || ((fabs(lb) < machineEps()) && (fabs(ub) > machineEps()))) Logger::ifout() << "---"; else Logger::ifout() << guarantee() << '%'; }
vector<int> searchRange(vector<int>& nums, int target) { int n = nums.size(); vector<int> vt(2,-1); if( n < 1 ) return vt; int low = lowerBound(nums, target); if( low >= 0 ){ vt[0] = low; vt[1] = upperBound(nums, target); } return vt; }
void Inlet1D:: save(XML_Node& o, doublereal* soln) { doublereal* s = soln + loc(); XML_Node& inlt = o.addChild("domain"); inlt.addAttribute("id",id()); inlt.addAttribute("points",1); inlt.addAttribute("type","inlet"); inlt.addAttribute("components",nComponents()); for (int k = 0; k < nComponents(); k++) { ctml::addFloat(inlt, componentName(k), s[k], "", "",lowerBound(k), upperBound(k)); } }
void Box<DATA>::enlarge_percent ( TData a_percent ) { int r; for (r=0;r<lowerBound.rows();++r) { lowerBound(r) -= length(r)*a_percent/100.0; upperBound(r) += length(r)*a_percent/100.0; } }
void Box<DATA>::reset ( ) { for (int r=0;r<lowerBound.rows();++r) { for (int c=0;c<lowerBound.cols();++c) { lowerBound(r,c) = Constants<typename DATA::value_type>().max(); upperBound(r,c) = Constants<typename DATA::value_type>().min(); } } // for r }
SEXP getMZ(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange, SEXP scanrange, SEXP lastscan) { double *pmz, *pintensity,*p_res, mzrangeFrom,mzrangeTo; int i,*pscanindex,scanrangeFrom, scanrangeTo,ilastScan,nmz,ctScan,buflength; SEXP res; pmz = REAL(mz); nmz = GET_LENGTH(mz); pintensity = REAL(intensity); pscanindex = INTEGER(scanindex); int firstScan = 1; // is always 1 ilastScan = INTEGER(lastscan)[0]; mzrangeFrom = REAL(mzrange)[0]; mzrangeTo = REAL(mzrange)[1]; scanrangeFrom = INTEGER(scanrange)[0]; scanrangeTo = INTEGER(scanrange)[1]; if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) || (scanrangeTo < firstScan) || (scanrangeTo > ilastScan)) error("Error in scanrange \n"); buflength = scanrangeTo - scanrangeFrom +1; PROTECT(res = NEW_NUMERIC(buflength)); p_res = NUMERIC_POINTER(res); i=0; for (ctScan=scanrangeFrom;ctScan<=scanrangeTo;ctScan++) { int idx,idx1,idx2; idx1 = pscanindex[ctScan -1] +1; if (ctScan == ilastScan) idx2 = nmz-1; else idx2 = pscanindex[ctScan]; int idx1b = lowerBound(mzrangeFrom, pmz, idx1-1, idx2-idx1-1); int idx2b = upperBound(mzrangeTo, pmz, idx1b, idx2-idx1b-1); int pc=0; p_res[i]=0; for (idx=idx1b;idx <= idx2b; idx++) { double mzval = pmz[idx]; if ((mzval <= mzrangeTo) && (mzval >= mzrangeFrom)) { if (pc==0) p_res[i] = mzval; else p_res[i] = ((pc * p_res[i]) + mzval) / (pc+1); pc++; } } i++; } UNPROTECT(1); return(res); }
void addRegion(trace::Call &call, unsigned long long address, void *buffer, unsigned long long size) { if (retrace::verbosity >= 2) { std::cout << "region " << std::hex << "0x" << address << "-0x" << (address + size) << " -> " << "0x" << (uintptr_t)buffer << "-0x" << ((uintptr_t)buffer + size) << std::dec << "\n"; } if (!address) { // Ignore NULL pointer assert(buffer == nullptr); return; } const bool debug = #ifdef NDEBUG false #else true #endif ; if (debug) { RegionMap::iterator start = lowerBound(address); RegionMap::iterator stop = upperBound(address + size - 1); if (0) { // Forget all regions that intersect this new one. regionMap.erase(start, stop); } else { for (RegionMap::iterator it = start; it != stop; ++it) { warning(call) << std::hex << "region 0x" << address << "-0x" << (address + size) << " " "intersects existing region 0x" << it->first << "-0x" << (it->first + it->second.size) << "\n" << std::dec; assert(intersects(it, address, size)); } } } assert(buffer); Region region; region.buffer = buffer; region.size = size; regionMap[address] = region; }
/*! \brief Calculate the filled rectangle of the pipe \param pipeRect Rectangle of the pipe \return Rectangle to be filled ( fill and alarm brush ) \sa pipeRect(), alarmRect() */ QRect QwtThermo::fillRect( const QRect &pipeRect ) const { double origin; if ( d_data->originMode == OriginMinimum ) { origin = qMin( lowerBound(), upperBound() ); } else if ( d_data->originMode == OriginMaximum ) { origin = qMax( lowerBound(), upperBound() ); } else // OriginCustom { origin = d_data->origin; } const QwtScaleMap scaleMap = scaleDraw()->scaleMap(); int from = qRound( scaleMap.transform( d_data->value ) ); int to = qRound( scaleMap.transform( origin ) ); if ( to < from ) qSwap( from, to ); QRect fillRect = pipeRect; if ( d_data->orientation == Qt::Horizontal ) { fillRect.setLeft( from ); fillRect.setRight( to ); } else // Qt::Vertical { fillRect.setTop( from ); fillRect.setBottom( to ); } return fillRect.normalized(); }
void solve(Point p1, Point p2) { if (p1.y == p2.y) return; if (p1.y > p2.y) { Point tmp = p1; p1 = p2; p2 = tmp; } for (int i = upperBound(p1.y); i <= lowerBound(p2.y); i++) if (i > 0 && i < 100) { double v = findX(p1,i,p2); if (maxX[i] < v) maxX[i] = v; if (minX[i] > v) minX[i] = v; } }
rocksdb::Iterator* RocksRecoveryUnit::NewIterator(std::string prefix, bool isOplog) { std::unique_ptr<rocksdb::Slice> upperBound(new rocksdb::Slice()); rocksdb::ReadOptions options; options.iterate_upper_bound = upperBound.get(); options.snapshot = snapshot(); auto iterator = _db->NewIterator(options); if (_writeBatch && _writeBatch->GetWriteBatch()->Count() > 0) { iterator = _writeBatch->NewIteratorWithBase(iterator); } return new PrefixStrippingIterator(std::move(prefix), iterator, isOplog ? nullptr : _compactionScheduler, std::move(upperBound)); }
int VeloList::velo(int tick) const { if (empty()) return 80; VeloList::const_iterator i = upperBound(tick); if (i == constBegin()) return 80; VeloList::const_iterator ii = i - 1; if (ii.value().type == VELO_FIX) return ii.value().val; int tickDelta = i.key() - ii.key(); int veloDelta = i.value().val - ii.value().val; return ii.value().val + ((tick-ii.key()) * veloDelta) / tickDelta; }
bool Box<DATA>::encloses ( const DATA& ar_DataVector ) { bool inside = true; for (int r=0;r<ar_DataVector.rows();++r) { for (int c=0;c<ar_DataVector.cols();++c) { inside &= (lowerBound(r,c) <= ar_DataVector(r,c)); inside &= (upperBound(r,c) >= ar_DataVector(r,c)); } } // for r return inside; }
void Box<DATA>::enlarge_1_to_1 ( ) { typename DATA::value_type l(0); int r; for (r=0;r<lowerBound.rows();++r) { l = max(l,length(r)); } for (r=0;r<lowerBound.rows();++r) { lowerBound(r) -= (l-length(r))/2.0; upperBound(r) += (l-length(r))/2.0; } }
/*! \brief Determine the value for a new position of the slider handle. \param pos Mouse position \return Value for the mouse position \sa isScrollPosition() */ double QwtSlider::scrolledTo( const QPoint &pos ) const { int p = ( orientation() == Qt::Horizontal ) ? pos.x() : pos.y(); p -= d_data->mouseOffset; int min = transform( lowerBound() ); int max = transform( upperBound() ); if ( min > max ) qSwap( min, max ); p = qBound( min, p, max ); return scaleMap().invTransform( p ); }