Scheduler.h
Go to the documentation of this file.
1 /*
2  * Scheduler.h
3  * @brief an example how inference can be used for scheduling qualifiers
4  * @date Mar 26, 2011
5  * @author Frank Dellaert
6  */
7 
8 #pragma once
9 
12 
13 namespace gtsam {
14 
22 class GTSAM_UNSTABLE_EXPORT Scheduler : public CSP {
23  private:
25  struct Student {
26  std::string name_;
27  DiscreteKey key_; // key for student
28  std::vector<DiscreteKey> keys_; // key for areas
29  std::vector<std::string> areaName_;
30  std::vector<double> advisor_;
31  Student(size_t nrFaculty, size_t advisorIndex)
32  : keys_(3), areaName_(3), advisor_(nrFaculty, 1.0) {
33  advisor_[advisorIndex] = 0.0;
34  }
35  void print() const {
36  using std::cout;
37  cout << name_ << ": ";
38  for (size_t area = 0; area < 3; area++) cout << areaName_[area] << " ";
39  cout << std::endl;
40  }
41  };
42 
45 
47  std::vector<Student> students_;
48 
50  std::map<std::string, size_t> facultyIndex_;
51  std::vector<std::string> facultyName_, slotName_, areaName_;
52 
54  typedef std::map<std::string, std::vector<double> > FacultyInArea;
55  FacultyInArea facultyInArea_;
56 
58  std::string available_;
59 
61  std::vector<double> slotsAvailable_;
62 
63  public:
69  Scheduler(size_t maxNrStudents) : maxNrStudents_(maxNrStudents) {}
70 
72  virtual ~Scheduler() {}
73 
74  void addFaculty(const std::string& facultyName) {
75  facultyIndex_[facultyName] = nrFaculty();
76  facultyName_.push_back(facultyName);
77  }
78 
79  size_t nrFaculty() const { return facultyName_.size(); }
80 
82  void setAvailability(const std::string& available) { available_ = available; }
83 
84  void addSlot(const std::string& slotName) { slotName_.push_back(slotName); }
85 
86  size_t nrTimeSlots() const { return slotName_.size(); }
87 
88  const std::string& slotName(size_t s) const { return slotName_[s]; }
89 
91  void setSlotsAvailable(const std::vector<double>& slotsAvailable) {
92  slotsAvailable_ = slotsAvailable;
93  }
94 
95  void addArea(const std::string& facultyName, const std::string& areaName) {
96  areaName_.push_back(areaName);
97  std::vector<double>& table =
98  facultyInArea_[areaName]; // will create if needed
99  if (table.empty()) table.resize(nrFaculty(), 0);
100  table[facultyIndex_[facultyName]] = 1;
101  }
102 
107  Scheduler(size_t maxNrStudents, const std::string& filename);
108 
110  const DiscreteKey& key(size_t s,
111  std::optional<size_t> area = {}) const;
112 
114  void addStudent(const std::string& studentName, const std::string& area1,
115  const std::string& area2, const std::string& area3,
116  const std::string& advisor);
117 
119  size_t nrStudents() const { return students_.size(); }
120 
121  const std::string& studentName(size_t i) const;
122  const DiscreteKey& studentKey(size_t i) const;
123  const std::string& studentArea(size_t i, size_t area) const;
124 
126  void addStudentSpecificConstraints(
127  size_t i, std::optional<size_t> slot = {});
128 
130  void buildGraph(size_t mutexBound = 7);
131 
133  void print(
134  const std::string& s = "Scheduler",
135  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
136 
138  void printAssignment(const DiscreteValues& assignment) const;
139 
141  void printSpecial(const DiscreteValues& assignment) const;
142 
144  void accumulateStats(const DiscreteValues& assignment,
145  std::vector<size_t>& stats) const;
146 
148  DiscreteBayesNet::shared_ptr eliminate() const;
149 
151  DiscreteValues bestSchedule() const;
152 
154  DiscreteValues bestAssignment(const DiscreteValues& bestSchedule) const;
155 
156 }; // Scheduler
157 
158 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
Scheduler(size_t maxNrStudents)
Definition: Scheduler.h:69
std::map< std::string, size_t > facultyIndex_
Definition: Scheduler.h:50
std::vector< std::string > slotName_
Definition: Scheduler.h:51
std::vector< DiscreteKey > keys_
Definition: Scheduler.h:28
void setAvailability(const std::string &available)
Definition: Scheduler.h:82
const std::string & slotName(size_t s) const
Definition: Scheduler.h:88
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
bool stats
const KeyFormatter & formatter
Student(size_t nrFaculty, size_t advisorIndex)
Definition: Scheduler.h:31
std::vector< double > advisor_
Definition: Scheduler.h:30
virtual ~Scheduler()
Destructor.
Definition: Scheduler.h:72
void addStudent(Scheduler &s, size_t i)
std::vector< Student > students_
Definition: Scheduler.h:47
FacultyInArea facultyInArea_
Definition: Scheduler.h:55
RealScalar s
void addSlot(const std::string &slotName)
Definition: Scheduler.h:84
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
void setSlotsAvailable(const std::vector< double > &slotsAvailable)
Definition: Scheduler.h:91
traits
Definition: chartTesting.h:28
size_t nrStudents() const
current number of students
Definition: Scheduler.h:119
ArrayXXf table(10, 4)
std::vector< std::string > areaName_
Definition: Scheduler.h:29
std::shared_ptr< This > shared_ptr
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
Definition: CSP.h:21
void addArea(const std::string &facultyName, const std::string &areaName)
Definition: Scheduler.h:95
void addFaculty(const std::string &facultyName)
Definition: Scheduler.h:74
std::map< std::string, std::vector< double > > FacultyInArea
Definition: Scheduler.h:54
size_t nrFaculty() const
Definition: Scheduler.h:79
std::vector< double > slotsAvailable_
Definition: Scheduler.h:61
size_t maxNrStudents_
Definition: Scheduler.h:44
size_t nrTimeSlots() const
Definition: Scheduler.h:86
std::string available_
Definition: Scheduler.h:58


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:36