/* * Scheduler.h * @brief an example how inference can be used for scheduling qualifiers * @date Mar 26, 2011 * @author Frank Dellaert */ #include #include #include #include #include #include #include #include #include #include namespace gtsam { using namespace std; Scheduler::Scheduler(size_t maxNrStudents, const string& filename): maxNrStudents_(maxNrStudents) { typedef boost::tokenizer > Tokenizer; // open file ifstream is(filename.c_str()); if (!is) { cerr << "Scheduler: could not open file " << filename << endl; throw runtime_error("Scheduler: could not open file " + filename); } string line; // buffer // process first line with faculty if (getline(is, line, '\r')) { Tokenizer tok(line); Tokenizer::iterator it = tok.begin(); for (++it; it != tok.end(); ++it) addFaculty(*it); } // for all remaining lines size_t count = 0; while (getline(is, line, '\r')) { if (count++ > 100) throw runtime_error("reached 100 lines, exiting"); Tokenizer tok(line); Tokenizer::iterator it = tok.begin(); addSlot(*it++); // add slot // add availability for (; it != tok.end(); ++it) available_ += (it->empty()) ? "0 " : "1 "; available_ += '\n'; } } // constructor /** addStudent has to be called after adding slots and faculty */ void Scheduler::addStudent(const string& studentName, const string& area1, const string& area2, const string& area3, const string& advisor) { assert(nrStudents() area) const { return area ? students_[s].keys_[*area] : students_[s].key_; } const string& Scheduler::studentName(size_t i) const { assert(i slot) { bool debug = ISDEBUG("Scheduler::buildGraph"); assert(iat(j); cout << studentName(s) << " slot: " << slotName_[slot] << endl; Index base = 3*s; for (size_t area = 0; area < 3; area++) { size_t faculty = assignment->at(base+area); cout << setw(12) << studentArea(s,area) << ": " << facultyName_[faculty] << endl; } cout << endl; } } /** Special print for single-student case */ void Scheduler::printSpecial(sharedValues assignment) const { Values::const_iterator it = assignment->begin(); for (size_t area = 0; area < 3; area++, it++) { size_t f = it->second; cout << setw(12) << it->first << ": " << facultyName_[f] << endl; } cout << endl; } /** Accumulate faculty stats */ void Scheduler::accumulateStats(sharedValues assignment, vector< size_t>& stats) const { for (size_t s = 0; s < nrStudents(); s++) { Index base = 3*s; for (size_t area = 0; area < 3; area++) { size_t f = assignment->at(base+area); assert(frbegin(); const Student & student = students_.front(); cout << endl; (*it)->print(student.name_); } tic(3, "my_optimize"); sharedValues mpe = optimize(*chordal); toc(3, "my_optimize"); return mpe; } /** find the assignment of students to slots with most possible committees */ Scheduler::sharedValues Scheduler::bestSchedule() const { sharedValues best; throw runtime_error("bestSchedule not implemented"); return best; } /** find the corresponding most desirable committee assignment */ Scheduler::sharedValues Scheduler::bestAssignment( sharedValues bestSchedule) const { sharedValues best; throw runtime_error("bestAssignment not implemented"); return best; } } // gtsam