inline Intervals toInterval(VarValue& v) { Intervals intervals; double y = _expr(v); switch (_r) { case Relation::Equal: intervals.push_back( Interval::closed(y,y)); break; case Relation::Greater: intervals.push_back( Interval::open(y,Limit::infinity())); break; case Relation::GreaterEqual: intervals.push_back( Interval::right_open(y,Limit::infinity())); break; case Relation::Less: //plu constraints are >=0 implicitly intervals.push_back( Interval::right_open(0,y)); break; case Relation::LessEqual: intervals.push_back( Interval::closed(0,y)); break; default: std::cerr<<"error: wrong relation type"; } return intervals; }
Intervals Interval::unionize(Interval& other) { Intervals result; if (isEmpty()) { result.push_back(other); return result; } else if (other.isEmpty()) { result.push_back(*this); return result; } else if (intersects(*this, other)) { //std::cout << "intersecting" << std::endl; Interval newInt(std::min(_min, other._min), std::max(_max, other._max)); result.push_back(newInt); return result; } else { if (_min < other._min) { result.push_back(*this); result.push_back(other); return result; } else { result.push_back(other); result.push_back(*this); return result; } } return result; }
void ZoomInfo::FindIntervals (double /*rate*/, Intervals &results, wxInt64 width, wxInt64 origin) const { results.clear(); results.reserve(2); const wxInt64 rightmost(origin + (0.5 + width)); wxASSERT(origin <= rightmost); { results.push_back(Interval(origin, zoom, false)); } if (origin < rightmost) results.push_back(Interval(rightmost, 0, false)); wxASSERT(!results.empty() && results[0].position == origin); }
DomainSet consensusDomains(WeightedDomainEnsemble& dEnsemble) { using PersistenceMap = map<Domain, double>; PersistenceMap pmap; for (auto dSetIdx : boost::irange(size_t{0}, dEnsemble.domainSets.size())) { auto& dSet = dEnsemble.domainSets[dSetIdx]; auto weight = dEnsemble.weights[dSetIdx]; for (auto& domain : dSet) { if ( pmap.find(domain) == pmap.end() ) pmap[domain] = 0; pmap[domain] += weight; } } Intervals ivals; for (auto domainPersistence : pmap) { auto domain = domainPersistence.first; auto persistence = domainPersistence.second; ivals.push_back(WeightedInterval(domain.start, domain.end, persistence)); } IntervalScheduler scheduler(ivals); scheduler.computeSchedule(); DomainSet dSet; for (auto ival : scheduler.extractIntervals()) { dSet.push_back(Domain(ival.start, ival.end)); } sort(dSet.begin(), dSet.end()); return dSet; }
Intervals IntervalScheduler::extractIntervals() { Intervals extracted; size_t j = bestGeneScore.size()-1; while (j > 0) { if (bestGeneScore[j] != bestGeneScore[j-1]) { extracted.push_back(ivals[j]); j = previousDisjointInterval(j); } else { j--; } } return extracted; }
Intervals Interval::difference(Interval& diff) { Intervals result; if (isEmpty()) { return result; } else if (diff.isEmpty()) { result.push_back(*this); return result; } if (intersects(*this, diff)) { if (_min < diff._min) { Interval temp(_min, diff._min); result.push_back(temp); } if (_max > diff._max) { Interval temp(diff._max, _max); result.push_back(temp); } } else { result.push_back(*this); } return result; }
void Intervals::intersect(Intervals is) { Intervals result; for (int i = 0; i < size(); i++) { if (_int[i].isEmpty()) continue; for (int j = 0; j < is.size(); j++) { if (is[j].isEmpty()) { continue; } if (Interval::intersects(_int[i], is[j])) { result.push_back(_int[i].intersect(is[j])); } } } _int = result._int; }