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;
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
gtsam::Scheduler::addFaculty
void addFaculty(const std::string &facultyName)
Definition: Scheduler.h:74
DiscreteBayesNet.h
gtsam::Scheduler::setAvailability
void setAvailability(const std::string &available)
Definition: Scheduler.h:82
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::Scheduler::slotName
const std::string & slotName(size_t s) const
Definition: Scheduler.h:88
gtsam::Scheduler::facultyInArea_
FacultyInArea facultyInArea_
Definition: Scheduler.h:55
gtsam::Scheduler::Student::advisor_
std::vector< double > advisor_
Definition: Scheduler.h:30
gtsam::Scheduler::slotName_
std::vector< std::string > slotName_
Definition: Scheduler.h:51
gtsam::Scheduler::Student::keys_
std::vector< DiscreteKey > keys_
Definition: Scheduler.h:28
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::Scheduler::students_
std::vector< Student > students_
Definition: Scheduler.h:47
gtsam::Scheduler::Student::areaName_
std::vector< std::string > areaName_
Definition: Scheduler.h:29
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::Scheduler::Student::Student
Student(size_t nrFaculty, size_t advisorIndex)
Definition: Scheduler.h:31
gtsam::Scheduler::maxNrStudents_
size_t maxNrStudents_
Definition: Scheduler.h:44
gtsam::Scheduler::addArea
void addArea(const std::string &facultyName, const std::string &areaName)
Definition: Scheduler.h:95
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
gtsam::Scheduler::addSlot
void addSlot(const std::string &slotName)
Definition: Scheduler.h:84
table
ArrayXXf table(10, 4)
stats
bool stats
Definition: SolverComparer.cpp:100
relicense.filename
filename
Definition: relicense.py:57
gtsam::Scheduler::Student::key_
DiscreteKey key_
Definition: Scheduler.h:27
gtsam::KeyFormatter
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
DiscreteValues
addStudent
void addStudent(Scheduler &s, size_t i)
Definition: schedulingExample.cpp:21
gtsam::Scheduler::slotsAvailable_
std::vector< double > slotsAvailable_
Definition: Scheduler.h:61
gtsam::Scheduler::facultyIndex_
std::map< std::string, size_t > facultyIndex_
Definition: Scheduler.h:50
key
const gtsam::Symbol key('X', 0)
gtsam::Scheduler
Definition: Scheduler.h:22
gtsam
traits
Definition: SFMdata.h:40
gtsam::CSP
Definition: CSP.h:21
gtsam::Scheduler::Scheduler
Scheduler(size_t maxNrStudents)
Definition: Scheduler.h:69
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::Scheduler::nrStudents
size_t nrStudents() const
current number of students
Definition: Scheduler.h:119
gtsam::Scheduler::available_
std::string available_
Definition: Scheduler.h:58
CSP.h
gtsam::Scheduler::setSlotsAvailable
void setSlotsAvailable(const std::vector< double > &slotsAvailable)
Definition: Scheduler.h:91
gtsam::DiscreteBayesNet::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: DiscreteBayesNet.h:43
gtsam::Scheduler::Student::name_
std::string name_
Definition: Scheduler.h:26
gtsam::Scheduler::~Scheduler
virtual ~Scheduler()
Destructor.
Definition: Scheduler.h:72
gtsam::Scheduler::FacultyInArea
std::map< std::string, std::vector< double > > FacultyInArea
Definition: Scheduler.h:54
gtsam::Scheduler::Student::print
void print() const
Definition: Scheduler.h:35
gtsam::Scheduler::nrFaculty
size_t nrFaculty() const
Definition: Scheduler.h:79
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::Scheduler::nrTimeSlots
size_t nrTimeSlots() const
Definition: Scheduler.h:86
gtsam::Scheduler::Student
Definition: Scheduler.h:25


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:09