some cleanup to remove useless functions
This commit is contained in:
parent
00cf558f55
commit
2b236d3681
101
src/algorithm.c
101
src/algorithm.c
|
@ -42,33 +42,11 @@ 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;
|
||||
for(int i = 0; i < len_creneau; i++) {
|
||||
x = date_dist(d, edt[i].date);
|
||||
//printf("%d\n", x);
|
||||
if(x >= 0 && (i == len_creneau-1 || date_dist(d, edt[i+1].date) - x > 1)) {
|
||||
return i;
|
||||
}
|
||||
|
@ -76,18 +54,13 @@ int get_next_friday(creneau* edt, int len_creneau, date d) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int get_fst_offset(creneau* edt, date d) {
|
||||
return (date_dist(edt[0].date, d));
|
||||
}
|
||||
// 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)*30); // max. 3 colles per creneau
|
||||
//printf("X\n");
|
||||
int ptr = 0;
|
||||
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 >= 30) {
|
||||
warn("Too many colleurs detected for a creneau\n");
|
||||
}
|
||||
|
@ -126,16 +99,12 @@ void print_arr(int* arr, int len) {
|
|||
}
|
||||
printf("]\n");
|
||||
}
|
||||
// ----------------------------------------------------- //
|
||||
// ------------------| NEW ALGORITHM |------------------ //
|
||||
// ----------------------------------------------------- //
|
||||
|
||||
void add_colle(creneau* edt, colleur* chads, int grp, int id_edt, int id_chad) {
|
||||
edt[id_edt].group = grp;
|
||||
edt[id_edt].namelen = chads[id_chad].namelen;
|
||||
str_copy(chads[id_chad].name, chads[id_chad].namelen, edt[id_edt].name);
|
||||
edt[id_edt].mat = chads[id_chad].mat;
|
||||
//printf("%s %d\n", chads[id_chad].name, chads[id_chad].namelen);
|
||||
//printf("{%d %s %d %d %d}\n", edt[id_edt].group, edt[id_edt].name, edt[id_edt].namelen, (int)(edt[id_edt].mat), id_edt);
|
||||
}
|
||||
|
||||
void remove_colle(creneau* edt, int id_edt) {
|
||||
|
@ -159,20 +128,6 @@ void move_colle(creneau* edt, int len_edt, int id_src, int id_dest) {
|
|||
remove_colle(edt, id_src);
|
||||
}
|
||||
|
||||
void swap_colle(creneau* edt, int len_edt, int id_src, int id_dest) {
|
||||
// BROKEN
|
||||
if((id_src < len_edt && id_dest < len_edt) == false) {
|
||||
printf("Bad\n");
|
||||
exit(1);
|
||||
}
|
||||
int dest_grp = edt[id_dest].group;
|
||||
|
||||
edt[id_dest].group = edt[id_src].group;
|
||||
|
||||
//printf("%d %d\n", edt[id_src].group, dest_grp);
|
||||
edt[id_src].group = edt[id_src].group;
|
||||
}
|
||||
|
||||
int mem_id(creneau* edt, int len_edt, int grp, char* colleur, int offset) {
|
||||
for(int i = offset; i < len_edt; i++) {
|
||||
if(edt[i].group == grp && str_equal(edt[i].name, colleur)) {
|
||||
|
@ -260,12 +215,11 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
int math_dude = 0; // length of colleur*
|
||||
int weeklen;
|
||||
|
||||
//printf("\n");
|
||||
for(int week = 0; week < n_weeks; week++) {
|
||||
|
||||
weeklen = weeks_len[week];
|
||||
// update what colles to add
|
||||
if(math == 0) {
|
||||
if(mat_halt == 1 || math == 0) {
|
||||
math = mat_halt-1;
|
||||
} else {
|
||||
remaining_to_add++;
|
||||
|
@ -278,7 +232,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
}
|
||||
|
||||
remaining_to_add++; // physics/english
|
||||
//printf("%d -> (%d %d)\n", grp, week, remaining_to_add);
|
||||
|
||||
// initialize/reset variables
|
||||
r = rand()%weeklen;
|
||||
|
@ -291,7 +244,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
if(edt[k+r%weeklen].mat == NOTHING && edt[k+r%weeklen].length == 2) {
|
||||
// if creneau is empty
|
||||
// import all colleurs available
|
||||
//printf("E");
|
||||
colleur* dudes = get_colleurs(chads, len_chads, edt[k+r%weeklen].date, &len_dudes);
|
||||
len_perm = len_dudes;
|
||||
|
||||
|
@ -309,10 +261,8 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
for(int dude = 0; dude < len_perm*(1-found); dude++) {
|
||||
if(dudes[perm[dude]].mat == INFO) {
|
||||
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
|
||||
//printf("E");
|
||||
found = true;
|
||||
info = 0;
|
||||
//printf("+info for week %d and group %d (index %d)\n", week, grp, k+r%weeklen);
|
||||
}
|
||||
}
|
||||
free(perm);
|
||||
|
@ -321,7 +271,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
}
|
||||
if(!found && halt > weeklen) {
|
||||
info = 0;
|
||||
//printf("Warning : skipping info colle for week %d and group %d\n", week+1, grp);
|
||||
*skip_count += 1;
|
||||
}
|
||||
r++;
|
||||
|
@ -360,7 +309,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
} else {
|
||||
found = true;
|
||||
remaining_to_add--;
|
||||
//printf("+math for week %d and group %d (index %d)\n", week, grp, k+r%weeklen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,7 +318,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
}
|
||||
if(!found && halt > weeklen) {
|
||||
remaining_to_add--;
|
||||
//printf("Warning : skipping math colle for week %d and group %d\n", week+1, grp);
|
||||
*skip_count += 1;
|
||||
}
|
||||
r++;
|
||||
|
@ -396,16 +343,13 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
}
|
||||
}
|
||||
for(int dude = 0; dude < len_perm*(1-found); dude++) {
|
||||
//printf("%d\n", chads[perm[dude]]);
|
||||
if(dudes[perm[dude]].mat == rotation) {
|
||||
add_colle(edt, dudes, grp, k+r%weeklen, perm[dude]);
|
||||
if(math_dude > free_math_space(edt, len_edt, k+r%weeklen) || is_overlap(edt, len_edt, k+r%weeklen)) {
|
||||
//if(math_dude > free_math_space(edt, len_edt, k+r%weeklen)) {
|
||||
remove_colle(edt, k+r%weeklen);
|
||||
} else {
|
||||
found = true;
|
||||
remaining_to_add--;
|
||||
///rintf("+secondary for week %d and group %d (index %d)\n", week, grp, k+r%weeklen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -415,7 +359,6 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
|
|||
}
|
||||
if(!found && halt > weeks_len[week]) {
|
||||
remaining_to_add--;
|
||||
//printf("Warning : skipping secondary colle for week %d and group %d\n", week+1, grp);
|
||||
*skip_count += 1;
|
||||
}
|
||||
r++;
|
||||
|
@ -493,7 +436,6 @@ int score(creneau* edt, int len_edt, int grp, int n_weeks) {
|
|||
char** met = malloc(sizeof(char*)*3*n_weeks);
|
||||
int p = 0;
|
||||
for(int i = 0; i < len_edt; i++) {
|
||||
//printf("%d\n", i);
|
||||
if(edt[i].group == grp) {
|
||||
met[p] = malloc(sizeof(char)*30);
|
||||
str_copy(edt[i].name, edt[i].namelen, met[p]);
|
||||
|
@ -537,7 +479,6 @@ int get_colleur_id(colleur* dudes, int n_dudes, char* target) {
|
|||
char* get_name_from_id(colleur* dudes, int n_dudes, int id) {
|
||||
for(int i = 0; i < n_dudes; i++) {
|
||||
if(id == dudes[i].id) {
|
||||
//printf("{%s}", dudes[i].name);
|
||||
return dudes[i].name;
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +519,6 @@ bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g
|
|||
int ptr_2 = 0;
|
||||
|
||||
for(int i = 0; i < len_edt; i++) {
|
||||
//printf("%d\n", i);
|
||||
if(edt[i].group == g1 && str_equal(edt[i].name, n1)) {
|
||||
indexes_1[ptr_1] = i;
|
||||
ptr_1++;
|
||||
|
@ -587,10 +527,6 @@ bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g
|
|||
ptr_2++;
|
||||
}
|
||||
}
|
||||
|
||||
//print_arr(indexes_1, ptr_1);
|
||||
//print_arr(indexes_2, ptr_2);
|
||||
|
||||
int j = 0;
|
||||
for(int i = 0; i < ptr_1; i++) {
|
||||
if(j >= ptr_2) {
|
||||
|
@ -598,7 +534,6 @@ bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g
|
|||
free(indexes_2);
|
||||
return false;
|
||||
} else {
|
||||
//printf("{%d %d}\n", i, j);
|
||||
int friday_1 = get_next_friday(edt, len_edt, edt[indexes_1[i]].date);
|
||||
int friday_2 = get_next_friday(edt, len_edt, edt[indexes_2[j]].date);
|
||||
if(friday_1 == friday_2) {
|
||||
|
@ -623,7 +558,6 @@ bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g
|
|||
}
|
||||
|
||||
int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks, bool is_debug) {
|
||||
//printf("{%d}\n", n_groups);
|
||||
int max_occ = 1;
|
||||
int** res = generate_matrix(n_groups, n_colleurs, 0);
|
||||
|
||||
|
@ -633,12 +567,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
}
|
||||
}
|
||||
|
||||
/*for(int k = 0; k < n_groups; k++) {
|
||||
printf("Group %d : ", k+1);
|
||||
print_arr(res[k], n_colleurs);
|
||||
}
|
||||
printf("\n"); // caused a minor panic */
|
||||
|
||||
bool halt = false;
|
||||
for(int it = 0; it < 5*(1-is_debug); it++) {
|
||||
for(int grp = 0; grp < n_groups; grp++) {
|
||||
|
@ -652,7 +580,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
int id_src;
|
||||
int id_dest;
|
||||
if(retreive_indexes(edt, len_edt, &id_src, &id_dest, grp+1, grp2+1, get_name_from_id(dudes, n_colleurs, dud), get_name_from_id(dudes, n_colleurs, dud2), n_weeks)) {;
|
||||
// RESOLVED : both colles need to be the same week
|
||||
|
||||
if(id_src < 0 || id_dest < 0 || id_src >= len_edt || id_dest >= len_edt) {
|
||||
printf("Uh oh (%d %d)\n", id_src, id_dest);
|
||||
|
@ -664,7 +591,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
res[grp2][dud] += 1;
|
||||
res[grp][dud2] += 1;
|
||||
|
||||
//printf("%d %d | ", edt[id_src].group, edt[id_dest].group);
|
||||
edt[id_src].group += edt[id_dest].group;
|
||||
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
|
||||
edt[id_src].group -= edt[id_dest].group;
|
||||
|
@ -675,7 +601,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
res[grp2][dud] += 1;
|
||||
res[grp][dud2] += 1;
|
||||
|
||||
//printf("%d %d | ", edt[id_src].group, edt[id_dest].group);
|
||||
edt[id_src].group += edt[id_dest].group;
|
||||
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
|
||||
edt[id_src].group -= edt[id_dest].group;
|
||||
|
@ -685,7 +610,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
res[grp2][dud] += 1;
|
||||
res[grp][dud2] += 1;
|
||||
|
||||
//printf("%d %d | ", edt[id_src].group, edt[id_dest].group);
|
||||
edt[id_src].group += edt[id_dest].group;
|
||||
edt[id_dest].group = edt[id_src].group - edt[id_dest].group;
|
||||
edt[id_src].group -= edt[id_dest].group;
|
||||
|
@ -693,11 +617,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
halt = true;
|
||||
dud--;
|
||||
}
|
||||
|
||||
//printf("%d %d\n", edt[id_src].group, edt[id_dest].group);
|
||||
|
||||
//printf("[%d %d - %d] <==> [%d %d - %d]\n", grp+1, id_src, edt[id_src].group, grp2+1, id_dest, edt[id_dest].group);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -709,13 +628,6 @@ int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for(int k = 0; k < n_groups; k++) {
|
||||
printf("Group %d : ", k+1);
|
||||
print_arr(res[k], n_colleurs);
|
||||
}
|
||||
printf("\n");*/
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -763,22 +675,17 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
|
|||
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);
|
||||
info("%d%% Completed (current max is %d/%d)", 100*a/n_sim, max_score, 100*n_groups);
|
||||
a += n_sim/100;
|
||||
}
|
||||
local_score = 0;
|
||||
local_min = 100;
|
||||
skipped = 0;
|
||||
for(int i = 0; i < n_groups; i++) {
|
||||
//for(int i = 0; i < 1; 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, i%6, &skipped);
|
||||
add_colles_for_group_MP2I(weeks_len, edt, len_edt, chads, len_chads, n_weeks, i+1, (topic)(2+i%2), i%3, i%info_app, &skipped, math_halt, info_app);
|
||||
add_colles_for_group_MP2I(weeks_len, edt, len_edt, chads, len_chads, n_weeks, i+1, (topic)(2+i%2), i%math_halt, i%info_app, &skipped, math_halt, info_app);
|
||||
}
|
||||
//int** temp_data = generate_matrix(n_groups, len_chads, 0);
|
||||
int** temp_data = occurencies(edt, len_edt, chads, n_groups, len_chads, n_weeks, false);
|
||||
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, n_weeks);
|
||||
local_score += temp;
|
||||
group_temp[i] = temp;
|
||||
|
|
Loading…
Reference in New Issue