fix
This commit is contained in:
parent
202b5ffc32
commit
c0bfdababc
149
src/algorithm.c
149
src/algorithm.c
|
@ -758,7 +758,6 @@ void move_colle(creneau* edt, int len_edt, int id_src, int id_dest) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -768,11 +767,11 @@ void swap_colle(creneau* edt, int len_edt, int id_src, int id_dest) {
|
|||
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;
|
||||
//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++) {
|
||||
int mem_id(creneau* edt, int len_edt, int grp, char* colleur) {
|
||||
for(int i = 0; i < len_edt; i++) {
|
||||
if(edt[i].group == grp && str_equal(edt[i].name, colleur)) {
|
||||
return i;
|
||||
}
|
||||
|
@ -1147,147 +1146,6 @@ topic get_mat_from_id(colleur* dudes, int n_dudes, int id) {
|
|||
return NOTHING;
|
||||
}
|
||||
|
||||
int** generate_matrix(int lines, int columns, int def) {
|
||||
int** mat = malloc(sizeof(int*)*lines);
|
||||
for(int i = 0; i < lines; i++) {
|
||||
mat[i] = malloc(sizeof(int)*columns);
|
||||
for(int j = 0; j < columns; j++) {
|
||||
mat[i][j] = def;
|
||||
}
|
||||
}
|
||||
return mat;
|
||||
}
|
||||
|
||||
void destroy_matrix(int** m, int li) {
|
||||
for(int i = 0; i < li; i++) {
|
||||
free(m[i]);
|
||||
}
|
||||
free(m);
|
||||
}
|
||||
|
||||
bool retreive_indexes(creneau* edt, int len_edt, int* p1, int* p2, int g1, int g2, char* n1, char* n2, int n_weeks) {
|
||||
int* indexes_1 = malloc(sizeof(int)*n_weeks);
|
||||
int* indexes_2 = malloc(sizeof(int)*n_weeks);
|
||||
int ptr_1 = 0;
|
||||
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++;
|
||||
} else if(edt[i].group == g2 && str_equal(edt[i].name, n2)) {
|
||||
indexes_2[ptr_2] = i;
|
||||
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) {
|
||||
free(indexes_1);
|
||||
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) {
|
||||
*p1 = indexes_1[i];
|
||||
*p2 = indexes_2[j];
|
||||
|
||||
free(indexes_1);
|
||||
free(indexes_2);
|
||||
return true;
|
||||
} else {
|
||||
if(friday_1 > friday_2) {
|
||||
i--;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(indexes_1);
|
||||
free(indexes_2);
|
||||
return false;
|
||||
}
|
||||
|
||||
void occurencies(creneau* edt, int len_edt, colleur* dudes, int n_groups, int n_colleurs, int n_weeks) {
|
||||
//printf("{%d}\n", n_groups);
|
||||
int max_occ = 1;
|
||||
int** res = generate_matrix(n_groups, n_colleurs, 0);
|
||||
|
||||
for(int c = 0; c < len_edt; c++) {
|
||||
if(edt[c].group != 0) {
|
||||
res[edt[c].group-1][get_colleur_id(dudes, n_colleurs, edt[c].name)] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*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 < 3; it++) {
|
||||
for(int grp = 0; grp < n_groups; grp++) {
|
||||
for(int dud = 0; dud < n_colleurs; dud++) {
|
||||
if(res[grp][dud] > max_occ) {
|
||||
for(int grp2 = 0; grp2 < n_groups*(1-halt); grp2++) {
|
||||
if(grp2 != grp) {
|
||||
for(int dud2 = 0; dud2 < n_colleurs*(1-halt); dud2++) {
|
||||
if(dud2 != dud && res[grp2][dud2] > max_occ && res[grp][dud2] < max_occ && res[grp2][dud] < max_occ && get_mat_from_id(dudes, n_colleurs, dud) == get_mat_from_id(dudes, n_colleurs, dud2)) {
|
||||
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
res[grp][dud] -= 1;
|
||||
res[grp2][dud2] -= 1;
|
||||
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;
|
||||
//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);
|
||||
halt = true;
|
||||
dud--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
halt = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for(int k = 0; k < n_groups; k++) {
|
||||
printf("Group %d : ", k+1);
|
||||
print_arr(res[k], n_colleurs);
|
||||
}
|
||||
printf("\n");*/
|
||||
|
||||
destroy_matrix(res, n_groups);
|
||||
}
|
||||
|
||||
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 start = time(NULL);
|
||||
int* weeks_len = malloc(sizeof(int)*n_weeks);
|
||||
|
@ -1334,7 +1192,6 @@ void aux_2(creneau* edt, int len_edt, colleur* chads, int len_chads, int n_group
|
|||
//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);
|
||||
}
|
||||
occurencies(edt, len_edt, chads, n_groups, len_chads, n_weeks);
|
||||
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);
|
||||
|
|
|
@ -46,7 +46,7 @@ void move_colle(creneau* edt, int len_edt, int id_src, int id_dest);
|
|||
|
||||
void swap_colle(creneau* edt, int len_edt, int id_src, int id_dest);
|
||||
|
||||
int mem_id(creneau* edt, int len_edt, int grp, char* colleur, int offset);
|
||||
int mem_id(creneau* edt, int len_edt, int grp, char* colleur);
|
||||
|
||||
bool is_overlap(creneau *edt, int len_edt, int id);
|
||||
|
||||
|
@ -66,14 +66,6 @@ char* get_name_from_id(colleur* dudes, int n_dudes, int id);
|
|||
|
||||
topic get_mat_from_id(colleur* dudes, int n_dudes, int id);
|
||||
|
||||
int** generate_matrix(int lines, int columns, int def);
|
||||
|
||||
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);
|
||||
|
||||
void aux_2(creneau *edt, int len_edt, colleur *chads, int len_chads, int n_groups, int n_weeks, int n_sim, char *outname);
|
||||
|
||||
#endif
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -34,7 +34,7 @@ void print_help()
|
|||
{
|
||||
printf("Colloscope - A program that generates a colloscope for French 'classe prépas'. By Alexandre Aboujaib\n");
|
||||
printf("Licensed under the terms of the GNU GPL version 3 or later.\n\n");
|
||||
printf("Usage: colloscope [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <output>\n\n");
|
||||
printf("Usage: colloscope [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iter> <output>\n\n");
|
||||
printf("Available options :\n");
|
||||
printf(" -q Quiet mode\n");
|
||||
printf(" -v Verbose mode\n");
|
||||
|
@ -51,11 +51,11 @@ int main(int argc, char **argv) {
|
|||
print_help();
|
||||
exit(0);
|
||||
}
|
||||
else if (argc==8)
|
||||
else if (argc==9 && argv[1][0]!='-')
|
||||
{
|
||||
offset=0;
|
||||
}
|
||||
else if (argc==9 && argv[1][0]=='-')
|
||||
else if (argc==10 && 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> <output>\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <n_iters> <output>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,8 @@ int main(int argc, char **argv) {
|
|||
int n_colleurs = str_to_int(argv[4+offset]);
|
||||
int n_weeks = str_to_int(argv[5+offset]);
|
||||
int n_groups = str_to_int(argv[6+offset]);
|
||||
char* path_output = argv[7+offset];
|
||||
int n_iter = str_to_int(argv[7+offset]);
|
||||
char* path_output = argv[8+offset];
|
||||
|
||||
|
||||
if (quiet) {
|
||||
|
@ -112,7 +113,7 @@ 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);
|
||||
|
||||
aux_2(edt, len_edt, dudes, n_colleurs, n_groups, n_weeks, 2500, path_output);
|
||||
aux_2(edt, len_edt, dudes, n_colleurs, n_groups, n_weeks, n_iter, path_output);
|
||||
|
||||
for(int i = 0; i < len_edt; i++) {
|
||||
free(edt[i].name);
|
||||
|
|
|
@ -145,8 +145,8 @@ 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 in l1 */
|
||||
for(int i = 0; i < l1; i++) {
|
||||
/* put the word src with length l1, \0 NOT included, in dest */
|
||||
for(int i = 0; i <= l1; i++) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
dest[l1] = '\0';
|
||||
|
@ -191,6 +191,7 @@ colleur* import_colleurs(char* filename, int n_colleurs, int max_available) {
|
|||
res[colleur_ptr].name = malloc(sizeof(char)*30);
|
||||
str_copy(word, wordlen, res[colleur_ptr].name);
|
||||
res[colleur_ptr].namelen = wordlen;
|
||||
res[colleur_ptr].id = colleur_ptr;
|
||||
} else if(current == 1) {
|
||||
if(word[0] == 'M') { // math
|
||||
res[colleur_ptr].mat = MATH;
|
||||
|
@ -414,6 +415,7 @@ colleur* import_colleurs_oneweek(char* filename, int n_colleurs, int n_weeks, in
|
|||
assert(0);
|
||||
}
|
||||
res[colleur_ptr].disp = malloc(sizeof(date)*len_oneweek);
|
||||
res[colleur_ptr].id = colleur_ptr;
|
||||
} else {
|
||||
res[colleur_ptr].disp[current-2].year = buffer;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct creneau {int length; date date; int group; char* name; int namele
|
|||
// /!\ creneau has to be sorted by ascending dates
|
||||
// with edt being a creneau*, it is required to have edt[0] be a Monday and edt[len(edt)-1] has to be a Friday
|
||||
|
||||
typedef struct colleur {char* name; int namelen; topic mat; date* disp; int n_disp;} colleur;
|
||||
typedef struct colleur {char* name; int namelen; topic mat; date* disp; int n_disp; int id;} colleur;
|
||||
// available creneaux for the colleurs
|
||||
|
||||
typedef struct array {int* a; int len; int memlen;} array;
|
||||
|
|
Loading…
Reference in New Issue