13 #include <boost/tokenizer.hpp> 23 : maxNrStudents_(maxNrStudents) {
24 typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
27 ifstream is(filename.c_str());
29 cerr <<
"Scheduler: could not open file " << filename << endl;
30 throw runtime_error(
"Scheduler: could not open file " + filename);
36 if (getline(is, line,
'\r')) {
38 Tokenizer::iterator it = tok.begin();
39 for (++it; it != tok.end(); ++it)
addFaculty(*it);
44 while (getline(is, line,
'\r')) {
45 if (count++ > 100)
throw runtime_error(
"reached 100 lines, exiting");
47 Tokenizer::iterator it = tok.begin();
50 for (; it != tok.end(); ++it)
available_ += (it->empty()) ?
"0 " :
"1 ";
57 const string& area2,
const string& area3,
58 const string& advisor) {
82 std::optional<size_t> area)
const {
103 std::optional<size_t> slot) {
110 if (debug) cout <<
"Adding availability of slots" << endl;
116 for (
size_t area = 0; area < 3; area++) {
118 const string& areaName = s.
areaName_[area];
120 if (debug) cout <<
"Area constraints " << areaName << endl;
124 if (debug) cout <<
"Advisor constraint " << areaName << endl;
125 assert(s.
advisor_.size() == areaKey.second);
128 if (debug) cout <<
"Availability of faculty " << areaName << endl;
135 auto q = p.
choose(dummyIndex, *slot);
144 if (debug) cout <<
"Mutex for faculty" << endl;
152 if (debug) cout <<
"Adding student-specific constraints" << endl;
164 if (debug) cout <<
"Mutex for Students" << endl;
165 for (
size_t i1 = 0; i1 <
nrStudents(); i1++) {
168 for (
size_t i2 = i1 + 1; i2 <
bound; i2++) {
177 cout << s <<
" Faculty:" << endl;
181 cout << s <<
" Slots:\n";
183 for (
const string& name :
slotName_) cout << i++ <<
" " << name << endl;
186 cout <<
"Availability:\n" <<
available_ <<
'\n';
188 cout << s <<
" Area constraints:\n";
190 cout << setw(12) << it.first <<
": ";
191 for (
double v : it.second) cout << v <<
" ";
196 cout << s <<
" Students:\n";
210 size_t slot = assignment.at(j);
213 for (
size_t area = 0; area < 3; area++) {
214 size_t faculty = assignment.at(base + area);
224 DiscreteValues::const_iterator it = assignment.begin();
225 for (
size_t area = 0; area < 3; area++, it++) {
226 size_t f = it->second;
234 vector<size_t>&
stats)
const {
237 for (
size_t area = 0; area < 3; area++) {
238 size_t f = assignment.at(base + area);
239 assert(f < stats.size());
251 for (
size_t i = 0;
i <
maxKey; ++
i) defaultKeyOrdering.push_back(
i);
261 throw runtime_error(
"bestSchedule not implemented");
268 throw runtime_error(
"bestAssignment not implemented");
Scheduler(size_t maxNrStudents)
void printAssignment(const DiscreteValues &assignment) const
DiscreteValues bestAssignment(const DiscreteValues &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
const std::string & studentArea(size_t i, size_t area) const
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)
void addStudentSpecificConstraints(size_t i, std::optional< size_t > slot={})
Key maxKey(const PROBLEM &problem)
void add(Args &&... args)
static constexpr bool debug
const KeyFormatter & formatter
const DiscreteKey & studentKey(size_t i) const
const DiscreteKey & key(size_t s, std::optional< size_t > area={}) const
void accumulateStats(const DiscreteValues &assignment, std::vector< size_t > &stats) const
std::vector< double > advisor_
void printSpecial(const DiscreteValues &assignment) const
std::vector< Student > students_
FacultyInArea facultyInArea_
Array< int, Dynamic, 1 > v
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
EIGEN_DEVICE_FUNC const Scalar & q
void addSlot(const std::string &slotName)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
void buildGraph(size_t mutexBound=7)
size_t nrStudents() const
current number of students
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_
DiscreteValues bestSchedule() const
std::shared_ptr< This > shared_ptr
std::pair< Key, size_t > DiscreteKey
void print(const std::string &s="DiscreteFactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Annotation for function names.
DiscreteBayesNet::shared_ptr eliminate() const
Annotation indicating that a class derives from another given type.
void addFaculty(const std::string &facultyName)
DecisionTree choose(const L &label, size_t index) const
std::uint64_t Key
Integer nonlinear key type.
std::vector< double > slotsAvailable_
size_t nrTimeSlots() const
DiscreteKeys is a set of keys that can be assembled using the & operator.