Compare commits

...

2 Commits

Author SHA1 Message Date
Valentin Moguérou be83812716 Ajout d'un Makefile 2024-04-15 23:56:46 +02:00
Valentin Moguérou 52fa0c1789 Réorganisation aka Exorcisation 2024-04-15 23:56:36 +02:00
8 changed files with 157 additions and 29 deletions

34
Makefile Normal file
View File

@ -0,0 +1,34 @@
CC=gcc
FLAGS=-g -Wall -Wextra -Wpedantic
LFLAGS=
all: bin/main
OBJECTS = obj/main.o obj/structure.o obj/display.o obj/algorithm.o
bin/main: bin $(OBJECTS)
$(CC) -o $@ $(LFLAGS) $(FLAGS) $(OBJECTS)
obj/main.o: main.c obj
$(CC) -o $@ -c $(FLAGS) $<
obj/structure.o: structure.c structure.h obj
$(CC) -o $@ -c $(FLAGS) $<
obj/display.o: display.c display.h obj
$(CC) -o $@ -c $(FLAGS) $<
obj/algorithm.o: algorithm.c algorithm.h obj
$(CC) -o $@ -c $(FLAGS) $<
bin:
mkdir -p bin
obj:
mkdir -p obj
.PHONY: clean
clean:
rm -rf bin/ obj/

View File

@ -1,4 +1,8 @@
#include "display.c"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "algorithm.h"
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);

40
algorithm.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef ALGORITHM_H_INCLUDED
#define ALGORITHM_H_INCLUDED
#include "structure.h"
bool is_equal_date(date d1, date d2);
int get_date_index(creneau* edt, int len_creneau, date d);
array get_all_date_index(creneau* edt, int len_edt, date d);
int get_next_friday(creneau* edt, int len_creneau, date d);
int get_fst_offset(creneau* edt, date d);
bool is_allowed_MP2I(creneau* edt, int len_edt, int grp, date end);
int heuristique_MP2I(creneau* edt, int len_edt, int grp, date end);
colleur *get_colleurs(colleur *cl, int len_cl, date d, int *how_many);
void add_colle(creneau *edt, colleur *chads, int grp, int id_edt, int id_chad);
void remove_coll(creneau *edt, int id_edt);
bool is_overlap(creneau *edt, int len_edt, int id);
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 write_to_file(char *filename, creneau *edt, int len_edt);
int score(creneau *edt, int len_edt, int grp);
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

View File

@ -1,4 +1,6 @@
#include "structure.c"
#include <stdio.h>
#include "structure.h"
/*
void remove_lanes(int n) {
@ -298,4 +300,4 @@ void print_all_colleurs(colleur* chads, int n_chads) {
for(int c = 0; c < n_chads; c++) {
printf("Colleur %s with %d available :\n", chads[c].name, chads[c].n_disp);
}
}
}

12
display.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef DISPLAY_H_INCLUDED
#define DISPLAY_H_INCLUDED
#include "structure.h"
void print_one_week(creneau *edt, int len_creneau, date start);
void print_all_edt(creneau *edt, int len_edt, int n_weeks, int len_oneweek);
void print_all_colleurs(colleur *chads, int n_chads);
#endif

6
main.c
View File

@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include "algorithm.c"
#include "structure.h"
#include "algorithm.h"
// gcc -g -Wall -Wextra -Wpedantic main.c -lSDL2 -lSDL2_image -lm -o main
// ./main MP2I-creneaux.txt 33 MP2I-colleurs.txt 16 6 15 output.csv

View File

@ -3,34 +3,11 @@
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>
typedef enum topic {NOTHING, MATH, PHYSICS, ENGLISH, FRENCH, INFO} topic;
// colles subjects
typedef struct date {int hour; int day; int month; int year;} date; /* format is {hour, day, month, year} */
// nothing to say here
typedef struct room {char building; int id;} room;
// rooms
// building can be C, M, R or V
typedef struct creneau {int length; date date; int group; char* name; int namelen; topic mat; room salle;} creneau;
// one créneau de colle
// /!\ 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;
// available creneaux for the colleurs
typedef struct array {int* a; int len; int memlen;} array;
// yes
#include "structure.h"
//static int width = 1200;
//static int height = 900;
int* stats;
int* n_colles;
int date_dist(date d1, date d2) { /* returns distance between d1 and d2 in days
if d2 is sooner than d1, it will return -1 */
if(d2.month == d1.month && d2.year == d1.year) {
@ -483,4 +460,4 @@ int str_to_int(char* s) {
i++;
}
return buffer/10;
}
}

55
structure.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef STRUCTURE_H_INCLUDED
#define STRUCTURE_H_INCLUDED
#include <stdbool.h>
extern int* stats;
extern int* n_colles;
typedef enum topic {NOTHING, MATH, PHYSICS, ENGLISH, FRENCH, INFO} topic;
// colles subjects
typedef struct date {int hour; int day; int month; int year;} date; /* format is {hour, day, month, year} */
// nothing to say here
typedef struct room {char building; int id;} room;
// rooms
// building can be C, M, R or V
typedef struct creneau {int length; date date; int group; char* name; int namelen; topic mat; room salle;} creneau;
// one créneau de colle
// /!\ 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;
// available creneaux for the colleurs
typedef struct array {int* a; int len; int memlen;} array;
// yes
int date_dist(date d1, date d2);
bool is_sorted(creneau *edt, int len);
creneau *import_creneaux(char *filename, int size);
bool str_equal(char *s1, char *s2);
void str_copy(char *src, int l1, char *dest);
colleur *import_colleurs(char *filename, int n_colleurs, int max_available);
date increment_date(date d, int inc);
creneau *import_creneaux_oneweek(char *filename, int len_file, int n_weeks);
void expand(colleur *guy, int id, int n_weeks);
colleur *import_colleurs_oneweek(char *filename, int n_colleurs, int n_weeks, int len_oneweek);
int str_to_int(char *s);
#endif