small score ajdustments
This commit is contained in:
parent
4903bd7455
commit
3c7c477985
613
src/algorithm.c
613
src/algorithm.c
|
@ -79,372 +79,6 @@ int get_next_friday(creneau* edt, int len_creneau, date d) {
|
||||||
int get_fst_offset(creneau* edt, date d) {
|
int get_fst_offset(creneau* edt, date d) {
|
||||||
return (date_dist(edt[0].date, d));
|
return (date_dist(edt[0].date, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Feuilles mortes (--> ligne WYSI (727)) :
|
|
||||||
|
|
||||||
bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
|
||||||
bool debug = false;
|
|
||||||
|
|
||||||
conditions (AND) :
|
|
||||||
* 0) Only 1 colle at a time
|
|
||||||
* 1) Alternate between physics and english
|
|
||||||
* 2) Pattern for math colles is exactly 3-1-3-1-...
|
|
||||||
* 3) Between 1 and 2 colles per week and per group (exclusing special colles such as Info)
|
|
||||||
* 4) Special colles (aka INFO) at least 1 every 6 weeks
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int end_id = get_next_friday(edt, len_edt, end); // index of first date that is later than end
|
|
||||||
if(end_id == -1) {
|
|
||||||
stats[4]++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int offs = get_date_index(edt, len_edt, end);
|
|
||||||
|
|
||||||
//printf("EndId : %d\n", end_id);
|
|
||||||
// 0)
|
|
||||||
int id = 1;
|
|
||||||
while(id >= 0 && id < len_edt && is_equal_date(edt[offs+id].date, end)) {
|
|
||||||
if(str_equal(edt[offs+id].name, edt[offs].name)) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Unable to duplicate colleur %s\n", edt[offs].name);
|
|
||||||
}
|
|
||||||
stats[0]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
id = -1;
|
|
||||||
while(id >= 0 && id < len_edt && is_equal_date(edt[offs+id].date, end)) {
|
|
||||||
if(str_equal(edt[offs+id].name, edt[offs].name)) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Unable to duplicate colleur %s\n", edt[offs].name);
|
|
||||||
}
|
|
||||||
stats[0]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
id--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1) PC/AGL alternance
|
|
||||||
|
|
||||||
int agl = 0;
|
|
||||||
int pc = 0;
|
|
||||||
char has_to_be = 'n'; // 'n' = not set, 'a' = AGL and 'p' = PC
|
|
||||||
for(int i = end_id-1; i >= 0; i--) {
|
|
||||||
//for(int i = -1; i >= 0; i--) {
|
|
||||||
if(i != end_id-1 && (i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4))) {
|
|
||||||
//printf("Checking AGL/PC...\n");
|
|
||||||
// currently pointed date is the last friday of the week
|
|
||||||
// since we are going down, friday <==> reset variables and check for conflicts
|
|
||||||
if(agl + pc != 1) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of english/physics colle at index %d for group %d (found %d)\n", i, grp, agl+pc);
|
|
||||||
}
|
|
||||||
stats[1]++;
|
|
||||||
return false;
|
|
||||||
} else if(has_to_be == 'p' && pc != 1) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Wrong number of physics colle at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
stats[1]++;
|
|
||||||
return false;
|
|
||||||
} else if(has_to_be == 'a' && agl != 1) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Wrong number of english colle at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
stats[1]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(has_to_be == 'n') {
|
|
||||||
if(agl == 1) {
|
|
||||||
has_to_be = 'p';
|
|
||||||
} else {
|
|
||||||
has_to_be = 'a';
|
|
||||||
}
|
|
||||||
} else if(has_to_be == 'p') {
|
|
||||||
has_to_be = 'a';
|
|
||||||
} else {
|
|
||||||
has_to_be = 'p';
|
|
||||||
}
|
|
||||||
agl = 0;
|
|
||||||
pc = 0;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp && edt[i].mat == ENGLISH) {
|
|
||||||
agl += 1;
|
|
||||||
} if(edt[i].group == grp && edt[i].mat == PHYSICS) {
|
|
||||||
pc += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 2) Math colles
|
|
||||||
// version 2
|
|
||||||
|
|
||||||
int math = 0;
|
|
||||||
int abort_2 = 0;
|
|
||||||
for(int i = end_id-1; i >= 0+abort_2*(end_id); i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
abort_2 = 1;
|
|
||||||
if(n_colles[grp-1] == 3) {
|
|
||||||
if(math != 0) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of math colles at index %d for group %d (found %d)\n", i, grp, math);
|
|
||||||
}
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(math != 1) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of math colles at index %d for group %d (found %d)\n", i, grp, math);
|
|
||||||
}
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp && edt[i].mat == MATH) {
|
|
||||||
math += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int t = 0;
|
|
||||||
int math = 0;
|
|
||||||
int last_no_math = -1;
|
|
||||||
bool not_seen_empty = true;
|
|
||||||
for(int i = end_id-1; i >= 0; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
//if(i == 0 || i%16 == 15) {
|
|
||||||
t++;
|
|
||||||
if(math != 1 && math != 0) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of math colles at index %d for group %d (found %d)\n", i, grp, math);
|
|
||||||
}
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
} else if(math == 0) {
|
|
||||||
if(!not_seen_empty && last_no_math != -1 && last_no_math != 3) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid rotation of math colles at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
//rintf("--> %d <--\n", t);
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
last_no_math = 0;
|
|
||||||
not_seen_empty = false;
|
|
||||||
} else {
|
|
||||||
if(last_no_math > 3) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Too many math colles at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(last_no_math == -1) {
|
|
||||||
last_no_math++;
|
|
||||||
}
|
|
||||||
last_no_math++;
|
|
||||||
}
|
|
||||||
math = 0;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp && edt[i].mat == MATH) {
|
|
||||||
math += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(last_no_math > 3) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Too many math colles at index %d for group %d\n", 0, grp);
|
|
||||||
}
|
|
||||||
stats[2]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) Count
|
|
||||||
int ncolles = 0;
|
|
||||||
for(int i = end_id-1; i >= 0; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
if(ncolles != 1 && ncolles != 2) {
|
|
||||||
//if(ncolles != n_colles[grp-1]) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of colles at index %d for group %d (found %d)\n", i, grp, ncolles);
|
|
||||||
}
|
|
||||||
stats[3]++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ncolles= 0;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp) {
|
|
||||||
ncolles++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4) Info
|
|
||||||
int inf = 0;
|
|
||||||
int last_no_inf = -1;
|
|
||||||
for(int i = end_id-1; i >= 0; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
if(inf != 0 && inf != 1) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Invalid number of info colles at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
stats[4]++;
|
|
||||||
return false;
|
|
||||||
} else if(inf == 0) {
|
|
||||||
last_no_inf = 0;
|
|
||||||
} else if(last_no_inf > 5) {
|
|
||||||
if(debug) {
|
|
||||||
printf("Too few info colles at index %d for group %d\n", i, grp);
|
|
||||||
}
|
|
||||||
stats[4]++;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if(last_no_inf != -1) {
|
|
||||||
last_no_inf += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inf = 0;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp && edt[i].mat == INFO) {
|
|
||||||
inf += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = end_id-1; i >= 0; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
// Check week
|
|
||||||
}
|
|
||||||
// Detect colles
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
int heuristique_MP2I(creneau* edt,int len_edt, int grp, date end) {
|
|
||||||
|
|
||||||
A - Both colles end at 7PM : -10
|
|
||||||
B - Having the same colleur two weeks in a row : -45
|
|
||||||
C - Having the same colleur at a 3w interval : -25
|
|
||||||
D - Having the same colleur at a 4w interval : -10
|
|
||||||
E - Two colles the same day : -20
|
|
||||||
F - Same date over 2 weeks : -20
|
|
||||||
|
|
||||||
int end_id = get_next_friday(edt, len_edt, end); // index of first date that is later than end
|
|
||||||
|
|
||||||
if(end_id == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int score = 0;
|
|
||||||
int halt = 0;
|
|
||||||
int remaining = 2;
|
|
||||||
creneau* temp = malloc(sizeof(creneau)*16);
|
|
||||||
int len_temp = 0;
|
|
||||||
|
|
||||||
//printf("EndId : %d\n", end_id);
|
|
||||||
|
|
||||||
// A - Colles 7PM (-10)
|
|
||||||
// Check for current week only
|
|
||||||
bool _7pm_1 = false;
|
|
||||||
bool _7pm_2 = false;
|
|
||||||
for(int i = end_id-1; i >= 0+halt; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
score -= 10*(_7pm_1 && _7pm_2);
|
|
||||||
halt = end_id-1;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp && edt[i].date.hour == 18) {
|
|
||||||
//printf("E\n");
|
|
||||||
_7pm_2 = _7pm_1;
|
|
||||||
_7pm_1 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = 0;
|
|
||||||
len_temp = 0;
|
|
||||||
|
|
||||||
// B, C and D : same colleur 2/3/4times in a row (-45)
|
|
||||||
// 4-week check
|
|
||||||
remaining = 4;
|
|
||||||
for(int i = end_id-1; i >= 0+halt; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
remaining -= 1;
|
|
||||||
if(remaining == 0 || i == 0) {
|
|
||||||
bool b = false;
|
|
||||||
int dist = 0;
|
|
||||||
for(int j = 0; j < len_temp; j++) {
|
|
||||||
for(int k = j+1; k < len_temp; k++) {
|
|
||||||
b = str_equal(temp[j].name, temp[k].name);
|
|
||||||
if(b && !(str_equal(temp[j].name, ""))) {
|
|
||||||
dist = date_dist(temp[k].date, temp[j].date);
|
|
||||||
if(dist < 7) {
|
|
||||||
score -= 45;
|
|
||||||
} else if(dist < 14) {
|
|
||||||
score -= 20;
|
|
||||||
} else if(dist < 21) {
|
|
||||||
score -= 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = end_id-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp) {
|
|
||||||
temp[len_temp] = edt[i];
|
|
||||||
len_temp++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = 0;
|
|
||||||
len_temp = 0;
|
|
||||||
|
|
||||||
// E - 2 colles the same day (-20)
|
|
||||||
// single-week check
|
|
||||||
for(int i = end_id-1; i >= 0+halt; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
if(len_temp >= 2) {
|
|
||||||
score -= 20*(temp[0].date.day == temp[1].date.day);
|
|
||||||
}
|
|
||||||
halt = end_id-1;
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp) {
|
|
||||||
temp[len_temp] = edt[i];
|
|
||||||
len_temp++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = 0;
|
|
||||||
len_temp = 0;
|
|
||||||
|
|
||||||
// F - Same over 2 weeks (-10)
|
|
||||||
// 2-week check
|
|
||||||
remaining = 2;
|
|
||||||
for(int i = end_id-1; i >= 0+halt; i--) {
|
|
||||||
if(i == 0 || (date_dist(edt[0].date, edt[i].date)%7 == 4 && date_dist(edt[0].date, edt[i+1].date)%7 != 4)) {
|
|
||||||
remaining -= 1;
|
|
||||||
if(remaining == 0 || i == 0) {
|
|
||||||
int dist = 0;
|
|
||||||
for(int j = 0; j < len_temp; j++) {
|
|
||||||
for(int k = j+1; k < len_temp; k++) {
|
|
||||||
dist = date_dist(temp[k].date, temp[j].date);
|
|
||||||
if(dist == 7 && temp[k].date.hour == temp[j].date.hour) {
|
|
||||||
score -= 20;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = end_id-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(edt[i].group == grp) {
|
|
||||||
temp[len_temp] = edt[i];
|
|
||||||
len_temp++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
halt = 0;
|
|
||||||
len_temp = 0;
|
|
||||||
|
|
||||||
free(temp);
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// typedef struct colleur {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur;
|
// typedef struct colleur {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur;
|
||||||
colleur* get_colleurs(colleur* cl, int len_cl, date d, int* how_many) {
|
colleur* get_colleurs(colleur* cl, int len_cl, date d, int* how_many) {
|
||||||
colleur* res = malloc(sizeof(colleur)*30); // max. 3 colles per creneau
|
colleur* res = malloc(sizeof(colleur)*30); // max. 3 colles per creneau
|
||||||
|
@ -492,238 +126,6 @@ void print_arr(int* arr, int len) {
|
||||||
}
|
}
|
||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void shiftright_ncolles(int n_grps) {
|
|
||||||
for(int i = 0; i < n_grps; i++) {
|
|
||||||
n_colles[i] = (n_colles[i]+1)%4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shiftleft_ncolles(int n_grps) {
|
|
||||||
for(int i = 0; i < n_grps; i++) {
|
|
||||||
if(n_colles[i] == 0) {
|
|
||||||
n_colles[i] = 3;
|
|
||||||
} else {
|
|
||||||
n_colles[i]--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void aux(int* abort, int* weeks_len, creneau* edt, int len_edt, colleur* chads, int n_chads, int n_groups, int n_weeks, int current_grp, int current_week, int current_offset, int starting_group, bool is_first) {
|
|
||||||
// append colles for specified week and group
|
|
||||||
//usleep(100000);
|
|
||||||
print_arr(stats, 10);
|
|
||||||
if(current_week > n_weeks) {
|
|
||||||
printf("Done\n");
|
|
||||||
*abort = true;
|
|
||||||
} else {
|
|
||||||
int n_available_i = 0;
|
|
||||||
int n_available_j = 0;
|
|
||||||
colleur* available_i = malloc(sizeof(colleur));
|
|
||||||
colleur* available_j = malloc(sizeof(colleur));
|
|
||||||
int picked_i = 0;
|
|
||||||
int picked_j = 0;
|
|
||||||
bool pass_i;
|
|
||||||
bool pass_j;
|
|
||||||
bool is_valid_i = false;
|
|
||||||
bool is_valid_j = false;
|
|
||||||
int* perms_i = malloc(sizeof(int)*30);
|
|
||||||
int* perms_j = malloc(sizeof(int)*30);
|
|
||||||
int succ = current_grp+1;
|
|
||||||
if(succ == n_groups+1) {
|
|
||||||
succ = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Colles for week %d, group %d {%d}\n", current_week, current_grp, (1-(*abort))*weeks_len[current_week-1]);
|
|
||||||
|
|
||||||
//for(int i = 0; i < weeks_len[current_week]; i++) { // loop for 1st colle
|
|
||||||
for(int i = 0; i < (1-(*abort))*weeks_len[current_week-1]; i++) { // loop for 1st colle
|
|
||||||
//printf("+1\n");
|
|
||||||
//printf("i(%d -> %d)i\n", current_grp, current_offset+i);
|
|
||||||
//printf(" ");
|
|
||||||
//printf("[%d]\n", current_offset+i);
|
|
||||||
//printf("I\n");
|
|
||||||
if(edt[current_offset+i].group == 0) {
|
|
||||||
free(available_i);
|
|
||||||
//get_colleurs(colleur* cl, int len_cl, date d, int* how_many) {
|
|
||||||
available_i = get_colleurs(chads, n_chads, edt[current_offset+i].date, &n_available_i);
|
|
||||||
if(n_available_i != 0) {
|
|
||||||
generate_random_perm(perms_i, n_available_i);
|
|
||||||
for(int ii = 0; ii < n_available_i; ii++) {
|
|
||||||
picked_i = perms_i[ii];
|
|
||||||
|
|
||||||
if(n_colles[current_grp-1] == 3) {
|
|
||||||
pass_i = available_i[picked_i].mat == PHYSICS || available_i[picked_i].mat == ENGLISH;
|
|
||||||
} else {
|
|
||||||
pass_i = available_i[picked_i].mat == MATH;
|
|
||||||
}
|
|
||||||
if(pass_i) {
|
|
||||||
// choose someone available
|
|
||||||
//picked_i = rand()%n_available_i;
|
|
||||||
|
|
||||||
// add the 1st colle
|
|
||||||
edt[current_offset+i].group = current_grp;
|
|
||||||
str_copy(available_i[picked_i].name, available_i[picked_i].namelen, edt[current_offset+i].name);
|
|
||||||
edt[current_offset+i].mat = available_i[picked_i].mat;
|
|
||||||
|
|
||||||
is_valid_i = is_allowed_MP2I(edt, len_edt, current_grp, edt[current_offset+i].date, 'i');
|
|
||||||
|
|
||||||
if(is_valid_i && *abort == 0) {
|
|
||||||
// /!\ DONT FORGET THE RECURSIVE CALL HERE (in case a group has only 1 colle that week)
|
|
||||||
//aux(weeks_len, edt, chads, n_chads, n_groups, n_weeks, current_grp, current_week, current_offset, starting_group, is_first);
|
|
||||||
|
|
||||||
if(succ == starting_group) {
|
|
||||||
//printf("---------------------------------------------------------\n");
|
|
||||||
shiftright_ncolles(n_groups);
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp, current_week+1, current_offset+weeks_len[current_week-1], current_grp, true);
|
|
||||||
shiftleft_ncolles(n_groups);
|
|
||||||
} else {
|
|
||||||
if(current_grp == n_groups) {
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, current_week, current_offset, starting_group, false);
|
|
||||||
} else {
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp+1, current_week, current_offset, starting_group, is_first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stats[8]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int j = 0; j < (1-(*abort))*weeks_len[current_week-1]*(n_colles[current_grp-1] != 3); j++) { // loop for 2nd colle
|
|
||||||
//printf("j(%d -> %d)j\n", current_grp, current_offset+j);
|
|
||||||
//printf(" ");
|
|
||||||
//printf("[%d]\n", current_offset+i);
|
|
||||||
//printf("I\n");
|
|
||||||
if(edt[current_offset+j].group == 0) {
|
|
||||||
free(available_j);
|
|
||||||
//get_colleurs(colleur* cl, int len_cl, date d, int* how_many) {
|
|
||||||
available_j = get_colleurs(chads, n_chads, edt[current_offset+j].date, &n_available_j);
|
|
||||||
if(n_available_j != 0) {
|
|
||||||
generate_random_perm(perms_j, n_available_j);
|
|
||||||
for(int jj = 0; jj < n_available_j; jj++) {
|
|
||||||
// choose someone available
|
|
||||||
//picked_j = rand()%n_available_j;
|
|
||||||
picked_j = perms_j[jj];
|
|
||||||
|
|
||||||
if(available_j[picked_j].mat != MATH) {
|
|
||||||
|
|
||||||
// add the 1st colle
|
|
||||||
edt[current_offset+j].group = current_grp;
|
|
||||||
str_copy(available_j[picked_j].name, available_j[picked_j].namelen, edt[current_offset+j].name);
|
|
||||||
edt[current_offset+j].mat = available_i[picked_j].mat;
|
|
||||||
|
|
||||||
is_valid_j = is_allowed_MP2I(edt, len_edt, current_grp, edt[current_offset+j].date, 'j');
|
|
||||||
|
|
||||||
if(is_valid_j && *abort == 0) {
|
|
||||||
// THE RECURSIVE CALL
|
|
||||||
//aux(weeks_len, edt, chads, n_chads, n_groups, n_weeks, current_grp, current_week, current_offset, starting_group, is_first);
|
|
||||||
|
|
||||||
if(succ == starting_group) {
|
|
||||||
//printf("---------------------------------------------------------\n");
|
|
||||||
shiftright_ncolles(n_groups);
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp, current_week+1, current_offset+weeks_len[current_week-1], current_grp, true);
|
|
||||||
shiftleft_ncolles(n_groups);
|
|
||||||
} else {
|
|
||||||
if(current_grp == n_groups) {
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, current_week, current_offset, starting_group, false);
|
|
||||||
} else {
|
|
||||||
aux(abort, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp+1, current_week, current_offset, starting_group, is_first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stats[9]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(*abort == 0) {
|
|
||||||
// remove 2nd colle in case it's blocked
|
|
||||||
edt[current_offset+j].group = 0;
|
|
||||||
edt[current_offset+j].name[0] = '\0';
|
|
||||||
edt[current_offset+j].mat = NOTHING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//printf("Occupied 2nd colle\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(*abort == 0) {
|
|
||||||
// remove 1st colle in case it's blocked
|
|
||||||
edt[current_offset+i].group = 0;
|
|
||||||
edt[current_offset+i].name[0] = '\0';
|
|
||||||
edt[current_offset+i].mat = NOTHING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//printf("Occupied 1st colle\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(available_i);
|
|
||||||
free(available_j);
|
|
||||||
free(perms_i);
|
|
||||||
free(perms_j);
|
|
||||||
}
|
|
||||||
//printf("[terminated : group %d with week %d]\n", current_grp, current_week);
|
|
||||||
}
|
|
||||||
|
|
||||||
void generate_colles_v1(creneau* edt, int len_edt, colleur* chads, int n_chads, int n_groups, int n_weeks) {
|
|
||||||
// Fill edt with a colloscope
|
|
||||||
// The final function
|
|
||||||
|
|
||||||
int* weeks_len = malloc(sizeof(int)*n_weeks);
|
|
||||||
int ptr = 0;
|
|
||||||
int current = 1;
|
|
||||||
for(int k = 1; k < len_edt; k++) {
|
|
||||||
if(date_dist(edt[k-1].date, edt[k].date) > 1 || k == len_edt-1) {
|
|
||||||
weeks_len[ptr] = current + (k == len_edt - 1);
|
|
||||||
current = 0;
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
current++;
|
|
||||||
}
|
|
||||||
|
|
||||||
print_arr(weeks_len, n_weeks);
|
|
||||||
|
|
||||||
stats = malloc(sizeof(int)*10);
|
|
||||||
for(int i = 0; i < 10; i++) {
|
|
||||||
stats[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
n_colles = malloc(sizeof(int)*n_groups);
|
|
||||||
for(int i = 0; i < n_groups; i++) {
|
|
||||||
n_colles[i] = i%4;
|
|
||||||
}
|
|
||||||
// invariant : if n_colles[grp-1] = 3 then grp has only 1 colle that week
|
|
||||||
|
|
||||||
|
|
||||||
//print_arr(n_colles, n_groups);
|
|
||||||
//assert(0);
|
|
||||||
|
|
||||||
printf("Entering aux\n");
|
|
||||||
int abort = 0;
|
|
||||||
int* ptrbool = &abort;
|
|
||||||
aux(ptrbool, weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, 1, 0, 1, true);
|
|
||||||
|
|
||||||
//aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, current_week, current_offset, starting_group, false);
|
|
||||||
system("clear");
|
|
||||||
|
|
||||||
print_one_week(edt, len_edt, edt[0].date);
|
|
||||||
printf("\n");
|
|
||||||
print_one_week(edt, len_edt, edt[16].date);
|
|
||||||
printf("\n");
|
|
||||||
print_one_week(edt, len_edt, edt[32].date);
|
|
||||||
printf("\n");
|
|
||||||
print_one_week(edt, len_edt, edt[48].date);
|
|
||||||
|
|
||||||
free(weeks_len);
|
|
||||||
free(stats);
|
|
||||||
free(n_colles);
|
|
||||||
printf("It's over\n");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// ----------------------------------------------------- //
|
// ----------------------------------------------------- //
|
||||||
// ------------------| NEW ALGORITHM |------------------ //
|
// ------------------| NEW ALGORITHM |------------------ //
|
||||||
// ----------------------------------------------------- //
|
// ----------------------------------------------------- //
|
||||||
|
@ -1082,7 +484,7 @@ int score(creneau* edt, int len_edt, int grp, int n_weeks) {
|
||||||
score -= 5;
|
score -= 5;
|
||||||
}
|
}
|
||||||
if(dist < 5 && edt[i].date.hour == 18 && edt[j].date.hour == 18) {
|
if(dist < 5 && edt[i].date.hour == 18 && edt[j].date.hour == 18) {
|
||||||
score -= 10;
|
score -= 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1099,13 +501,13 @@ int score(creneau* edt, int len_edt, int grp, int n_weeks) {
|
||||||
if(str_equal(met[k], met[p])) {
|
if(str_equal(met[k], met[p])) {
|
||||||
switch(edt[i].mat) {
|
switch(edt[i].mat) {
|
||||||
case MATH:
|
case MATH:
|
||||||
score -= 15;
|
score -= 12;
|
||||||
break;
|
break;
|
||||||
case PHYSICS:
|
case PHYSICS:
|
||||||
score -= 15;
|
score -= 12;
|
||||||
break;
|
break;
|
||||||
case ENGLISH:
|
case ENGLISH:
|
||||||
score -= 15;
|
score -= 12;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1428,10 +830,3 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
|
||||||
free(weeks_len);
|
free(weeks_len);
|
||||||
destroy_matrix(occ_data, n_groups);
|
destroy_matrix(occ_data, n_groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue