diff --git a/algorithm.c b/algorithm.c index 6b5a442..89f41eb 100644 --- a/algorithm.c +++ b/algorithm.c @@ -736,9 +736,10 @@ bool is_overlap(creneau* edt, int len_edt, int id) { 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) { - topic rotation = start_rotation; - int math = mth; +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) + int info = inf; // info (1/6) int r; // randomize the 1st date int k = 0; // offset @@ -767,18 +768,59 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu remaining_to_add++; math--; } - remaining_to_add++; if(rotation == ENGLISH) { rotation = PHYSICS; } else { rotation = ENGLISH; } + remaining_to_add++; // physics/english + // initialize/reset variables r = rand()%weeklen; halt = 0; found = false; + info++; + // info colle + while(info == 5) { + if(edt[k+r%weeklen].group == 0 && edt[k+r%weeklen].length == 2) { + // if creneau is empty + // import all colleurs available + free(dudes); + dudes = get_colleurs(chads, len_chads, edt[k+r%weeklen].date, &len_dudes); + len_perm = len_dudes; + + // if there are colleurs available + if(len_dudes != 0) { + + // randomize the order of colleurs + generate_random_perm(perm, len_perm); + + // for each one of them, add his colle for selected group pf and only if + // - 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) { + add_colle(edt, chads, grp, k+r%weeklen, perm[dude]); + found = true; + info = 0; + } + } + } + } + if(!found && halt > weeklen) { + info = 0; + printf("Warning : skipping info colle for week %d and group %d\n", week+1, grp); + } + r++; + halt++; + } + // reset the variables + r = rand()%16; + found = false; + halt = 0; + // if there is a math colle to add, enter this loop while(remaining_to_add == 2) { @@ -898,16 +940,16 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group 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); + 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[16].date); + print_one_week(edt, len_edt, edt[19].date); printf("\n"); - print_one_week(edt, len_edt, edt[32].date); + print_one_week(edt, len_edt, edt[38].date); printf("\n"); - print_one_week(edt, len_edt, edt[48].date); + print_one_week(edt, len_edt, edt[57].date); write_to_file("output.csv", edt, len_edt); printf("Completed\n"); diff --git a/main.c b/main.c index 9d9dab6..5412270 100644 --- a/main.c +++ b/main.c @@ -9,8 +9,8 @@ int main() { creneau* edt = import_creneaux("file.txt", 76); int len_creneau = 76; - colleur* dudes = import_colleurs("some_data.txt", 12, 68); - int n_colleurs = 12; + colleur* dudes = import_colleurs("some_data.txt", 13, len_creneau); + int n_colleurs = 13; // {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur; diff --git a/output.csv b/output.csv new file mode 100644 index 0000000..b0044bb --- /dev/null +++ b/output.csv @@ -0,0 +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 +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 +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 +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 +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 +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 +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 +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 +17,1,3,2024,1,0,none,none +18,1,3,2024,1,0,none,none