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 
11 
12 namespace gtsam {
13 
21  class GTSAM_UNSTABLE_EXPORT Scheduler : public CSP {
22 
23  private:
24 
26  struct Student {
27  std::string name_;
28  DiscreteKey key_; // key for student
29  std::vector<DiscreteKey> keys_; // key for areas
30  std::vector<std::string> areaName_;
31  std::vector<double> advisor_;
32  Student(size_t nrFaculty, size_t advisorIndex) :
33  keys_(3), areaName_(3), advisor_(nrFaculty, 1.0) {
34  advisor_[advisorIndex] = 0.0;
35  }
36  void print() const {
37  using std::cout;
38  cout << name_ << ": ";
39  for (size_t area = 0; area < 3; area++)
40  cout << areaName_[area] << " ";
41  cout << std::endl;
42  }
43  };
44 
47 
49  std::vector<Student> students_;
50 
52  std::map<std::string, size_t> facultyIndex_;
53  std::vector<std::string> facultyName_, slotName_, areaName_;
54 
56  typedef std::map<std::string, std::vector<double> > FacultyInArea;
57  FacultyInArea facultyInArea_;
58 
60  std::string available_;
61 
63  std::vector<double> slotsAvailable_;
64 
65  public:
66 
72  Scheduler(size_t maxNrStudents) : maxNrStudents_(maxNrStudents) {}
73 
75  virtual ~Scheduler() {}
76 
77  void addFaculty(const std::string& facultyName) {
78  facultyIndex_[facultyName] = nrFaculty();
79  facultyName_.push_back(facultyName);
80  }
81 
82  size_t nrFaculty() const {
83  return facultyName_.size();
84  }
85 
87  void setAvailability(const std::string& available) {
88  available_ = available;
89  }
90 
91  void addSlot(const std::string& slotName) {
92  slotName_.push_back(slotName);
93  }
94 
95  size_t nrTimeSlots() const {
96  return slotName_.size();
97  }
98 
99  const std::string& slotName(size_t s) const {
100  return slotName_[s];
101  }
102 
104  void setSlotsAvailable(const std::vector<double>& slotsAvailable) {
105  slotsAvailable_ = slotsAvailable;
106  }
107 
108  void addArea(const std::string& facultyName, const std::string& areaName) {
109  areaName_.push_back(areaName);
110  std::vector<double>& table = facultyInArea_[areaName]; // will create if needed
111  if (table.empty()) table.resize(nrFaculty(), 0);
112  table[facultyIndex_[facultyName]] = 1;
113  }
114 
119  Scheduler(size_t maxNrStudents, const std::string& filename);
120 
122  const DiscreteKey& key(size_t s, boost::optional<size_t> area = boost::none) const;
123 
125  void addStudent(const std::string& studentName, const std::string& area1,
126  const std::string& area2, const std::string& area3,
127  const std::string& advisor);
128 
130  size_t nrStudents() const {
131  return students_.size();
132  }
133 
134  const std::string& studentName(size_t i) const;
135  const DiscreteKey& studentKey(size_t i) const;
136  const std::string& studentArea(size_t i, size_t area) const;
137 
139  void addStudentSpecificConstraints(size_t i, boost::optional<size_t> slot = boost::none);
140 
142  void buildGraph(size_t mutexBound = 7);
143 
145  void print(
146  const std::string& s = "Scheduler",
147  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
148 
150  void printAssignment(sharedValues assignment) const;
151 
153  void printSpecial(sharedValues assignment) const;
154 
156  void accumulateStats(sharedValues assignment,
157  std::vector<size_t>& stats) const;
158 
160  DiscreteBayesNet::shared_ptr eliminate() const;
161 
163  sharedValues optimalAssignment() const;
164 
166  sharedValues bestSchedule() const;
167 
169  sharedValues bestAssignment(sharedValues bestSchedule) const;
170 
171  }; // Scheduler
172 
173 } // gtsam
174 
175 
const std::string & slotName(size_t s) const
Definition: Scheduler.h:99
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
Scheduler(size_t maxNrStudents)
Definition: Scheduler.h:72
std::map< std::string, size_t > facultyIndex_
Definition: Scheduler.h:52
std::vector< std::string > slotName_
Definition: Scheduler.h:53
std::vector< DiscreteKey > keys_
Definition: Scheduler.h:29
void print() const
Definition: Scheduler.h:36
void setAvailability(const std::string &available)
Definition: Scheduler.h:87
size_t nrTimeSlots() const
Definition: Scheduler.h:95
size_t nrStudents() const
current number of students
Definition: Scheduler.h:130
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
bool stats
const KeyFormatter & formatter
Student(size_t nrFaculty, size_t advisorIndex)
Definition: Scheduler.h:32
std::vector< double > advisor_
Definition: Scheduler.h:31
virtual ~Scheduler()
Destructor.
Definition: Scheduler.h:75
void addStudent(Scheduler &s, size_t i)
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
std::vector< Student > students_
Definition: Scheduler.h:49
FacultyInArea facultyInArea_
Definition: Scheduler.h:57
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
RealScalar s
void addSlot(const std::string &slotName)
Definition: Scheduler.h:91
void setSlotsAvailable(const std::vector< double > &slotsAvailable)
Definition: Scheduler.h:104
traits
Definition: chartTesting.h:28
ArrayXXf table(10, 4)
std::vector< std::string > areaName_
Definition: Scheduler.h:30
size_t nrFaculty() const
Definition: Scheduler.h:82
boost::shared_ptr< This > shared_ptr
Definition: CSP.h:21
void addArea(const std::string &facultyName, const std::string &areaName)
Definition: Scheduler.h:108
void addFaculty(const std::string &facultyName)
Definition: Scheduler.h:77
std::map< std::string, std::vector< double > > FacultyInArea
Definition: Scheduler.h:56
boost::shared_ptr< Values > sharedValues
std::vector< double > slotsAvailable_
Definition: Scheduler.h:63
size_t maxNrStudents_
Definition: Scheduler.h:46
std::string available_
Definition: Scheduler.h:60


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:54