From 98df9a36fe2197fa5e847167c0ea7f726445cc31 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 8 Apr 2024 22:18:16 +0200 Subject: [PATCH] minor fixes --- algorithm.c | 42 ++++++++++++++++++++++++++++++++++++------ main.c | 7 +++++-- structure.c | 3 +++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/algorithm.c b/algorithm.c index e2050dd..32dc491 100644 --- a/algorithm.c +++ b/algorithm.c @@ -2,9 +2,10 @@ int get_date_index(creneau* edt, int len_creneau, date d) { // could be done in log(n), I know + // yields the 1st occurence of d in edt int x = -1; for(int i = 0; i < len_creneau; i++) { - x = date_dist(edt[i].date, d); + x = date_dist(d, edt[i].date); if(x >= 0) { return i; } @@ -12,6 +13,27 @@ int get_date_index(creneau* edt, int len_creneau, date d) { return -1; } +array get_all_date_index(creneau* edt, int len_edt, date d) { + array arr; + arr.a = malloc(sizeof(int)*8); + arr.memlen = 8; + arr.len = 0; + + int x = -1; + int halt = 0; + for(int i = 0; i < len_edt-halt; i++) { + x = date_dist(d, edt[i].date); + if(x == 0) { + arr.a[arr.len] = i; + arr.len++; + } else if(x > 0) { + halt = len_edt; + } + } + + return arr; +} + int get_next_friday(creneau* edt, int len_creneau, date d) { // could be done in log(n), I know again int x = -1; @@ -133,13 +155,9 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) { printf("Invalid number of info colles at index %d for group %d\n", i, grp); return false; } else if(inf == 0) { - if(last_no_inf != -1 && last_no_inf != 5) { - printf("Invalid rotation of info colles at index %d for group %d\n", i, grp); - return false; - } last_no_inf = 0; } else if(last_no_inf > 5) { - printf("Too many info colles at index %d for group %d\n", i, grp); + printf("Too few info colles at index %d for group %d\n", i, grp); return false; } else { if(last_no_inf != -1) { @@ -164,6 +182,18 @@ bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end) { } */ +int heuristique(creneau* edt,int len_edt, int grp, date end) { + /* + - Both colles end at 7PM : -10 + - Having the same colleur two weeks in a row : -45 + - Having the same colleur at a 3w interval : -25 + - Having the same colleur at a 4w interval : -10 + - Two colles the same day : -20 + - Same date over 2 weeks : -10 + */ + return 0; +} + /* void generate_colles_v1(creneau* edt, int len_edt, int n_groups, colleur* chads, int n_chads) { diff --git a/main.c b/main.c index 4f9d298..2bb1212 100644 --- a/main.c +++ b/main.c @@ -25,15 +25,18 @@ int main() { //print_one_week(rend, edt, 112, d1); - edt[3].group = 1; - edt[3].mat = ENGLISH; + /* edt[6].group = 1; edt[6].mat = INFO; edt[20].group = 1; edt[20].mat = PHYSICS; + edt[1].group = 1; + edt[1].mat = ENGLISH; edt[21].group = 1; edt[21].mat = MATH; is_allowed_MP2I(edt,len_creneau, 1, d1); + */ + /* date d1 = {19, 1, 3, 2024}; diff --git a/structure.c b/structure.c index de263ea..8a191b5 100644 --- a/structure.c +++ b/structure.c @@ -21,6 +21,9 @@ typedef struct creneau {date date; int group; char* name; topic mat;} creneau; typedef struct colleur {char* name; topic mat; date* disp; int n_disp;} colleur; // available creneaux for the colleurs +typedef struct array {int* a; int len; int memlen;} array; +// yes + static int width = 1200; static int height = 900;