00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UDINE_VARIABLES
00022 #define UDINE_VARIABLES
00023
00024 #include <sstream>
00025 #include <ilcplex/ilocplex.h>
00026
00027 #include "solver_config.h"
00028 #include "loader.h"
00029 #include "neighbourhood.h"
00030
00031 ILOSTLBEGIN
00032
00033 namespace Udine {
00034
00035 struct Variables {
00036
00037
00038 IloArray< IloArray<IloIntVarArray> > x;
00039
00040
00041
00042 IloIntVarArray courseMinDayViolations;
00043
00044 IloArray<IloIntVarArray> courseRooms;
00045
00046 IloArray<IloIntVarArray> coursePeriods;
00047
00048 IloArray<IloIntVarArray> courseDays;
00049
00050 IloArray< IloArray<IloIntVarArray> > singletonChecks;
00051
00052
00053
00054 IloIntVar penaltyRoomStability;
00055 IloIntVar penaltyRoomCapacity;
00056 IloIntVar penaltyPeriodSingletons;
00057 IloIntVar penaltyPeriodSpread;
00058
00059
00060 Variables(IloEnv env, Config &config, Instance &i, Neighbourhood &def)
00061 : x(IloArray< IloArray<IloIntVarArray> >(env)),
00062 courseRooms(IloArray<IloIntVarArray>(env)),
00063 coursePeriods(IloArray<IloIntVarArray>(env)),
00064 courseDays(IloArray<IloIntVarArray>(env)),
00065 courseMinDayViolations(IloIntVarArray(env)),
00066 singletonChecks(IloArray< IloArray<IloIntVarArray> >(env)),
00067 penaltyRoomStability(env, 0, 214783647, "penaltyRoomStability"),
00068 penaltyRoomCapacity(env, 0, 214783647, "penaltyRoomCapacity"),
00069 penaltyPeriodSingletons(env, 0, 214783647, "penaltyPeriodSingletons"),
00070 penaltyPeriodSpread(env, 0, 214783647, "penaltyPeriodSpread")
00071 {
00072
00073 int p, d, r, c, u, s;
00074
00075
00076 for (p = 0; p < i.getPeriodCount(); p++) {
00077 IloArray<IloIntVarArray> forPeriod = IloArray<IloIntVarArray>(env);
00078 for (r = 0; r < i.getRoomCount(def.type); r++) {
00079 IloIntVarArray forRoom(env);
00080 for (c = 0; c < i.getCourseCount(); c++) {
00081 std::stringstream name;
00082 name << "x(" << p << "," << r << "," << c << ")";
00083 IloIntVar var(env, 0, 1, name.str().c_str());
00084 forRoom.add(var);
00085 }
00086 forPeriod.add(forRoom);
00087 }
00088 x.add(forPeriod);
00089 }
00090
00091
00092 for (c = 0; c < i.getCourseCount(); c++) {
00093 IloIntVarArray forCourse(env);
00094 for (r = 0; r < i.getRoomCount(def.type); r++) {
00095 std::stringstream name;
00096 name << "courseRoom(" << c << "," << r << ")";
00097 IloIntVar var(env, 0, 1, name.str().c_str());
00098 forCourse.add(var);
00099 }
00100 courseRooms.add(forCourse);
00101 }
00102
00103 if (def.type != Surface) {
00104 if (config.getParam(UseAdditionalVariables))
00105 for (c = 0; c < i.getCourseCount(); c++) {
00106 IloIntVarArray forCourse(env);
00107 for (p = 0; p < i.getPeriodCount(); p++) {
00108 std::stringstream name;
00109 name << "coursePeriod(" << c << "," << p << ")";
00110 IloIntVar var(env, 0, 1, name.str().c_str());
00111 forCourse.add(var);
00112 }
00113 coursePeriods.add(forCourse);
00114 }
00115 }
00116
00117 if (def.type != FixPeriod) {
00118
00119 for (u = 0; u < i.getProperCurriculumCount(); u++) {
00120 IloArray<IloIntVarArray> forCurriculum(env);
00121 for (d = 0; d < i.getDayCount(); d++) {
00122 IloIntVarArray forDay(env);
00123 if ((def.type == Surface && config.getParam(UseHeuristicCompactnessAtSurface))
00124 || (def.type == FixDay && config.getParam(UseHeuristicCompactnessInDayDives))) {
00125 std::stringstream name;
00126 name << "singletonCheck(" << u << "," << d << ")";
00127 IloIntVar var(env, 0, 1, name.str().c_str());
00128 forDay.add(var);
00129 } else {
00130 for (s = 0; s < i.getCheckCount(); s++) {
00131 std::stringstream name;
00132 name << "singletonCheck(" << u << "," << d << "," << s << ")";
00133 IloIntVar var(env, 0, 1, name.str().c_str());
00134 forDay.add(var);
00135 }
00136 }
00137 forCurriculum.add(forDay);
00138 }
00139 singletonChecks.add(forCurriculum);
00140 }
00141 }
00142
00143 if (def.type == Monolithic || def.type == Surface) {
00144
00145
00146 for (c = 0; c < i.getCourseCount(); c++) {
00147 std::stringstream name;
00148 name << "minDayViol(" << c << ")";
00149 IloIntVar var(env, 0, 1, name.str().c_str());
00150 courseMinDayViolations.add(var);
00151 }
00152
00153
00154 for (c = 0; c < i.getCourseCount(); c++) {
00155 IloIntVarArray forCourse(env);
00156 for (d = 0; d < i.getDayCount(); d++) {
00157 std::stringstream name;
00158 name << "courseDays(" << c << "," << d << ")";
00159 IloIntVar var(env, 0, 1, name.str().c_str());
00160 forCourse.add(var);
00161 }
00162 courseDays.add(forCourse);
00163 }
00164
00165 }
00166 }
00167
00168 };
00169
00170 }
00171
00172 #endif // UDINE VARIABLES