1 /*
2 File timetable_defs.h
3 */
4 
5 /***************************************************************************
6                           timetable_defs.h  -  description
7                              -------------------
8     begin                : Sat Mar 15 2003
9     copyright            : (C) 2003 by Lalescu Liviu
10     email                : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
11  ***************************************************************************/
12 
13 /***************************************************************************
14  *                                                                         *
15  *   This program is free software: you can redistribute it and/or modify  *
16  *   it under the terms of the GNU Affero General Public License as        *
17  *   published by the Free Software Foundation, either version 3 of the    *
18  *   License, or (at your option) any later version.                       *
19  *                                                                         *
20  ***************************************************************************/
21 
22 #ifndef TIMETABLE_DEFS_H
23 #define TIMETABLE_DEFS_H
24 
25 #ifdef NDEBUG
26 #undef NDEBUG
27 #endif
28 #include <cassert>
29 
30 #include <QString>
31 
32 #include <QtGlobal>
33 
34 #include "centerwidgetonscreen.h"
35 
36 #if QT_VERSION < QT_VERSION_CHECK(5,7,0)
37 #include <type_traits>
38 namespace std
39 {
40 	template<class T> using add_const_t = typename add_const<T>::type;
41 }
qAsConst(T & t)42 template<class T> constexpr std::add_const_t<T>& qAsConst(T& t) noexcept
43 {
44 	return t;
45 }
46 template<class T> void qAsConst(const T&&) = delete;
47 #endif
48 
49 class QWidget;
50 
51 /**
52 The version number
53 */
54 extern const QString FET_VERSION;
55 
56 /**
57 The language
58 */
59 extern QString FET_LANGUAGE;
60 
61 extern bool LANGUAGE_STYLE_RIGHT_TO_LEFT;
62 
63 extern QString LANGUAGE_FOR_HTML;
64 
65 /**
66 Timetable html css javaScript Level, added by Volker Dirr
67 */
68 extern int TIMETABLE_HTML_LEVEL;
69 
70 extern bool TIMETABLE_HTML_PRINT_ACTIVITY_TAGS;
71 
72 extern bool PRINT_DETAILED_HTML_TIMETABLES;
73 
74 extern bool PRINT_DETAILED_HTML_TEACHERS_FREE_PERIODS;
75 
76 extern bool PRINT_NOT_AVAILABLE_TIME_SLOTS;
77 
78 extern bool PRINT_BREAK_TIME_SLOTS;
79 
80 extern bool DIVIDE_HTML_TIMETABLES_WITH_TIME_AXIS_BY_DAYS;
81 
82 extern bool TIMETABLE_HTML_REPEAT_NAMES;
83 
84 extern bool PRINT_ACTIVITIES_WITH_SAME_STARTING_TIME;
85 
86 extern bool USE_GUI_COLORS;
87 
88 extern bool SHOW_SUBGROUPS_IN_COMBO_BOXES;
89 extern bool SHOW_SUBGROUPS_IN_ACTIVITY_PLANNING;
90 
91 extern bool TIMETABLES_SUBGROUPS_SORTED;
92 
93 extern bool WRITE_TIMETABLE_CONFLICTS;
94 
95 extern bool WRITE_TIMETABLES_STATISTICS;
96 extern bool WRITE_TIMETABLES_XML;
97 extern bool WRITE_TIMETABLES_DAYS_HORIZONTAL;
98 extern bool WRITE_TIMETABLES_DAYS_VERTICAL;
99 extern bool WRITE_TIMETABLES_TIME_HORIZONTAL;
100 extern bool WRITE_TIMETABLES_TIME_VERTICAL;
101 
102 extern bool WRITE_TIMETABLES_SUBGROUPS;
103 extern bool WRITE_TIMETABLES_GROUPS;
104 extern bool WRITE_TIMETABLES_YEARS;
105 extern bool WRITE_TIMETABLES_TEACHERS;
106 extern bool WRITE_TIMETABLES_TEACHERS_FREE_PERIODS;
107 extern bool WRITE_TIMETABLES_ROOMS;
108 extern bool WRITE_TIMETABLES_SUBJECTS;
109 extern bool WRITE_TIMETABLES_ACTIVITY_TAGS;
110 extern bool WRITE_TIMETABLES_ACTIVITIES;
111 
112 extern bool SHOW_VIRTUAL_ROOMS_IN_TIMETABLES;
113 
114 extern bool SHOW_SHORTCUTS_ON_MAIN_WINDOW;
115 
116 extern bool SHOW_TOOLTIPS_FOR_CONSTRAINTS_WITH_TABLES;
117 
118 extern bool ENABLE_ACTIVITY_TAG_MAX_HOURS_DAILY;
119 extern bool ENABLE_ACTIVITY_TAG_MIN_HOURS_DAILY;
120 extern bool ENABLE_STUDENTS_MAX_GAPS_PER_DAY;
121 extern bool ENABLE_MAX_GAPS_PER_REAL_DAY;
122 
123 extern bool SHOW_WARNING_FOR_NOT_PERFECT_CONSTRAINTS;
124 
125 extern bool SHOW_WARNING_FOR_SUBGROUPS_WITH_THE_SAME_ACTIVITIES;
126 
127 extern bool SHOW_WARNING_FOR_ACTIVITIES_FIXED_SPACE_VIRTUAL_REAL_ROOMS_BUT_NOT_FIXED_TIME;
128 
129 extern bool SHOW_WARNING_FOR_MAX_HOURS_DAILY_WITH_UNDER_100_WEIGHT;
130 
131 extern bool ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS;
132 extern bool SHOW_WARNING_FOR_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS;
133 extern bool ENABLE_STUDENTS_MIN_HOURS_PER_MORNING_WITH_ALLOW_EMPTY_MORNINGS;
134 extern bool SHOW_WARNING_FOR_STUDENTS_MIN_HOURS_PER_MORNING_WITH_ALLOW_EMPTY_MORNINGS;
135 
136 extern bool ENABLE_GROUP_ACTIVITIES_IN_INITIAL_ORDER;
137 extern bool SHOW_WARNING_FOR_GROUP_ACTIVITIES_IN_INITIAL_ORDER;
138 
139 extern bool CONFIRM_ACTIVITY_PLANNING;
140 extern bool CONFIRM_SPREAD_ACTIVITIES;
141 extern bool CONFIRM_REMOVE_REDUNDANT;
142 extern bool CONFIRM_SAVE_TIMETABLE;
143 
144 extern bool VERBOSE;
145 
146 /**
147 The maximum total number of different subgroups of students
148 */
149 const int MAX_TOTAL_SUBGROUPS=30000;
150 
151 const int MAX_ROOM_CAPACITY=30000;
152 
153 /**
154 The maximum number of activities
155 DEPRECATED COMMENT BELOW
156 IMPORTANT: must be qint16 (max 32767), because we are using qint16 for each activity index and for
157 unallocated activity = max_activities
158 */
159 const int MAX_ACTIVITIES=500000;
160 
161 /**
162 The maximum number of rooms
163 DEPRECATED COMMENT BELOW
164 IMPORTANT: max_rooms+1 must be qint16 (max 32766 for max_rooms), because we are using qint16 for each room index and
165 for unallocated space = max_rooms and for unspecified room = max_rooms+1
166 */
167 const int MAX_ROOMS=30000;
168 
169 /**
170 The maximum number of buildings
171 */
172 const int MAX_BUILDINGS=30000;
173 
174 /**
175 This constant represents an unallocated activity
176 */
177 const int UNALLOCATED_ACTIVITY = MAX_ACTIVITIES;
178 
179 /**
180 The maximum number of working hours per day.
181 
182 IMPORTANT: MAX_HOURS_PER_DAY * MAX_DAYS_PER_WEEK == MAX_HOURS_PER_WEEK must be int (max 2^31-1)
183 because each time is int and unallocated time is int
184 */
185 const int MAX_HOURS_PER_DAY=1440;
186 
187 /**
188 The maximum number of working days per week.
189 
190 IMPORTANT: MAX_HOURS_PER_DAY * MAX_DAYS_PER_WEEK == MAX_HOURS_PER_WEEK must be int (max 2^31-1)
191 because each time is int and unallocated time is int
192 */
193 const int MAX_DAYS_PER_WEEK=1000;
194 
195 //This is a practically chosen value so that the dialog of add activity does not become unresponsive.
196 const int MAX_SPLIT_OF_AN_ACTIVITY=1000;
197 
198 /**
199 The predefined names of the days of the week
200 */
201 //extern const QString PREDEFINED_DAYS_OF_THE_WEEK[];
202 
203 /**
204 The maximum number of working hours in a week.
205 
206 Hours in a week are arranged like this:
207          Mo Tu We Th Fr
208 1        0  1  2  3  4
209 2        5  6  7  8  9
210 3        10 11 12 13 14
211 4        15 16 17 18 19
212 5        20 21 22 23 24
213 6        25 26 27 28 29 etc.
214 
215 IMPORTANT: MAX_HOURS_PER_DAY * MAX_DAYS_PER_WEEK == MAX_HOURS_PER_WEEK must be int (max 2^31-1)
216 because each time is int and unallocated time is int
217 */
218 const int MAX_HOURS_PER_WEEK = MAX_HOURS_PER_DAY * MAX_DAYS_PER_WEEK;
219 
220 /**
221 This constant represents unallocated time for an activity
222 */
223 const int UNALLOCATED_TIME = MAX_HOURS_PER_WEEK;
224 
225 /**
226 This constant represents unallocated space for an activity
227 */
228 const int UNALLOCATED_SPACE = MAX_ROOMS;
229 
230 const int UNSPECIFIED_ROOM = MAX_ROOMS+1;
231 
232 /**
233 The maximum number of time constraints
234 */
235 //const int MAX_TIME_CONSTRAINTS = 60000;
236 
237 /**
238 The maximum number of space constraints
239 */
240 //const int MAX_SPACE_CONSTRAINTS = 60000;
241 
242 /**
243 File and directory separator
244 */
245 extern const QString FILE_SEP;
246 
247 /**
248 The timetable's rules input file name
249 */
250 extern QString INPUT_FILENAME_XML;
251 
252 /**
253 The working directory
254 */
255 extern QString WORKING_DIRECTORY;
256 
257 /**
258 The import directory
259 */
260 extern QString IMPORT_DIRECTORY;
261 
262 //OUTPUT FILES
263 
264 /**
265 The output directory. Please be careful when editing it,
266 because the functions add a FILE_SEP sign at the end of it
267 and then the name of a file. If you make OUTPUT_DIR="",
268 there might be problems.
269 */
270 extern QString OUTPUT_DIR;
271 
272 /**
273 A log file explaining how the xml input file was parsed
274 */
275 extern const QString XML_PARSING_LOG_FILENAME;
276 
277 /**
278 A function used in xml saving
279 */
280 QString protect(const QString& str);
281 
282 /**
283 A function used in html saving
284 */
285 QString protect2(const QString& str);
286 
287 /**
288 A function used in html saving
289 */
290 QString protect2vert(const QString& str);
291 
292 /**
293 A function used in html saving
294 */
295 //QString protect2id(const QString& str);
296 
297 /**
298 A function used in html saving
299 */
300 //QString protect2java(const QString& str);
301 
302 /**
303 This constants represents free periods of a teacher in the teachers free periods timetable
304 */
305 const int TEACHER_HAS_SINGLE_GAP = 0;
306 const int TEACHER_HAS_BORDER_GAP = 1;
307 const int TEACHER_HAS_BIG_GAP = 2;
308 
309 const int TEACHER_MUST_COME_EARLIER = 4;
310 const int TEACHER_MUST_COME_MUCH_EARLIER = 6;
311 
312 const int TEACHER_MUST_STAY_LONGER = 3;
313 const int TEACHER_MUST_STAY_MUCH_LONGER = 5;		// BE CAREFUL, I just print into LESS_DETAILED timetable, if it's smaller than TEACHER_MUST_STAY_MUCH_LONGER
314 
315 const int TEACHER_HAS_A_FREE_DAY = 7;
316 
317 const int TEACHER_IS_NOT_AVAILABLE = 8;
318 
319 const int TEACHERS_FREE_PERIODS_N_CATEGORIES = 9;
320 
321 extern bool checkForUpdates;
322 
323 extern QString internetVersion;
324 
325 const int STUDENTS_COMBO_BOXES_STYLE_SIMPLE=0;
326 const int STUDENTS_COMBO_BOXES_STYLE_ICONS=1;
327 const int STUDENTS_COMBO_BOXES_STYLE_CATEGORIZED=2;
328 extern int STUDENTS_COMBO_BOXES_STYLE;
329 
330 ///////tricks to save work to reconvert old code
331 const int CUSTOM_DOUBLE_PRECISION=6; //the maximum number of significant digits after the decimal dot for the weights
332 const int MULTIPLICANT_DOUBLE_PRECISION=100000000; //10^(2+CUSTOM_DOUBLE_PRECISION)
333 const int HALF_MULTIPLICANT_DOUBLE_PRECISION=MULTIPLICANT_DOUBLE_PRECISION/2;
334 
335 void weight_sscanf(const QString& str, const char* fmt, double* result);
336 
337 class CustomFETString{
338 public:
339 	static QString number(int n);
340 	static QString number(double x);
341 	static QString numberPlusTwoDigitsPrecision(double x);
342 };
343 
344 double customFETStrToDouble(const QString& str, bool* ok=0);
345 ////////////////////////////////////////////////
346 
347 //Trick found on http://www.qtcentre.org/threads/53066-QMap-sorting-according-to-QLocale
348 //to create a QMap<QString, ...> ordered by locale order.
349 //Third post, by ChrisW67.
350 class LocaleString: public QString{
351 public:
LocaleString(const QString & s)352 	LocaleString(const QString& s): QString(s){}
353 };
354 
355 inline bool operator<(const LocaleString& lhs, const LocaleString& rhs)
356 {
357 	return QString::localeAwareCompare(lhs, rhs)<0;
358 }
359 /////////////////////////////////////////////////////
360 
361 extern bool BEEP_AT_END_OF_GENERATION;
362 extern bool ENABLE_COMMAND_AT_END_OF_GENERATION;
363 extern QString commandAtEndOfGeneration;
364 //extern bool DETACHED_NOTIFICATION;
365 //extern int terminateCommandAfterSeconds;
366 //extern int killCommandAfterSeconds;
367 
368 //Old RNG below
369 //for random Knuth - from Knuth TAOCP Vol. 2 Seminumerical Algorithms section 3.6
370 //these numbers are really important - please do not change them, NEVER!!!
371 //if you want, write a new random number generator routine, with other name
372 //I think I found a minor possible improvement, the author said: if(Z<=0) then Z+=MM,
373 //but I think this would be better: if(Z<=0) then Z+=MM-1. - Yes, the author confirmed.
374 //The period of this RNG is ~74 quadrilions, according to Knuth ( (2^31-2)*(2^31-250)/62 ~= 7.4*10^16 ).
375 //Unfortunately, this period is not too long. For the moment I prefer to keep this RNG,
376 //since changing it is highly critical. But we need to consider the change for the future.
377 //Changing it will also mean that the method of saving/restoring the seed will need to change.
378 //extern int XX;
379 //extern int YY;
380 /*const int MM=2147483647;
381 const int AA=48271;
382 const int QQ=44488;
383 const int RR=3399;
384 
385 const int MMM=2147483399;
386 const int AAA=40692;
387 const int QQQ=52774;
388 const int RRR=3791;
389 
390 void initRandomKnuth();
391 int randomKnuth1MM1(); //a random between 1 and MM-1
392 int randomKnuth(int k); //a random between 0 and k-1
393 */
394 
395 //32-bits Random number generator U(0,1): MRG32k3a
396 //Author: Pierre L'Ecuyer
397 //Modified: U[0,1), as instructed by the author in his papers.
398 
399 //Reference for the MRG32k3a random number generator code:
400 
401 //P. L'Ecuyer, ``Good Parameter Sets for Combined Multiple Recursive
402 //Random Number Generators'', Shorter version in Operations Research, 47,
403 //1 (1999), 159--164.
404 //<http://pubsonline.informs.org/doi/abs/10.1287/opre.47.1.159>
405 
406 //Includes ideas and code from the files: http://simul.iro.umontreal.ca/rng/MRG32k3a.h, http://simul.iro.umontreal.ca/rng/MRG32k3a.c,
407 //and/or https://www.iro.umontreal.ca/~lecuyer/myftp/papers/combmrg2.c
408 
409 //Used with permission from the author, Pierre L'Ecuyer (9 March 2020)
410 
411 //Modified so that it uses 64-bit integer number operations instead of the not-so-reliable 'double' type.
412 
413 //The period of this RNG is ~2^191 or ~3*10^57. It has an internal state of 6 32-bit integers.
414 
415 class MRG32k3a{
416 public:
417 	qint64 s10, s11, s12, s20, s21, s22;
418 
419 	static const qint64 m1;
420 	static const qint64 m2;
421 	static const qint64 a12;
422 	static const qint64 a13n;
423 	static const qint64 a21;
424 	static const qint64 a23n;
425 
426 	MRG32k3a();
427 	~MRG32k3a();
428 
429 	/*
430 	The seeds for s10, s11, s12 must be integers in [0, m1 - 1] and not all 0.
431 	The seeds for s20, s21, s22 must be integers in [0, m2 - 1] and not all 0.
432 	*/
433 	void initializeMRG32k3a(qint64 _s10, qint64 _s11, qint64 _s12,
434 	 qint64 _s20, qint64 _s21, qint64 _s22);
435 
436 	void initializeMRG32k3a();
437 
438 	unsigned int uiMRG32k3a(); //returns a random number >=0 and <m1
439 
440 	//double dMRG32k3a(); //returns a uniform real number (double) in the interval [0,1)
441 
442 	int intMRG32k3a(int k); //returns a random integer >=0 and <k, using the multiplication method recommended in Knuth TAOCP Vol. 2, Section 3.4.1,
443 		//but implemented using 64-bit numbers. (although I think that we could use the integer division/modulo method, as Knuth additionally notes,
444 		//since m1 and m2 are prime and so the last bits are also random - but he added that note for a single modulo operation, not for the difference.)
445 };
446 
447 #endif
448