more debug info + mem leak fix

This commit is contained in:
alexandre 2024-04-23 20:51:26 +02:00
parent da52582cc7
commit a9d47591ef
4 changed files with 65 additions and 24 deletions

View File

@ -835,7 +835,7 @@ int free_math_space(creneau* edt, int len_edt, int id) {
return howmany;
}
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, int* skip_count) {
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, int* skip_count, int mat_halt, int info_app) {
topic rotation = start_rotation; // physics/english rotation
int math = mth; // math (3/4)
int info = inf; // info (1/6)
@ -864,7 +864,7 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
weeklen = weeks_len[week];
// update what colles to add
if(math == 0) {
math = 2;
math = mat_halt-1;
} else {
remaining_to_add++;
math--;
@ -885,10 +885,11 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
info++;
// info colle
while(info >= 6) {
if(edt[k+r%weeklen].group == 0 && edt[k+r%weeklen].length == 2) {
while(info >= info_app) {
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;
@ -900,13 +901,16 @@ void add_colles_for_group_MP2I(int* weeks_len, creneau* edt, int len_edt, colleu
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
// - he is a MATH colleur
// - he does not have another colle at the same time (is_overlap)
// if a colle has been addded, interrupt the for andwhile loops
for(int dude = 0; dude < len_perm*(1-found); dude++) {
if(dudes[perm[dude]].mat == INFO && !is_overlap_creneau(edt, len_edt, k+r%weeklen, grp)) {
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);
@ -915,7 +919,7 @@ 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);
//printf("Warning : skipping info colle for week %d and group %d\n", week+1, grp);
*skip_count += 1;
}
r++;
@ -1216,7 +1220,7 @@ bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g
return false;
}
void occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks) {
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);
@ -1234,10 +1238,10 @@ void occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_
printf("\n"); // caused a minor panic */
bool halt = false;
for(int it = 0; it < 3; it++) {
for(int it = 0; it < 3*(1-is_debug); it++) {
for(int grp = 0; grp < n_groups; grp++) {
for(int dud = 0; dud < n_colleurs; dud++) {
if(res[grp][dud] > max_occ) {
if(res[grp][dud] > max_occ && get_mat_from_id(dudes, n_colleurs, dud) != INFO) {
for(int grp2 = 0; grp2 < n_groups*(1-halt); grp2++) {
if(grp2 != grp) {
for(int dud2 = 0; dud2 < n_colleurs*(1-halt); dud2++) {
@ -1285,10 +1289,19 @@ void occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_
}
printf("\n");*/
destroy_matrix(res, n_groups);
return res;
}
void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_groups, int n_weeks, int n_sim, char* outname) {
void copy_matrix(int** src, int lines, int col, int** dest) {
for(int i = 0; i < lines; i++) {
for(int j = 0; j < col; j++) {
dest[i][j] = src[i][j];
}
}
}
void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_groups, int n_weeks, int n_sim, char* outname, int math_halt, int info_app) {
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
@ -1316,6 +1329,7 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
int temp = 0;
int skipped = 0;
int a = 0;
int** occ_data = generate_matrix(n_groups, len_chads, 0);;
info("Testing %d combinations...", n_sim);
printf("\n");
for(int k = 0; k < n_sim*(1 - (max_score == n_groups*100)); k++) {
@ -1332,9 +1346,9 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
//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, -20, &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);
}
occurencies(edt, len_edt, chads, n_groups, len_chads, n_weeks);
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);
@ -1354,11 +1368,13 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
for(int p = 0; p < n_groups; p++) {
group_stats[p] = group_temp[p];
}
copy_matrix(temp_data, n_groups, len_chads, occ_data);
write_to_file(outname, edt, len_edt);
}
for(int r = 0; r < len_edt; r++) {
remove_colle(edt, r);
}
destroy_matrix(temp_data, n_groups);
}
printf("\x1b[1F");
@ -1374,10 +1390,17 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
}
}
int end = time(NULL);
printf("\n");
info("Here is all data regarding colles occurencies :");
for(int k = 0; k < n_groups; k++) {
printf("Group %d : ", (k+1)%10);
print_arr(occ_data[k], len_chads);
}
info("Took %ds to find", end-start);
free(group_stats);
free(group_temp);
free(weeks_len);
destroy_matrix(occ_data, n_groups);
}

View File

@ -54,7 +54,7 @@ bool is_overlap_creneau(creneau* edt, int len_edt, int id, int grp);
int free_math_space(creneau *edt, int len_edt, int id);
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, int *skip_count);
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, int *skip_count, int math_halt, int info_app);
void write_to_file(char *filename, creneau *edt, int len_edt);
@ -72,8 +72,10 @@ void destroy_matrix(int** m, int li);
bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g2, char* n1, char* n2, int n_weeks);
void occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks);
int** occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks, bool is_debug);
void aux_2(creneau *edt, int len_edt, colleur *chads, int len_chads, int n_groups, int n_weeks, int n_sim, char *outname);
void copy_matrix(int** src, int lines, int col, int** dest);
void aux_2(creneau *edt, int len_edt, colleur *chads, int len_chads, int n_groups, int n_weeks, int n_sim, char *outname, int math_halt, int info_app);
#endif

