-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.h
185 lines (154 loc) · 5.19 KB
/
import.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef INCLUDE_IMPORT_H
#define INCLUDE_IMPORT_H
#include "timetable_types.h"
#include <boost/serialization/string.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/mpi/datatype.hpp>
#include <boost/mpl/bool.hpp>
#include <map>
#include <istream>
#include <vector>
#include <string>
namespace import {
// this can be both a professor or a TA
class Professor {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & this->id;
ar & this->name;
ar & this->available_hours;
}
public:
// sourced from input
timetable_professor_t id;
std::string name;
unsigned int available_hours; // the amount of hours this TA is available (ignored for those that are only professors)
/**
* Imports professors.
* Format:
* <num_professors>
* <professor_id> <professor_name> <available_hours>
* ...
*/
static std::map<int, Professor> import_professors(std::string& file_path);
};
class Classroom {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & this->id;
ar & this->lecture_capacity;
ar & this->tutorial_capacity;
}
public:
// sourced from input
timetable_classroom_t id;
unsigned int lecture_capacity;
unsigned int tutorial_capacity;
/**
* Imports classrooms.
* Format:
* <num_classrooms>
* <classroom_id> <capacity>
* ...
*/
static std::map<int, Classroom> import_classrooms(std::string& file_path);
/**
* Used for sorting with std::sort. Sorts by lecture capacity descending,
* which also means tutorial capacities are sorted.
*/
static struct {
bool operator()(Classroom a, Classroom b) {
return a.lecture_capacity > b.lecture_capacity;
};
} descending_capacity_sort;
};
class Student {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & this->id;
ar & this->subjects;
}
public:
// sourced from input
timetable_student_t id;
std::vector<timetable_subject_t> subjects;
/**
* Imports students.
* Format:
* <num_students>
* <id>
* <num_subjects>
* <subjects ...>
* ...
*/
static std::map<int, Student> import_students(std::string& file_path);
};
class Subject {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & this->id;
ar & this->lecture_classrooms;
ar & this->tutorial_classrooms;
ar & this->professors;
ar & this->teaching_assistants;
ar & this->teaching_assistant_weights;
ar & this->students;
}
public:
// sourced from input
timetable_subject_t id;
std::vector<timetable_classroom_t> lecture_classrooms;
std::vector<timetable_classroom_t> tutorial_classrooms;
std::vector<timetable_professor_t> professors;
std::vector<timetable_professor_t> teaching_assistants;
std::vector<double> teaching_assistant_weights;
// computed from a list of students
std::vector<timetable_student_t> students;
/**
* Return a list of classroom IDs that fit this subject's requirements.
*/
std::vector<Classroom> get_possible_classrooms(std::vector<Classroom>& classrooms, bool lectures);
/**
* Imports subjects.
* Format:
* <num_subjects>
*
* <id>
* <num_available_lecture_classrooms>
* <lecture_classroom ...>
* <num_available_tutorial_classroom>
* <tutorial_classroom>
* <num_professors>
* <professor ...>
* <num_assistants>
* <assistant> <choose_weight> // all weights should sum to 1
* ...
*/
static std::map<int, Subject> import_subjects(std::string& file_path);
/**
* Given a list of students, populates this subject with the students that are taking it.
*/
void populate_students(std::map<int, Student> student_map);
};
}
/**
* These are Boost's way of optimizing fixed structures. They must be placed outside of namespace import because C++.
*/
namespace boost {
namespace mpi {
template <>
struct is_mpi_datatype<import::Professor> : boost::mpl::true_ { };
template <>
struct is_mpi_datatype<import::Classroom> : boost::mpl::true_ { };
}
}
#endif //INCLUDE_IMPORT_H