added score function and bulk testing

This commit is contained in:
alexandre 2024-04-13 20:00:39 +02:00
parent b094606989
commit 5dab5ad86a
3 changed files with 164 additions and 67 deletions

View File

@ -718,7 +718,7 @@ void remove_colle(creneau* edt, int id_edt) {
edt[id_edt].mat = NOTHING;
}
bool is_overlap(creneau* edt, int len_edt, int id) {
bool is_overlap(creneau* edt, int len_edt, int id) { // detect if a colleur has 2 colles at the same time
int k = 1;
while(id+k < len_edt && is_equal_date(edt[id].date, edt[id+k].date)) {
if(str_equal(edt[id].name, edt[id+k].name)) {
@ -736,6 +736,17 @@ bool is_overlap(creneau* edt, int len_edt, int id) {
return false;
}
bool is_overlap_creneau(creneau* edt, int len_edt, int id, int grp) { // detect if a group has 2 overlapping colles
int k = 1;
while((id+k < len_edt && edt[id+k].date.hour - edt[id].date.hour < edt[id].length) && edt[id+k].date.day == edt[id].date.day) {
if(edt[id+k].group == grp) {
return true;
}
k++;
}
return false;
}
void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleur* chads, int len_chads, int n_weeks, int grp, topic start_rotation, int mth, int inf) {
topic rotation = start_rotation; // physics/english rotation
int math = mth; // math (3/4)
@ -801,7 +812,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
// - he is a INFO colleur
// if a colle has been addded, interrupt the for and while loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(chads[perm[dude]].mat == INFO) {
if(chads[perm[dude]].mat == INFO && !is_overlap_creneau(edt, len_edt, k+r%weeklen, grp)) {
add_colle(edt, chads, grp, k+r%weeklen, perm[dude]);
found = true;
info = 0;
@ -923,8 +934,49 @@ void write_to_file(char* filename, creneau* edt, int len_edt) {
fclose(ptr);
}
int min(int x, int y) {
if(x < y) {
return x;
}
return y;
}
void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_groups, int n_weeks) {
int max(int x, int y) {
if(x > y) {
return x;
}
return y;
}
int score(creneau* edt, int len_edt, int grp) {
int score = 100;
int dist = 0;
for(int i = 0; i < len_edt; i++) {
for(int j = i+1; j < len_edt; j++) {
if(edt[i].group == grp && edt[j].group == grp) {
dist = date_dist(edt[i].date, edt[j].date);
if(dist == 0) {
score -= 7;
}
if(str_equal(edt[i].name, edt[j].name)) {
score -= 5*min(0, 28-dist);
}
if(dist == 7 && edt[i].date.hour == edt[j].date.hour) {
score -= 5;
}
if(dist < 7 && edt[i].date.hour == 18 && edt[j].date.hour == 18) {
score -= 10;
}
}
}
}
return score;
}
void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_groups, int n_weeks, int n_sim) {
int start = time(NULL);
int* weeks_len = malloc(sizeof(int)*n_weeks);
// this list is used to tell the above code what index of edt it has to go to search for a colle
int ptr = 0;
@ -938,11 +990,7 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
current++;
}
for(int i = 0; i < n_groups; i++) {
printf("Adding colles for group %d...\n", i+1);
add_colles_for_group_MP2I(weeks_len, edt, len_edt, chads, len_chads, n_weeks, i+1, (topic)(2+i%2), i%4,1+i%4);
}
/*
print_one_week(edt, len_edt, edt[0].date);
printf("\n");
print_one_week(edt, len_edt, edt[19].date);
@ -950,9 +998,60 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
print_one_week(edt, len_edt, edt[38].date);
printf("\n");
print_one_week(edt, len_edt, edt[57].date);
*/
printf("\n");
int max_score = 0;
int global_min = 0;
int screwed_group = 0;
int local_score = 0;
int local_min = 0;
int local_group = 0;
int temp = 0;
int a = n_sim/100;
for(int k = 0; k < n_sim*(1 - (max_score == n_groups*100)); k++) {
if(k >= a) {
printf("\x1b[1F");
printf("\x1b[2K");
printf("%d Completed (current max is %d/%d)\n", 100*a/n_sim, max_score, 100*n_groups);
a += n_sim/100;
}
local_score = 0;
local_min = 100;
for(int i = 0; i < n_groups; i++) {
//rintf("Adding colles for group %d...\n", i+1);
add_colles_for_group_MP2I(weeks_len, edt, len_edt, chads, len_chads, n_weeks, i+1, (topic)(2+i%2), i%4,1+i%4);
}
for(int i = 0; i < n_groups; i++) {
//printf("Score for group %d : %d\n", i+1, score(edt, len_edt, i+1));
temp = score(edt, len_edt, i+1);
local_score += temp;
if(local_min > temp) {
local_min = temp;
local_group = i+1;
}
}
if(local_score > max_score) {
max_score = local_score;
screwed_group = local_group;
global_min = local_min;
write_to_file("output.csv", edt, len_edt);
printf("Completed\n");
}
for(int r = 0; r < len_edt; r++) {
remove_colle(edt, r);
}
}
printf("\x1b[1F");
printf("\x1b[2K");
if(max_score == 100*n_groups) {
printf("Interrupting early due to a perfect score achieved\n");
} else {
printf("100 Completed, best score is %d/%d\n", max_score, 100*n_groups);
printf("Most screwed group is %d with a score of %d/100\n", screwed_group, global_min);
}
int end = time(NULL);
printf("Took %ds to found\n", end-start);
}
@ -964,5 +1063,3 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group

2
main.c
View File

@ -18,7 +18,7 @@ int main() {
/*int* a = malloc(sizeof(int)*10);
generate_random_perm(a, 10);
print_arr(a, 10);*/
aux_2(edt, len_creneau, dudes, n_colleurs, 7, 4);
aux_2(edt, len_creneau, dudes, n_colleurs, 7, 4, 3000);
//generate_colles_v1(edt, len_creneau, dudes, n_colleurs, 9, 4);
//generate_colles_v1(edt, len_creneau, dudes, n_colleurs, 15, 4);

View File

@ -1,77 +1,77 @@
hour,day,month,year,length,group,colleur,matiere
12,5,2,2024,1,2,Rapin,Maths
13,5,2,2024,1,1,Herbaud,Anglais
18,5,2,2024,1,2,Chibani,Physique
17,6,2,2024,1,3,Rapin,Maths
18,6,2,2024,1,3,Belaggoune,Anglais
14,7,2,2024,1,4,Chevalier,Physique
12,5,2,2024,1,1,Herbaud,Anglais
13,5,2,2024,1,2,Colin,Physique
18,5,2,2024,1,0,none,none
17,6,2,2024,1,4,Poupy,Physique
18,6,2,2024,1,6,Carpintero,Maths
14,7,2,2024,1,7,Mullaert,Maths
14,7,2,2024,2,4,Jospin,Info
14,7,2,2024,2,0,none,none
14,7,2,2024,2,0,none,none
15,7,2,2024,1,5,Mann,Anglais
16,7,2,2024,1,4,Mullaert,Maths
17,7,2,2024,1,7,Mullaert,Maths
18,7,2,2024,1,7,Belaggoune,Anglais
14,8,2,2024,1,6,Chevalier,Physique
15,8,2,2024,1,6,Mullaert,Maths
18,8,2,2024,1,0,none,none
15,7,2,2024,1,3,Boully,Maths
16,7,2,2024,1,3,Belaggoune,Anglais
17,7,2,2024,1,6,Chibani,Physique
18,7,2,2024,1,5,Le_Gourielec,Anglais
14,8,2,2024,1,4,Rapin,Maths
15,8,2,2024,1,2,Rapin,Maths
18,8,2,2024,1,7,Belaggoune,Anglais
16,9,2,2024,1,0,none,none
17,9,2,2024,1,0,none,none
18,9,2,2024,1,0,none,none
12,12,2,2024,1,0,none,none
13,12,2,2024,1,2,Le_Gourielec,Anglais
18,12,2,2024,1,5,Boully,Maths
17,13,2,2024,1,4,Le_Gourielec,Anglais
18,13,2,2024,1,3,Carpintero,Maths
14,14,2,2024,1,5,Chevalier,Physique
12,12,2,2024,1,7,Chibani,Physique
13,12,2,2024,1,0,none,none
18,12,2,2024,1,3,Colin,Physique
17,13,2,2024,1,5,Chevalier,Physique
18,13,2,2024,1,0,none,none
14,14,2,2024,1,6,Mann,Anglais
14,14,2,2024,2,3,Jospin,Info
14,14,2,2024,2,7,Jospin,Info
14,14,2,2024,2,0,none,none
15,14,2,2024,1,1,Chevalier,Physique
16,14,2,2024,1,1,Carpintero,Maths
17,14,2,2024,1,3,Poupy,Physique
18,14,2,2024,1,4,Boully,Maths
14,15,2,2024,1,7,Rapin,Maths
15,15,2,2024,1,6,Mann,Anglais
18,15,2,2024,1,7,Colin,Physique
15,14,2,2024,1,7,Rapin,Maths
16,14,2,2024,1,5,Mullaert,Maths
17,14,2,2024,1,1,Rapin,Maths
18,14,2,2024,1,1,Chevalier,Physique
14,15,2,2024,1,2,Belaggoune,Anglais
15,15,2,2024,1,3,Rapin,Maths
18,15,2,2024,1,4,Boully,Maths
16,16,2,2024,1,0,none,none
17,16,2,2024,1,0,none,none
18,16,2,2024,1,0,none,none
12,19,2,2024,1,4,Colin,Physique
13,19,2,2024,1,6,Poupy,Physique
18,19,2,2024,1,7,Belaggoune,Anglais
17,20,2,2024,1,4,Rapin,Maths
18,20,2,2024,1,0,none,none
14,21,2,2024,1,5,Mann,Anglais
12,19,2,2024,1,0,none,none
13,19,2,2024,1,7,Herbaud,Anglais
18,19,2,2024,1,0,none,none
17,20,2,2024,1,4,Mullaert,Maths
18,20,2,2024,1,6,Boully,Maths
14,21,2,2024,1,0,none,none
14,21,2,2024,2,2,Jospin,Info
14,21,2,2024,2,6,Jospin,Info
14,21,2,2024,2,0,none,none
15,21,2,2024,1,1,Le_Gourielec,Anglais
16,21,2,2024,1,2,Boully,Maths
17,21,2,2024,1,1,Rapin,Maths
18,21,2,2024,1,2,Colin,Physique
14,22,2,2024,1,5,Carpintero,Maths
15,22,2,2024,1,6,Rapin,Maths
18,22,2,2024,1,3,Mann,Anglais
16,23,2,2024,1,0,none,none
15,21,2,2024,1,1,Mullaert,Maths
16,21,2,2024,1,2,Chibani,Physique
17,21,2,2024,1,3,Belaggoune,Anglais
18,21,2,2024,1,5,Mann,Anglais
14,22,2,2024,1,4,Colin,Physique
15,22,2,2024,1,2,Mullaert,Maths
18,22,2,2024,1,1,Mann,Anglais
16,23,2,2024,1,5,Mullaert,Maths
17,23,2,2024,1,0,none,none
18,23,2,2024,1,0,none,none
12,26,2,2024,1,0,none,none
13,26,2,2024,1,7,Chibani,Physique
18,26,2,2024,1,5,Colin,Physique
17,27,2,2024,1,4,Mann,Anglais
18,27,2,2024,1,0,none,none
14,28,2,2024,1,5,Carpintero,Maths
12,26,2,2024,1,7,Chevalier,Physique
13,26,2,2024,1,1,Rapin,Maths
18,26,2,2024,1,2,Belaggoune,Anglais
17,27,2,2024,1,6,Rapin,Maths
18,27,2,2024,1,3,Boully,Maths
14,28,2,2024,1,3,Poupy,Physique
14,28,2,2024,2,1,Jospin,Info
14,28,2,2024,2,5,Jospin,Info
14,28,2,2024,2,0,none,none
15,28,2,2024,1,1,Poupy,Physique
16,28,2,2024,1,1,Rapin,Maths
17,28,2,2024,1,2,Le_Gourielec,Anglais
18,28,2,2024,1,2,Rapin,Maths
14,29,2,2024,1,3,Rapin,Maths
15,29,2,2024,1,6,Carpintero,Maths
18,29,2,2024,1,6,Belaggoune,Anglais
16,1,3,2024,1,7,Rapin,Maths
15,28,2,2024,1,2,Rapin,Maths
16,28,2,2024,1,4,Mann,Anglais
17,28,2,2024,1,5,Mullaert,Maths
18,28,2,2024,1,6,Mann,Anglais
14,29,2,2024,1,7,Carpintero,Maths
15,29,2,2024,1,5,Chevalier,Physique
18,29,2,2024,1,1,Chibani,Physique
16,1,3,2024,1,0,none,none
17,1,3,2024,1,0,none,none
18,1,3,2024,1,0,none,none

1 hour day month year length group colleur matiere
2 12 5 2 2024 1 2 1 Rapin Herbaud Maths Anglais
3 13 5 2 2024 1 1 2 Herbaud Colin Anglais Physique
4 18 5 2 2024 1 2 0 Chibani none Physique none
5 17 6 2 2024 1 3 4 Rapin Poupy Maths Physique
6 18 6 2 2024 1 3 6 Belaggoune Carpintero Anglais Maths
7 14 7 2 2024 1 4 7 Chevalier Mullaert Physique Maths
8 14 7 2 2024 2 4 Jospin Info
9 14 7 2 2024 2 0 none none
10 14 7 2 2024 2 0 none none
11 15 7 2 2024 1 5 3 Mann Boully Anglais Maths
12 16 7 2 2024 1 4 3 Mullaert Belaggoune Maths Anglais
13 17 7 2 2024 1 7 6 Mullaert Chibani Maths Physique
14 18 7 2 2024 1 7 5 Belaggoune Le_Gourielec Anglais
15 14 8 2 2024 1 6 4 Chevalier Rapin Physique Maths
16 15 8 2 2024 1 6 2 Mullaert Rapin Maths
17 18 8 2 2024 1 0 7 none Belaggoune none Anglais
18 16 9 2 2024 1 0 none none
19 17 9 2 2024 1 0 none none
20 18 9 2 2024 1 0 none none
21 12 12 2 2024 1 0 7 none Chibani none Physique
22 13 12 2 2024 1 2 0 Le_Gourielec none Anglais none
23 18 12 2 2024 1 5 3 Boully Colin Maths Physique
24 17 13 2 2024 1 4 5 Le_Gourielec Chevalier Anglais Physique
25 18 13 2 2024 1 3 0 Carpintero none Maths none
26 14 14 2 2024 1 5 6 Chevalier Mann Physique Anglais
27 14 14 2 2024 2 3 Jospin Info
28 14 14 2 2024 2 7 Jospin Info
29 14 14 2 2024 2 0 none none
30 15 14 2 2024 1 1 7 Chevalier Rapin Physique Maths
31 16 14 2 2024 1 1 5 Carpintero Mullaert Maths
32 17 14 2 2024 1 3 1 Poupy Rapin Physique Maths
33 18 14 2 2024 1 4 1 Boully Chevalier Maths Physique
34 14 15 2 2024 1 7 2 Rapin Belaggoune Maths Anglais
35 15 15 2 2024 1 6 3 Mann Rapin Anglais Maths
36 18 15 2 2024 1 7 4 Colin Boully Physique Maths
37 16 16 2 2024 1 0 none none
38 17 16 2 2024 1 0 none none
39 18 16 2 2024 1 0 none none
40 12 19 2 2024 1 4 0 Colin none Physique none
41 13 19 2 2024 1 6 7 Poupy Herbaud Physique Anglais
42 18 19 2 2024 1 7 0 Belaggoune none Anglais none
43 17 20 2 2024 1 4 Rapin Mullaert Maths
44 18 20 2 2024 1 0 6 none Boully none Maths
45 14 21 2 2024 1 5 0 Mann none Anglais none
46 14 21 2 2024 2 2 Jospin Info
47 14 21 2 2024 2 6 Jospin Info
48 14 21 2 2024 2 0 none none
49 15 21 2 2024 1 1 Le_Gourielec Mullaert Anglais Maths
50 16 21 2 2024 1 2 Boully Chibani Maths Physique
51 17 21 2 2024 1 1 3 Rapin Belaggoune Maths Anglais
52 18 21 2 2024 1 2 5 Colin Mann Physique Anglais
53 14 22 2 2024 1 5 4 Carpintero Colin Maths Physique
54 15 22 2 2024 1 6 2 Rapin Mullaert Maths
55 18 22 2 2024 1 3 1 Mann Anglais
56 16 23 2 2024 1 0 5 none Mullaert none Maths
57 17 23 2 2024 1 0 none none
58 18 23 2 2024 1 0 none none
59 12 26 2 2024 1 0 7 none Chevalier none Physique
60 13 26 2 2024 1 7 1 Chibani Rapin Physique Maths
61 18 26 2 2024 1 5 2 Colin Belaggoune Physique Anglais
62 17 27 2 2024 1 4 6 Mann Rapin Anglais Maths
63 18 27 2 2024 1 0 3 none Boully none Maths
64 14 28 2 2024 1 5 3 Carpintero Poupy Maths Physique
65 14 28 2 2024 2 1 Jospin Info
66 14 28 2 2024 2 5 Jospin Info
67 14 28 2 2024 2 0 none none
68 15 28 2 2024 1 1 2 Poupy Rapin Physique Maths
69 16 28 2 2024 1 1 4 Rapin Mann Maths Anglais
70 17 28 2 2024 1 2 5 Le_Gourielec Mullaert Anglais Maths
71 18 28 2 2024 1 2 6 Rapin Mann Maths Anglais
72 14 29 2 2024 1 3 7 Rapin Carpintero Maths
73 15 29 2 2024 1 6 5 Carpintero Chevalier Maths Physique
74 18 29 2 2024 1 6 1 Belaggoune Chibani Anglais Physique
75 16 1 3 2024 1 7 0 Rapin none Maths none
76 17 1 3 2024 1 0 none none
77 18 1 3 2024 1 0 none none