00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UDINE_LOADER
00022 #define UDINE_LOADER
00023
00024 #include <cassert>
00025 #include <vector>
00026 #include <string>
00027 #include <iostream>
00028 #include <utility>
00029
00030 #include "solver_config.h"
00031
00032
00033 namespace Udine {
00034
00035
00036
00037
00038
00039 struct Course {
00040 std::string name, teacher;
00041 int lectures, minWorkingDays, students;
00042 };
00043 typedef std::vector<Course> Courses;
00044
00045 struct Room {
00046 std::string name;
00047 int capacity;
00048 };
00049 typedef std::vector<Room> Rooms;
00050 struct RoomCapacityLess { bool operator()(const Room &x, const Room &y ); };
00051
00052 struct MRoom {
00053 std::vector<Room> rooms;
00054 int multiplicity;
00055 int perEventCapacity;
00056 MRoom() { multiplicity = 0; perEventCapacity = 0; }
00057 };
00058 typedef std::vector<MRoom> MRooms;
00059 typedef std::vector<MRooms> MRoomsVersions;
00060
00061 typedef std::vector<int> CourseIds;
00062 struct Curriculum {
00063 std::string name;
00064 CourseIds courseIds;
00065 };
00066 typedef std::vector<Curriculum> Curricula;
00067
00068 struct Restriction {
00069 int courseId;
00070 int period;
00071 };
00072 typedef std::vector<Restriction> Restrictions;
00073
00074
00075 struct Pattern { std::vector<int> coefs; int penalty; int rhs; };
00076 typedef std::vector<Pattern> PatternDB;
00077
00078 class Instance {
00079 protected:
00080 int periods, periodsPerDay, days, checks;
00081 Courses courses;
00082 Rooms rooms;
00083 MRoomsVersions mRooms;
00084 int origCurricula;
00085 Curricula curricula;
00086 Restrictions restrict;
00087 PatternDB patterns;
00088
00089
00090 void genPatterns(int periodsPerDay, int rhs = -1, std::vector<int> soFar = std::vector<int>());
00091 void genMRoomsAggregates();
00092
00093 public:
00094 Instance() : mRooms(MRoomsVersions(ModelTypeLen)) {}
00095
00096 void load(const char *filename);
00097
00098 int getPeriodCount() { return periods; }
00099 int getDayCount() { return days; }
00100 int getPeriodsPerDayCount() { return periodsPerDay; }
00101 int getCheckCount() { return checks; }
00102 int getCourseCount() { return courses.size(); }
00103 int getProperCurriculumCount() { return origCurricula; }
00104 int getCurriculumCount() { return curricula.size(); }
00105 int getRestrictionCount() { return restrict.size(); }
00106
00107 const Course & getCourse(int i) {
00108 assert(i >= 0 && i < courses.size());
00109 return courses.at(i);
00110 }
00111
00112 const Curriculum & getCurriculum(int u) {
00113 assert(u >= 0 && u < curricula.size());
00114 return curricula.at(u);
00115 }
00116
00117 const Restriction & getRestriction(int i) {
00118 assert(i >= 0 && i < restrict.size());
00119 return restrict.at(i);
00120 }
00121
00122 int getRoomCount(ModelType t) {
00123 assert(t >= 0 && t < ModelTypeLen);
00124 return mRooms.at(t).size();
00125 }
00126
00127 int getRoomTotalMultiplicity(ModelType t) {
00128 assert(t >= 0 && t < ModelTypeLen);
00129 int multiplicity = 0;
00130 for(int r = 0; r < mRooms.at(t).size(); r++)
00131 multiplicity += mRooms.at(t).at(r).multiplicity;
00132 return multiplicity;
00133 }
00134
00135 const std::string getRoomName(int r) {
00136 assert(r >= 0 && r < rooms.size());
00137 return rooms.at(r).name;
00138 }
00139
00140 int getRoomMultiplicity(ModelType t, int r) {
00141 assert(t >= 0 && t < ModelTypeLen);
00142 assert(r >= 0 && r < mRooms.at(t).size());
00143 return mRooms.at(t).at(r).multiplicity;
00144 }
00145
00146 int getRoomPerEventCapacity(ModelType t, int r) {
00147 assert(t >= 0 && t < ModelTypeLen);
00148 assert(r >= 0 && r < mRooms.at(t).size());
00149 return mRooms.at(t).at(r).perEventCapacity;
00150 }
00151
00152 PatternDB & getPatterns() {
00153 return patterns;
00154 }
00155 };
00156
00157 }
00158
00159 #endif // UDINE LOADER