13 #include <boost/tokenizer.hpp> 24 maxNrStudents_(maxNrStudents)
26 typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
29 ifstream is(filename.c_str());
31 cerr <<
"Scheduler: could not open file " << filename << endl;
32 throw runtime_error(
"Scheduler: could not open file " + filename);
38 if (getline(is, line,
'\r')) {
40 Tokenizer::iterator it = tok.begin();
41 for (++it; it != tok.end(); ++it)
47 while (getline(is, line,
'\r')) {
48 if (count++ > 100)
throw runtime_error(
"reached 100 lines, exiting");
50 Tokenizer::iterator it = tok.begin();
53 for (; it != tok.end(); ++it)
61 const string& area1,
const string& area2,
62 const string& area3,
const string& advisor) {
112 if (debug) cout <<
"Adding availability of slots" << endl;
118 for (
size_t area = 0; area < 3; area++) {
121 const string& areaName = s.
areaName_[area];
123 if (debug) cout <<
"Area constraints " << areaName << endl;
127 if (debug) cout <<
"Advisor constraint " << areaName << endl;
128 assert(s.
advisor_.size()==areaKey.second);
131 if (debug) cout <<
"Availability of faculty " << areaName << endl;
146 if (debug) cout <<
"Mutex for faculty" << endl;
155 if (debug) cout <<
"Adding student-specific constraints" << endl;
161 "0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1");
166 dkeys.push_back(
s.key_);
169 if (debug) cout <<
"Mutex for Students" << endl;
170 for (
size_t i1 = 0; i1 <
nrStudents(); i1++) {
173 for (
size_t i2 = i1 + 1; i2 <
bound; i2++) {
182 cout << s <<
" Faculty:" << endl;
184 cout <<
name <<
'\n';
187 cout << s <<
" Slots:\n";
190 cout << i++ <<
" " << name << endl;
193 cout <<
"Availability:\n" <<
available_ <<
'\n';
195 cout << s <<
" Area constraints:\n";
198 cout << setw(12) << it.first <<
": ";
199 for(
double v: it.second)
205 cout << s <<
" Students:\n";
220 size_t slot = assignment->at(j);
223 for (
size_t area = 0; area < 3; area++) {
224 size_t faculty = assignment->at(base+area);
235 for (
size_t area = 0; area < 3; area++, it++) {
236 size_t f = it->second;
244 size_t>&
stats)
const {
247 for (
size_t area = 0; area < 3; area++) {
248 size_t f = assignment->at(base+area);
249 assert(f<
stats.size());
262 defaultKeyOrdering +=
Key(
i);
272 if (
ISDEBUG(
"Scheduler::optimalAssignment")) {
276 (*it)->print(student.
name_);
288 throw runtime_error(
"bestSchedule not implemented");
296 throw runtime_error(
"bestAssignment not implemented");
sharedValues optimalAssignment() const
void add(const DiscreteKey &j, SOURCE table)
Scheduler(size_t maxNrStudents)
sharedValues bestSchedule() const
sharedValues bestAssignment(sharedValues bestSchedule) const
std::vector< std::string > facultyName_
std::map< std::string, size_t > facultyIndex_
std::vector< std::string > slotName_
std::vector< DiscreteKey > keys_
const std::string & studentName(size_t i) const
size_t nrTimeSlots() const
DecisionTree choose(const L &label, size_t index) const
IsDerived< DERIVEDFACTOR > push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
double bound(double a, double min, double max)
void addStudent(const std::string &studentName, const std::string &area1, const std::string &area2, const std::string &area3, const std::string &advisor)
size_t nrStudents() const
current number of students
Key maxKey(const PROBLEM &problem)
const KeyFormatter & formatter
void printAssignment(sharedValues assignment) const
std::vector< double > advisor_
void addStudentSpecificConstraints(size_t i, boost::optional< size_t > slot=boost::none)
std::pair< Key, size_t > DiscreteKey
std::vector< Student > students_
const std::string & studentArea(size_t i, size_t area) const
FacultyInArea facultyInArea_
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
EIGEN_DEVICE_FUNC const Scalar & q
void addSlot(const std::string &slotName)
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
void buildGraph(size_t mutexBound=7)
const DiscreteKey & studentKey(size_t i) const
FastVector< sharedFactor >::const_iterator const_iterator
void print(const std::string &s="Scheduler", const KeyFormatter &formatter=DefaultKeyFormatter) const override
void addAllDiff(const DiscreteKey &key1, const DiscreteKey &key2)
Add a binary AllDiff constraint.
std::vector< std::string > areaName_
DiscreteBayesNet::shared_ptr eliminate() const
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
boost::shared_ptr< This > shared_ptr
void print(const std::string &s="DiscreteFactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Annotation for function names.
Annotation indicating that a class derives from another given type.
void addFaculty(const std::string &facultyName)
const DiscreteKey & key(size_t s, boost::optional< size_t > area=boost::none) const
std::uint64_t Key
Integer nonlinear key type.
boost::shared_ptr< Values > sharedValues
std::vector< double > slotsAvailable_
void accumulateStats(sharedValues assignment, std::vector< size_t > &stats) const
DiscreteKeys is a set of keys that can be assembled using the & operator.
void printSpecial(sharedValues assignment) const