diff --git a/SAE2 b/SAE2 index 378a5f3..1e94dd1 100755 Binary files a/SAE2 and b/SAE2 differ diff --git a/includes/charge.h b/includes/charge.h index c3be7ce..4714c70 100644 --- a/includes/charge.h +++ b/includes/charge.h @@ -29,14 +29,14 @@ int max(int a, int b); int lenListeDevis(ListeDevis l); int longueurMaxNomEntreprise(ListeDevis ldevis); int nombrePred(char travaux[], Precedence prec[], int tlog); +int calculerDureeProjet(Tache **tachesTriees, int nbTaches); void displayDevis(Devis d); void displayOffre(Offre *o); void displayListeDevis(ListeDevis l); void afficherDevisEntreprise(Offre **tabTravaux); void displayPrecedences(Precedence *tabP, int tlog); void afficherTaches(Tache **tachesTriees, int p_tmax); -void enfiler(ListeAttente **file, Tache *tache); -void initialiserFileAttente(Tache **tabTache, int nbTaches, ListeAttente **fileAttente); +void enfiler(ListeAttente *file, Tache *tache); Offre *newOffre(char *travauxName); Booleen emptyListe(ListeDevis l); Booleen emptyOffre(Offre *o); @@ -47,9 +47,9 @@ Liste lstSucc(char travaux[], Precedence prec[], int tlog); ListeDevis del(ListeDevis l); ListeDevis insert(ListeDevis l, Devis d); ListeDevis newListeDevis(void); -Tache *defiler(ListeAttente **file); Tache *trouverTache(Tache **tabTache, int nbTaches, char *nom); +Tache* defiler(ListeAttente *file); +ListeAttente* initialiserFileAttente(void); - -void traiterTaches(Tache **tabTache, int p_tmax); \ No newline at end of file +ListeAttente* traiterTaches(Tache **tabTache, int p_tmax); diff --git a/includes/main.h b/includes/main.h index a75b478..585445f 100644 --- a/includes/main.h +++ b/includes/main.h @@ -1,6 +1 @@ -#include "charge.h" - - -#define TMAXTRAV 8 -#define TRACE false - +#include "charge.h" \ No newline at end of file diff --git a/includes/structures.h b/includes/structures.h index 6fb39ad..4a3a5f2 100644 --- a/includes/structures.h +++ b/includes/structures.h @@ -2,6 +2,9 @@ #include #include +#define TMAXTRAV 8 +#define TRACE false + typedef struct { char *nomE; @@ -49,8 +52,8 @@ typedef struct char travauxSucc[30]; } Precedence; -typedef struct fileAtt -{ - Tache *tac; //Demander si on peut pointeur -> moins lourd - struct fileAtt *nxt; -} ListeAttente; +typedef struct fileAtt { + Tache *tab[TMAXTRAV]; + int debut; + int fin; +} ListeAttente; \ No newline at end of file diff --git a/obj/structures.o b/obj/structures.o index f4730c0..aaf79bb 100644 Binary files a/obj/structures.o and b/obj/structures.o differ diff --git a/srcs/part4.c b/srcs/part4.c index 5a66271..c837eb2 100644 --- a/srcs/part4.c +++ b/srcs/part4.c @@ -1,40 +1,35 @@ #include "../includes/main.h" -void traiterTaches(Tache **tabTache, int p_tmax) +ListeAttente* traiterTaches(Tache **tabTache, int p_tmax) { int i; int dateCourante; - ListeAttente *file; Tache *tacheCourante; - Liste successeurs; Tache *successeur; - - file = NULL; - initialiserFileAttente(tabTache, p_tmax, &file); + Liste successeurs; + ListeAttente *file = initialiserFileAttente(); + + for (i = 0; i < p_tmax; i++) + if (tabTache[i]->nbPred == 0) + enfiler(file, tabTache[i]); + while (!estVide(file)) { - tacheCourante = defiler(&file); + tacheCourante = defiler(file); dateCourante = tacheCourante->dateDebut; successeurs = tacheCourante->succ; + while (successeurs) { successeur = trouverTache(tabTache, p_tmax, successeurs->tache); successeur->dateDebut = max(successeur->dateDebut, dateCourante + tacheCourante->duree); successeur->nbPred--; + if (successeur->nbPred == 0) - enfiler(&file, successeur); + enfiler(file, successeur); successeurs = successeurs->nxt; } } - for (i = 0; i < p_tmax; i++) - { - if (tabTache[i]->nbPred > 0) - { - printf("toutes les taches n'ont pas ete executees"); - exit(1); - } - } - - // nouveau tri fusion pour l'ordre des taches -} \ No newline at end of file + return (file); +} diff --git a/srcs/structures.c b/srcs/structures.c index 27821d8..d2f3c16 100644 --- a/srcs/structures.c +++ b/srcs/structures.c @@ -28,13 +28,22 @@ Liste newListe(void) } //file -void initialiserFileAttente(Tache **tabTache, int nbTaches, ListeAttente **fileAttente) +ListeAttente* initialiserFileAttente(void) { - for (int i = 0; i < nbTaches; i++) - if (tabTache[i]->nbPred == 0) - enfiler(fileAttente, tabTache[i]); -} + ListeAttente *file; + + file = malloc(sizeof(ListeAttente)); + if (!file) + { + printf("Erreur d'allocation mémoire\n"); + exit(1); + } + file->debut = 0; + file->fin = 0; + + return (file); +} /*------------verifications------------*/ @@ -53,11 +62,11 @@ Booleen emptyOffre(Offre *o) } // file -Booleen estVide(ListeAttente *file) -{ - return (file == NULL); +Booleen estVide(ListeAttente *file) { + return (file->debut == file->fin); } + /*-------------insertions---------------*/ // Insere un devis en tete de la liste des devis @@ -94,23 +103,16 @@ Liste insertSucc(Liste l, char travaux[]) } //file -void enfiler(ListeAttente **file, Tache *tache) +void enfiler(ListeAttente *file, Tache *tache) { - ListeAttente *nouveauMaillon; - ListeAttente *courant; - - nouveauMaillon = malloc(sizeof(ListeAttente)); - nouveauMaillon->tac = tache; - nouveauMaillon->nxt = NULL; - if (*file == NULL) - *file = nouveauMaillon; - else - { - courant = *file; - while (courant->nxt != NULL) - courant = courant->nxt; - courant->nxt = nouveauMaillon; + if ((file->fin + 1) % TMAXTRAV == file->debut) + { + printf("File d'attente pleine\n"); + exit(1); } + + file->tab[file->fin] = tache; + file->fin = (file->fin + 1) % TMAXTRAV; } @@ -141,26 +143,20 @@ ListeDevis del(ListeDevis l) free(md->dev.nomE); free(md->dev.adresse); free(md); - return l; + return (l); } //file -Tache *defiler(ListeAttente **file) +Tache* defiler(ListeAttente *file) { - ListeAttente *premierMaillon; Tache *tache; + if (file->debut == file->fin) + return (NULL); - if (*file == NULL) - return NULL; - - premierMaillon = *file; - tache = premierMaillon->tac; - *file = premierMaillon->nxt; - free(premierMaillon); - + tache = file->tab[file->debut]; + file->debut = (file->debut + 1) % TMAXTRAV; return (tache); } - /*---------------calculs----------------*/ // Calcule la longueur de la liste de devis @@ -173,7 +169,7 @@ int lenListeDevis(ListeDevis l) len++; l=l->suiv; } - return len; + return (len); } int lenMaxNomEntreprise(ListeDevis ldevis) @@ -190,7 +186,7 @@ int lenMaxNomEntreprise(ListeDevis ldevis) maxLen = len; ldevis = ldevis->suiv; } - return maxLen; + return (maxLen); } // Calcule le nombre de precedences pour un travail donne @@ -340,19 +336,10 @@ void displayPrecedences(Precedence *tabP, int tlog) int i; printf("Liste des precedences :\n"); - for (i = 0; i < tlog; i++) { + for (i = 0; i < tlog; i++) printf("\t%s\t\t : \t%s\n", tabP[i].travauxPrec, tabP[i].travauxSucc); - } } -void afficherTaches(Tache **tachesTriees, int p_tmax) -{ - int i; - - printf("Tâches triées par date de début :\n"); - for (i = 0; i < p_tmax; i++) - printf("la tache: %s, debute : %d\n", tachesTriees[i]->tache, tachesTriees[i]->dateDebut); -} // Partie 4 (à trier)