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; }
IntervalScheduler::IntervalScheduler(Intervals &inputIntervals) : n(inputIntervals.size()), bestGeneScore(vector<double>(n+1, 0)), p(vector<size_t>(n+1, 0)) { sort(inputIntervals.begin(), inputIntervals.end()); // We want the gene list to start at index 1 ivals.push_back(WeightedInterval(-1,-1,-1)); for (auto i : inputIntervals) ivals.push_back(i); for (size_t j = 1; j < n+1; j++) { p[j] = previousDisjointInterval(j); } }
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); }
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; }
void Intervals::unionize() { std::sort(begin(), end(), compare); for (int i = 0; i < size(); i++) { for (int j = i + 1; j < size(); j++) { Intervals temp = _int[i].unionize(_int[j]); //std::cout << ints[i] << " " << ints[j] << std::endl; //std::cout << "unioned: " << temp << std::endl; if (temp.size() == 1) { auto b = begin() + j; _int.erase(b); _int[i] = temp[0]; j = i; } } } }
// Given some number of polynomials (where each polynomial c0*t^n + // + c1*t^(n-1) + ... + cn is represented by the std::vector containing // (c0, c1, ..., cn), find the first time t >= 0 for which: // 1. Each polynomial is >= 0 at t; // 2. Each polynomial is > 0 at t + any sufficiently small number epsilon. // If no such time exists, returns infinity instead. // // Does not need to be changed by students. double PolynomialIntervalSolver::findFirstIntersectionTime(const std::vector<Polynomial> &polys) { s_polynomials.insert(s_polynomials.end(), polys.begin(), polys.end()); if(polys.size() == 0) return std::numeric_limits<double>::infinity(); std::vector<Polynomial>::const_iterator it = polys.begin(); Intervals inter = findPolyIntervals(*it); for(++it; it != polys.end(); ++it) { Intervals nextint = findPolyIntervals(*it); inter = intersect(inter, nextint); } return inter.findNextSatTime(0.0); }
// busy intervals are produced from Intervals.fixed void ScheduleToXML::BusyToXML(ofstream &f){ int inc = 0; // for each resource type for (unsigned i = 0; i < data.resources.size(); i++){ Intervals windows; // get intervals of this resource type data.resources[i].GetCurrentWindows(windows); // get fixed intervals vector <BusyIntervals> fixed = windows.GetFixedIntervals(); // for each resource for (unsigned j = 0; j < fixed.size(); j++){ // get pointer to resource's intervals BusyIntervals::iterator bIt = fixed[j].begin(); // loop on different cores for (;bIt != fixed[j].end(); bIt++){ int coreNum = bIt->first-1; coreNum += inc; // loop on different intervals for (vector<pair<int,int>>::size_type k = 0; k < bIt->second.size(); k++){ int tBegin = bIt->second[k].first; int tEnd = bIt->second[k].second; f << "\t\t<node_statistics>" << endl; f << "\t\t <node_property name=\"id\" value=\""<< coreNum <<"\"/>" << endl; f << "\t\t <node_property name=\"type\" value=\"busy\"/>" << endl; f << "\t\t <node_property name=\"start_time\" value=\"" << tBegin << "\"/>" << endl; f << "\t\t <node_property name=\"end_time\" value=\"" << tEnd << "\"/>" << endl; f << "\t\t <configuration>" << endl; f << "\t\t <conf_property name=\"cluster_id\" value=\"0\"/>" << endl; f << "\t\t <conf_property name=\"host_nb\" value=\"1\"/>" << endl; f << "\t\t <host_lists>" << endl; f << "\t\t <hosts start=\"" << coreNum << "\" nb=\"1\"/>" << endl; f << "\t\t </host_lists>" << endl; f << "\t\t </configuration>" << endl; f << "\t\t</node_statistics>" << endl; } } inc += fixed[j].size(); } } }
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; }
Scheduler::Scheduler( ModelData& md ): data(md.GetData()) { methodsSet.resize(data.GetWFCount()); maxEff = 0.0; xmlWriter = unique_ptr<ScheduleToXML>(new ScheduleToXML(data)); data.SetWfPriorities(); eff = unique_ptr<Efficiency>(new Efficiency(2.00 / data.GetprocessorsCount(), data.GetT())); maxPossible = 0.0; for (int i = 0; i < data.GetResourceCount(); i++){ Intervals initIntervals; data.Resources(i).GetCurrentWindows(initIntervals); vector <BusyIntervals> current; current = initIntervals.GetCurrentIntervals(); for (int j = 0; j < current.size(); j++){ BusyIntervals & processorIntervals = current[j]; for (auto it = processorIntervals.begin(); it != processorIntervals.end(); it++){ for (int k = 0; k < it->second.size(); k++){ maxPossible += eff->EfficiencyByPeriod(1, it->second[k].first, it->second[k].second); } } } } maxPossible = 1.00 - maxPossible; }
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; }
// Static solve function, returns a list of interval indexes that spans the // first input, returns an empty list if no such collection exists. // Throws a range_error if any interval [a, b] has [b < a] static vector<int> Solve(Interval a, Intervals const & v) { // check input if(!validateInput(a, v)) throw range_error("Invalid interval ranges"); // sort by lower bound and keep reference to original order typedef pair<Interval, int> P; // pair of interval and original index vector<P> p; rep(i, 0, (int)v.size()) p.push_back(P(v[i], i)); sort(all(p)); // solve the problem vector<int> ret; D minVal = a.first; typename vector<P>::iterator from = p.begin(); // while interval is not covered while(minVal < a.second || minVal == a.second && ret.empty()) { // find intervals which includes left boundary, pick the one with the // highest right boundary int index = -1; D maxVal = minVal; for(auto curr = from; curr != p.end(); ++curr) { D f = curr->first.first, t = curr->first.second; if(f <= minVal) { if(t > maxVal || ret.empty() && t == maxVal) { maxVal = t; index = curr->second; } continue; } from = curr; break; } // if no such vector can be found problem is unsolvable if(index == -1) return vector<int>(); // otherwise add vector to answer and repeat ret.push_back(index); minVal = maxVal; } return ret; }
void Intervals::difference(Intervals is) { for (int i = 0; i < size(); i++) { for (int j = 0; j < is.size(); j++) { Intervals temp = _int[i].difference(is[j]); if (temp.size() > 1) { erase(begin() + i); insert(begin() + i, temp.begin(), temp.end()); } else if (temp.size() == 0) { erase(begin() + i); } else if (temp[0] != _int[i]) { _int[i] = temp[0]; } } } }
void Intervals::cat(Intervals i) { _int.insert(end(), i.begin(), i.end()); }
int EvalExpAndCounts(PilParams ¶ms, double tmin, double tmax, int &countscalc, double &expcalc) { int timestep = 1; Intervals intervals; if (!eval::LoadTimeList(params["timelist"], intervals, tmin, tmax)) { cerr << "Error loading timelist file '" << params["timelist"].GetStr() << "'" << endl; return EXIT_FAILURE; } cout << endl << "INPUT PARAMETERS:" << endl; params.Print(); double radius = params["radius"]; //mres double mdim = radius*sqrt(2); cout << "radius for evt: " << radius << " - mdim for exp: " << mdim << endl; double binstep = 1.0; const char *projection = "ARC"; cout << "Binstep: " << binstep << endl; cout << "Projection: " << projection << endl; cout << "INTERVALS N=" << intervals.Count() << ":" << endl; for (int i=0; i<intervals.Count(); i++) cout << " " << intervals[i].String() << endl; cout << "Selecting the events.." << endl; char selectionLogFilename[FLEN_FILENAME]; char templateLogFilename[FLEN_FILENAME]; tmpnam(selectionLogFilename); tmpnam(templateLogFilename); char *logfile = (char*) params["logfile"].GetStr(); if (logfile && logfile[0]=='@') logfile++; string logExpr = selection::LogExprString(intervals, params["phasecode"], timestep); cout << logExpr << endl; int status = selection::MakeSelection(logfile, intervals, logExpr, selectionLogFilename, templateLogFilename); if (status==-118) { cout << endl << "AG_lm5......................no matching events found" << endl; cout << endString << endl; return 0; } else if (status != 0) { cout << endl << "AG_lm5......................selection failed" << endl; cout << endString << endl; return 0; } cout << "Selecting the events.." << endl; char selectionEvtFilename[FLEN_FILENAME]; char templateEvtFilename[FLEN_FILENAME]; tmpnam(selectionEvtFilename); tmpnam(templateEvtFilename); char *evtfile = (char*) params["evtfile"].GetStr(); if (evtfile && evtfile[0]=='@') evtfile++; string evtExpr = selection::EvtExprString(intervals, params["emin"], params["emax"], params["albrad"], params["fovradmax"], params["fovradmin"], params["phasecode"], params["filtercode"]); status = selection::MakeSelection(evtfile, intervals, evtExpr, selectionEvtFilename, templateEvtFilename); if (status==-118) { cout << endl << "AG_lm5......................no matching events found" << endl; cout << endString << endl; return 0; } else if (status != 0) { cout << endl << "AG_lm5......................selection failed" << endl; cout << endString << endl; return 0; } double beginTime = tmin; double endTime = tmax; cout.setf(ios::fixed); cout << std::setprecision(2); cout << "***** " << beginTime << " " << endTime << " " << endl << endl; Interval timeSlot; timeSlot.Set(beginTime, endTime); #ifdef DEBUG cout << "Time slot beginTime: " << beginTime << " endTime: " << endTime << endl; #endif Intervals intervalSlots = Intersection(intervals, timeSlot); if (intervalSlots.Count()) { cout << "Selected slots:" << endl; for (int i=0; i<intervalSlots.Count(); i++) cout << " " << intervalSlots[i].Start() << " " << intervalSlots[i].Stop() << endl; vector< vector<double> > exposures; status = eval::EvalExposure("None", params["sarFileName"], params["edpFileName"], "None", projection, mdim, mdim, params["la"], params["ba"], params["lonpole"], params["albrad"], params["y_tol"], params["roll_tol"], params["earth_tol"], params["phasecode"], binstep, params["timestep"], params["index"], tmin, tmax, params["emin"], params["emax"], params["fovradmin"], params["fovradmax"], selectionLogFilename, templateLogFilename, intervalSlots, exposures, false); vector<int> counts; status = eval::EvalCountsInRadius("None", tmin, tmax, radius, params["la"], params["ba"], params["lonpole"], params["emin"], params["emax"], params["fovradmax"], params["fovradmin"], params["albrad"], params["phasecode"], params["filtercode"], selectionEvtFilename, templateEvtFilename, intervalSlots, counts); expcalc = 0; countscalc = 0; for (int slot=0; slot<intervalSlots.Count(); slot++) { expcalc += exposures[slot][0]; // the map is 1x1 countscalc += counts[slot]; } } else cout << "No intervals selected" << endl; FitsFile slogfile(selectionLogFilename); slogfile.Delete(); FitsFile tlogfile(templateLogFilename); tlogfile.Delete(); FitsFile sevtfile(selectionEvtFilename); sevtfile.Delete(); FitsFile tevtfile(templateEvtFilename); tevtfile.Delete(); if (status == -118) { cout << endl << "AG_lm5......................no matching events found" << endl; } else if (status != 0) { cout << endl << "AG_lm5...................... exiting with ERROR:"<< endl; fits_report_error(stdout, status); } cout << endString << endl; return status; }