and now it's fully working
This commit is contained in:
parent
dea9f499ed
commit
57eb465d91
212
algorithm.c
212
algorithm.c
|
@ -52,6 +52,7 @@ int get_fst_offset(creneau* edt, date d) {
|
|||
}
|
||||
|
||||
bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
||||
|
||||
/* conditions (AND) :
|
||||
1) Alternate between physics and english
|
||||
2) Pattern for math colles is exactly 3-1-3-1-...
|
||||
|
@ -66,7 +67,8 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
|||
|
||||
//printf("EndId : %d\n", end_id);
|
||||
|
||||
// 1) PC/AGL alternance
|
||||
// 1) PC/AGL alternance
|
||||
|
||||
int agl = 0;
|
||||
int pc = 0;
|
||||
char has_to_be = 'n'; // 'n' = not set, 'a' = AGL and 'p' = PC
|
||||
|
@ -91,6 +93,10 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
|||
} else {
|
||||
has_to_be = 'a';
|
||||
}
|
||||
} else if(has_to_be == 'p') {
|
||||
has_to_be = 'a';
|
||||
} else {
|
||||
has_to_be = 'p';
|
||||
}
|
||||
agl = 0;
|
||||
pc = 0;
|
||||
|
@ -101,6 +107,7 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
|||
pc += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2) Math colles
|
||||
int math = 0;
|
||||
|
@ -136,7 +143,7 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) {
|
|||
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(n_colles != 1 && n_colles != 2) {
|
||||
printf("Invalid number of colles at index %d for group %d (found %d)", i, grp, n_colles);
|
||||
printf("Invalid number of colles at index %d for group %d (found %d)\n", i, grp, n_colles);
|
||||
return false;
|
||||
}
|
||||
n_colles= 0;
|
||||
|
@ -189,7 +196,7 @@ int heuristique_MP2I(creneau* edt,int len_edt, int grp, date end) {
|
|||
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 : -10
|
||||
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
|
||||
|
||||
|
@ -305,11 +312,202 @@ int heuristique_MP2I(creneau* edt,int len_edt, int grp, date end) {
|
|||
return score;
|
||||
}
|
||||
|
||||
/*
|
||||
void generate_colles_v1(creneau* edt, int len_edt, int n_groups, colleur* chads, int n_chads) {
|
||||
|
||||
bool is_equal_date(date d1, date d2) {
|
||||
return (d1.hour == d2.hour && d1.day == d2.day && d2.month == d1.month && d2.year == d1.year);
|
||||
}
|
||||
|
||||
// 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* res = malloc(sizeof(colleur)*20); // max. 3 colles per creneau
|
||||
//printf("X\n");
|
||||
int ptr = 0;
|
||||
//printf("[]\n");
|
||||
for(int i = 0; i < len_cl; i++) {
|
||||
for(int j = 0; j < cl[i].n_disp; j++) {
|
||||
if(is_equal_date(cl[i].disp[j], d)) {
|
||||
//printf("%s\n", cl[i].name);
|
||||
if(ptr >= 20) {
|
||||
printf("warning : too many colleurs detected for a creneau\n");
|
||||
*how_many = 0;
|
||||
return res;
|
||||
}
|
||||
res[ptr] = cl[i];
|
||||
ptr++;
|
||||
j = cl[i].n_disp;
|
||||
}
|
||||
}
|
||||
}
|
||||
*how_many = ptr;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void aux(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);
|
||||
if(current_week > n_weeks) {
|
||||
printf("Done\n");
|
||||
assert(0);
|
||||
} 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 is_valid_i = false;
|
||||
bool is_valid_j = false;
|
||||
int succ = current_grp+1;
|
||||
if(succ == n_groups+1) {
|
||||
succ = 1;
|
||||
}
|
||||
|
||||
printf("Colles for week %d, group %d\n", current_week, current_grp);
|
||||
|
||||
//for(int i = 0; i < weeks_len[current_week]; i++) { // loop for 1st colle
|
||||
for(int i = 0; i < 16; 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) {
|
||||
// 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);
|
||||
} else {
|
||||
is_valid_i = false;
|
||||
}
|
||||
|
||||
if(is_valid_i) {
|
||||
// /!\ 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");
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, succ, current_week+1, current_offset+weeks_len[current_week-1], succ, true);
|
||||
} else {
|
||||
if(current_grp == n_groups) {
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, current_week, current_offset, starting_group, false);
|
||||
} else {
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp+1, current_week, current_offset, starting_group, is_first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 0; j < 16; j++) { // loop for 1st 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) {
|
||||
// choose someone available
|
||||
picked_j = rand()%n_available_j;
|
||||
|
||||
// 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);
|
||||
} else {
|
||||
is_valid_j = false;
|
||||
}
|
||||
|
||||
if(is_valid_j) {
|
||||
// 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");
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, succ, current_week+1, current_offset+weeks_len[current_week-1], succ, true);
|
||||
} else {
|
||||
if(current_grp == n_groups) {
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, 1, current_week, current_offset, starting_group, false);
|
||||
} else {
|
||||
aux(weeks_len, edt, len_edt, chads, n_chads, n_groups, n_weeks, current_grp+1, current_week, current_offset, starting_group, is_first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(n_available_j != 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(n_available_i != 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);
|
||||
}
|
||||
//printf("[terminated : group %d with week %d]\n", current_grp, current_week);
|
||||
}
|
||||
|
||||
|
||||
void print_arr(int* arr, int len) {
|
||||
printf("[");
|
||||
for(int i = 0; i < len; i++) {
|
||||
printf("%d ", arr[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
weeks_len[3] = 16;
|
||||
|
||||
print_arr(weeks_len, n_weeks);
|
||||
|
||||
aux(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);
|
||||
|
||||
free(weeks_len);
|
||||
printf("It's over\n");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
51
file.txt
51
file.txt
|
@ -61,53 +61,4 @@
|
|||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
12 4 3 2024
|
||||
13 4 3 2024
|
||||
18 4 3 2024
|
||||
17 5 3 2024
|
||||
18 5 3 2024
|
||||
14 6 3 2024
|
||||
15 6 3 2024
|
||||
16 6 3 2024
|
||||
17 6 3 2024
|
||||
18 6 3 2024
|
||||
14 7 3 2024
|
||||
15 7 3 2024
|
||||
18 7 3 2024
|
||||
16 8 3 2024
|
||||
17 8 3 2024
|
||||
18 8 3 2024
|
||||
12 11 3 2024
|
||||
13 11 3 2024
|
||||
18 11 3 2024
|
||||
17 12 3 2024
|
||||
18 12 3 2024
|
||||
14 13 3 2024
|
||||
15 13 3 2024
|
||||
16 13 3 2024
|
||||
17 13 3 2024
|
||||
18 13 3 2024
|
||||
14 14 3 2024
|
||||
15 14 3 2024
|
||||
18 14 3 2024
|
||||
16 15 3 2024
|
||||
17 15 3 2024
|
||||
18 15 3 2024
|
||||
12 18 3 2024
|
||||
13 18 3 2024
|
||||
18 18 3 2024
|
||||
17 19 3 2024
|
||||
18 19 3 2024
|
||||
14 20 3 2024
|
||||
15 20 3 2024
|
||||
16 20 3 2024
|
||||
17 20 3 2024
|
||||
18 20 3 2024
|
||||
14 21 3 2024
|
||||
15 21 3 2024
|
||||
18 21 3 2024
|
||||
16 22 3 2024
|
||||
17 22 3 2024
|
||||
18 22 3 2024
|
||||
$
|
||||
18 1 3 2024
|
22
main.c
22
main.c
|
@ -4,6 +4,7 @@
|
|||
|
||||
int main() {
|
||||
printf("Starting\n");
|
||||
srand(time(NULL));
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||
printf("error initializing SDL: %s\n", SDL_GetError());
|
||||
}
|
||||
|
@ -13,20 +14,17 @@ int main() {
|
|||
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
|
||||
SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_BLEND);
|
||||
|
||||
creneau* edt = import_creneaux("file.txt", 112);
|
||||
int len_creneau = 112;
|
||||
creneau* edt = import_creneaux("file.txt", 64);
|
||||
int len_creneau = 64;
|
||||
|
||||
colleur* dudes = import_colleurs("some_data.txt", 7, 64);
|
||||
int n_colleurs = 7;
|
||||
|
||||
//printf("%d %d %d %d\n", edt[10].date.hour, edt[10].date.day, edt[10].date.month, edt[10].date.year);
|
||||
|
||||
date d1 = {18, 14, 2, 2024};
|
||||
|
||||
//printf("%d\n", date_dist(d1, d1));
|
||||
|
||||
//printf("%d %d %d %d\n", edt[70].date.hour, edt[70].date.day, edt[70].date.month, edt[70].date.year);
|
||||
|
||||
//print_one_week(rend, edt, 112, d1);
|
||||
|
||||
|
||||
/*
|
||||
edt[9].group = 1;
|
||||
edt[9].mat = INFO;
|
||||
edt[9].name = "Rapin";
|
||||
|
@ -40,6 +38,12 @@ int main() {
|
|||
if(is_allowed_MP2I(edt,len_creneau, 1, d1)) {
|
||||
printf("Score : %d\n", heuristique_MP2I(edt, 112, 1, d1));
|
||||
}
|
||||
*/
|
||||
|
||||
// {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur;
|
||||
|
||||
generate_colles_v1(edt, len_creneau, dudes, n_colleurs, 7, 4);
|
||||
//generate_colles_v1(edt, len_creneau, dudes, n_colleurs, 15, 4);
|
||||
|
||||
/*
|
||||
date d1 = {19, 1, 3, 2024};
|
||||
|
|
|
@ -0,0 +1,470 @@
|
|||
Mullaert
|
||||
MATH
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Rapin
|
||||
MATH
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Colin
|
||||
PHYSICS
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Poupy
|
||||
PHYSICS
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Belaggoune
|
||||
ENGLISH
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Mann
|
||||
ENGLISH
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
Jospin
|
||||
INFO
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
+
|
||||
$
|
105
structure.c
105
structure.c
|
@ -131,9 +131,112 @@ bool str_equal(char* s1, char* s2) {
|
|||
}
|
||||
|
||||
void str_copy(char* src, int l1, char* dest) {
|
||||
/* put the word length as l1, \0 NOT included */
|
||||
/* put the word length as l1, \0 NOT included in l1 */
|
||||
for(int i = 0; i < l1; i++) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
dest[l1] = '\0';
|
||||
}
|
||||
|
||||
colleur* import_colleurs(char* filename, int n_colleurs, int max_available) {
|
||||
/*
|
||||
|
||||
file has the following format :
|
||||
name
|
||||
mat
|
||||
dates (date*)
|
||||
-
|
||||
name2
|
||||
mat2
|
||||
dates2
|
||||
-
|
||||
name3
|
||||
...
|
||||
$
|
||||
|
||||
*/
|
||||
FILE* ptr = fopen(filename, "r");
|
||||
char c = fgetc(ptr);
|
||||
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
|
||||
colleur* res = malloc(sizeof(colleur)*n_colleurs);
|
||||
|
||||
char* word = malloc(sizeof(char)*30);
|
||||
int wordlen = 0;
|
||||
|
||||
int buffer = 0;
|
||||
|
||||
int date_ptr = 0;
|
||||
|
||||
int current = 0; // 0 = name, 1 = mat, 2+ = dates
|
||||
int colleur_ptr = 0;
|
||||
|
||||
while(c != EOF && c != '$') {
|
||||
if(c == '\n') {
|
||||
if(current == 0) {
|
||||
word[wordlen] = '\0';
|
||||
res[colleur_ptr].name = malloc(sizeof(char)*30);
|
||||
str_copy(word, wordlen, res[colleur_ptr].name);
|
||||
res[colleur_ptr].namelen = wordlen;
|
||||
} else if(current == 1) {
|
||||
if(word[0] == 'M') { // math
|
||||
res[colleur_ptr].mat = MATH;
|
||||
} else if(word[0] == 'P') { // physics
|
||||
res[colleur_ptr].mat = PHYSICS;
|
||||
} else if(word[0] == 'E') { // english
|
||||
res[colleur_ptr].mat = ENGLISH;
|
||||
} else if(word[0] == 'I') { // info
|
||||
res[colleur_ptr].mat = INFO;
|
||||
} else {
|
||||
word[wordlen] = '\0';
|
||||
printf("Wait that's illegal (%s)\n", word);
|
||||
assert(0);
|
||||
}
|
||||
res[colleur_ptr].disp = malloc(sizeof(date)*max_available);
|
||||
} else {
|
||||
res[colleur_ptr].disp[current-2].year = buffer;
|
||||
}
|
||||
current++;
|
||||
wordlen = 0;
|
||||
buffer = 0;
|
||||
date_ptr = 0;
|
||||
} else if(c == '+') {
|
||||
res[colleur_ptr].n_disp = current-2;
|
||||
current = 0;
|
||||
colleur_ptr++;
|
||||
|
||||
c = fgetc(ptr); // always a '\n', this to avoid some seg fault
|
||||
} else {
|
||||
if(current <= 1) {
|
||||
word[wordlen] = c;
|
||||
wordlen++;
|
||||
} else {
|
||||
if((int)(c) >= 48 && (int)(c) <= 57) {
|
||||
buffer *= 10;
|
||||
buffer += (int)(c) - 48;
|
||||
} else {
|
||||
if(date_ptr == 0) {
|
||||
res[colleur_ptr].disp[current-2].hour = buffer;
|
||||
} else if(date_ptr == 1) {
|
||||
res[colleur_ptr].disp[current-2].day = buffer;
|
||||
} else if(date_ptr == 2) {
|
||||
res[colleur_ptr].disp[current-2].month = buffer;
|
||||
} else {
|
||||
printf("Oh no (%d)\n", date_ptr);
|
||||
assert(0);
|
||||
}
|
||||
buffer = 0;
|
||||
date_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//printf("%c", c);
|
||||
c = fgetc(ptr);
|
||||
}
|
||||
// {char* name; int namelen; topic mat; date* disp; int n_disp;}
|
||||
|
||||
printf("Successfully imported colleurs\n");
|
||||
fclose(ptr);
|
||||
free(word);
|
||||
|
||||
return res;
|
||||
}
|
Loading…
Reference in New Issue