View File

@ -51,11 +51,11 @@ int main(int argc, char **argv) {
print_help();
exit(0);
}
else if (argc==9 && argv[1][0]!='-')
else if (argc==11 && argv[1][0]!='-')
{
offset=0;
}
else if (argc==10 && argv[1][0]=='-')
else if (argc==12 && argv[1][0]=='-')
{
offset=1;
@ -78,7 +78,7 @@ int main(int argc, char **argv) {
}
}
else {
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iters> <output>\n", argv[0]);
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iters> <output> <math_rest> <info_occ>\n", argv[0]);
exit(1);
}
@ -91,7 +91,8 @@ int main(int argc, char **argv) {
int n_groups = str_to_int(argv[6+offset]);
int n_iter = str_to_int(argv[7+offset]);
char* path_output = argv[8+offset];
int math_i = str_to_int(argv[9+offset]);
int info_i = str_to_int(argv[10+offset]);
if (quiet) {
create_logger("colloscope.log", LOG_WARN);
@ -101,7 +102,7 @@ int main(int argc, char **argv) {
create_logger("colloscope.log", LOG_INFO);
}
trace("%d %d %d %d", n_creneaux, n_colleurs, n_weeks, n_groups);
//info("%d %d %d %d", n_creneaux, n_colleurs, n_weeks, n_groups);
info("Starting");
srand(time(NULL));
@ -112,8 +113,20 @@ int main(int argc, char **argv) {
//colleur* dudes = import_colleurs("some_data.txt", 13, len_creneau);
colleur* dudes = import_colleurs_oneweek(path_colleurs, n_colleurs, n_weeks, n_creneaux);
debug("Entries are : ");
debug("Creneaux filename : %s", path_creneaux);
debug("Number of creneaux (for one week) : %d", n_creneaux);
debug("Colleurs filename : %s", path_colleurs);
debug("Number of colleurs (for one week) : %d", n_colleurs);
debug("Output filename : %s", path_output);
debug("Number of weeks : %d", n_weeks);
debug("Number of groups : %d", n_groups);
debug("Number of rolls : %d", n_iter);
debug("Proportion of math colles : %d/%d", math_i, math_i+1);
debug("Proportion of info colles : 1/%d", info_i);
aux_2(edt, len_edt, dudes, n_colleurs, n_groups, n_weeks, n_iter, path_output);
aux_2(edt, len_edt, dudes, n_colleurs, n_groups, n_weeks, n_iter, path_output, math_i, info_i);
for(int i = 0; i < len_edt; i++) {
free(edt[i].name);

View File

@ -403,10 +403,13 @@ colleur* import_colleurs_oneweek(char* filename, int n_colleurs, int n_weeks, in
} else if(current == 1) {
if(word[0] == 'M') { // math
res[colleur_ptr].mat = MATH;
//printf("M");
} else if(word[0] == 'P') { // physics
res[colleur_ptr].mat = PHYSICS;
//printf("P");
} else if(word[0] == 'E') { // english
res[colleur_ptr].mat = ENGLISH;
//printf("E");
} else if(word[0] == 'I') { // info
res[colleur_ptr].mat = INFO;
} else {