Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • e87374u/projet_pne
1 result
Select Git revision
Show changes
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<<<<<<< HEAD
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
=======
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
<?xml version="1.0" encoding="UTF-8"?>
<<<<<<< HEAD
<?xml version="1.0" encoding="UTF-8"?>
=======
<?xml version="1.0" encoding="UTF-8"?>
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<<<<<<< HEAD
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
=======
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/LE PROJET.iml" filepath="$PROJECT_DIR$/.idea/LE PROJET.iml" />
</modules>
</component>
<<<<<<< HEAD
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/LE PROJET.iml" filepath="$PROJECT_DIR$/.idea/LE PROJET.iml" />
</modules>
</component>
=======
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/LE PROJET.iml" filepath="$PROJECT_DIR$/.idea/LE PROJET.iml" />
</modules>
</component>
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
</project>
\ No newline at end of file
{
"configurations": [
{
"name": " Make MPM",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/../bin/mpm",
"args": ["data/graph2.dta"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Définir la version désassemblage sur Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "make: all",
"miDebuggerPath": "/usr/bin/gdb"
},
],
"version": "2.0.0"
}
\ No newline at end of file
<<<<<<< HEAD
{
"configurations": [
{
"name": " Make MPM",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/../bin/mpm",
"args": ["data/graph2.dta"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Définir la version désassemblage sur Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "make: all",
"miDebuggerPath": "/usr/bin/gdb"
},
],
"version": "2.0.0"
}
=======
{
"configurations": [
{
"name": " Make MPM",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/../bin/mpm",
"args": ["data/graph2.dta"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Définir la version désassemblage sur Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "make: all",
"miDebuggerPath": "/usr/bin/gdb"
},
],
"version": "2.0.0"
}
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
{
"C_Cpp.errorSquiggles": "disabled"
<<<<<<< HEAD
{
"C_Cpp.errorSquiggles": "disabled"
=======
{
"C_Cpp.errorSquiggles": "disabled"
>>>>>>> b22557cb9feed82fb96729193cc5b95819e8eac9
}
\ No newline at end of file
{
"version": "2.0.0",
"tasks": [
{
"label": "make: all",
"type": "shell",
"command": "make",
"args": [
"all"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
\ No newline at end of file
DS 2 NIL
DC 4 DS NIL
PC 4 DC E NIL
P 5 PC NIL
E 3 DC DS NIL
PS 3 DS PC NIL
PE 1 P NIL
PM 2 P PS NIL
\ No newline at end of file
DS 2 NIL
DC 4 DS NIL
PC 4 DC DS NIL
P 5 PC NIL
\ No newline at end of file
File added
/* graph.h
*
* Header file for graph-related functions.
*/
#ifndef GRAPH_H
#define GRAPH_H
#include "list.h" /* Ensure list_t is defined. */
/* If you plan to use this header in a C++ project, uncomment the extern "C" section below. */
/*
#ifdef __cplusplus
extern "C" {
#endif
*/
/**
* @brief Reads a graph from the file specified by filename.
*
* This function opens the file, reads job names and their relationships,
* and builds a graph represented as a list_t.
*
* @param filename The name of the file to read.
* @return Pointer to the constructed list_t (graph) or NULL on failure.
*/
list_t *read_graph(char *filename);
/*
#ifdef __cplusplus
}
#endif
*/
#endif /* GRAPH_H */
\ No newline at end of file
......@@ -45,4 +45,4 @@ int titleJobCmp(job_t * J1, job_t * J2);
int iDegreeJobCmp(job_t * J1, job_t * J2);
int oDegreeJobCmp(job_t * J1, job_t * J2);
int rangJobCmp(job_t * J1, job_t * J2);
int InverseRangJobCmp(job_t * J1, job_t * J2);
#pragma once
#include <stdbool.h>
#include "list_elm.h"
typedef struct list {
list_elm_t * head;
list_elm_t* tail;
typedef struct elmlist_t {
void * data;
struct elmlist_t * pred;
struct elmlist_t * suc;
} elmlist_t;
typedef struct list_t {
elmlist_t * head;
elmlist_t * tail;
int numelm;
} list_t;
list_t * new_list();
void del_list ( list_t * * L, void (*ptrf) () );
bool empty_list ( list_t * L );
list_elm_t * get_head ( list_t * L );
list_elm_t * get_tail ( list_t * L );
void view_list ( list_t * L, void (*ptrf)() );
list_t * new_list ();
void del_list ( list_t ** ptrL , void (* ptrf ) ());
void clean ( list_t * L);
bool is_empty ( list_t * L);
elmlist_t * get_head ( list_t * L);
elmlist_t * get_tail ( list_t * L);
int get_numelm ( list_t * L);
void take_out ( list_t * L, void * D);
void cons ( list_t * L, void * data );
void queue ( list_t * L, void * data );
void ordered_insert ( list_t * L, void * data, int (*cmpFct)() );
int get_numelm(list_t * L);
// void take_out(struct list_t * L, void * D);
void quick_sort(list_t * L, int (*cmpFct)());
void find(list_t * L, void ** ptrKey, int (*cmpFct)(), void (*delFct)());
void del_list(list_t ** ptrL, void (*ptrf) ());
void clean(list_t * L);
bool is_empty(list_t * L);
void ordered_insert ( list_t * L, void * data , int (*cmp_ptrf )());
void quick_sort ( list_t * L, int (* cmpFct )());
void view_list ( list_t * L, void (* ptrf )());
void find ( list_t * L, void ** ptrKey , int (* cmpFct )() , void (*delFct )());
//test
elmlist_t * get_suc(elmlist_t * E);
elmlist_t * get_pred(elmlist_t * E);
void * get_data(elmlist_t * E);
void set_suc(elmlist_t * E, elmlist_t * suc);
void set_pred(elmlist_t * E, elmlist_t * pred);
void set_data(elmlist_t * E, void * data);
elmlist_t * new_list_elm(void * data);
bool is_in_list(list_t *L, void *key, int (*cmpFct)(void*, void*));
#pragma once
#include "list.h"
void ranking(list_t * G);
void prune(list_t * G);
void marges(list_t * G);
......@@ -11,10 +11,10 @@ LFLAGS = -lm
PROG = $(BDIR)/mpm
_DEPS = job.h list.h list_elm.h outils.h #rank.h
_DEPS = job.h list.h outils.h rank.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJS = db.o io.o job.o list.o list_elm.o main.o outils.o #rank.o
_OBJS = io.o job.o list.o main.o outils.o rank.o
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
.PHONY : run all dirs clean delete
......
#include "list.h"
#include "list_elm.h"
#include "job.h"
#include "list.h"
#include "outils.h"
#include "rank.h"
#include "io.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
list_t * read_graph ( char * filename ) {
FILE * fd = fopen ( filename, "rt" );
list_t * G = new_list ( );
assert ( fd && G );
char job_name [ BUFSIZ ];
while ( !feof ( fd ) ) {
fscanf ( fd, " %s", job_name);
if ( !strcmp (job_name, "NIL" ) ) continue;
job_t * J = new_job ( job_name );
list_t * read_graph( char * filename ) {
FILE * fd = fopen( filename, "rt" );
list_t * G = new_list( );
assert( fd && G );
char job_name[BUFSIZ];
/** @note
À l'appel J pointe sur le job que l'on vient de créer.
FIND retrouve le job J dans la liste G des jobs grâce à la fonction titleJobCmp.
Si ce job n'est pas dans la liste G alors
le job pointé par J est enregistré dans G
Si ce job est déjà dans G alors
le job pointé par J est supprimé grâce à free_job
puis le pointeur de J est réassigné sur le job trouvé dans G
*/
find ( G, ( void ** ) &J, &titleJobCmp, &free_job );
while ( !feof( fd ) ) {
fscanf ( fd, "%lf", &(J->life) );
fscanf( fd, " %s", job_name );
if ( !strcmp( job_name, "NIL" ) )
continue;
printf("DEBUG: job_name lire = %s\n", job_name);
/** @note
Enregistrement des préséances
*/
job_t * predJ;
fscanf( fd, " %s", job_name );
while ( strcmp ( job_name, "NIL" ) ) {
predJ = new_job ( job_name );
//SOUVIENS SI &TITTLEJOBCMP = &SETJOBTITLE
find ( G, (void **) &predJ, &titleJobCmp, &free_job );
job_t * J = new_job( job_name );
ordered_insert ( predJ->posteriority, J, &titleJobCmp );
incr_job_oDegree ( predJ );
ordered_insert ( J->precedence, predJ, &titleJobCmp );
incr_job_iDegree ( J );
/** @note
À l'appel J pointe sur le job que l'on vient de créer.
FIND retrouve le job J dans la liste G des jobs grâce à la fonction titleJobCmp.
Si ce job n'est pas dans la liste G alors
le job pointé par J est enregistré dans G
Si ce job est déjà dans G alors
le job pointé par J est supprimé grâce à free_job
puis le pointeur de J est réassigné sur le job trouvé dans G
*/
find( G, ( void ** ) &J, &titleJobCmp, &free_job );
//NOUVEAU
if( !is_in_list( G, J, (int (*)(void*, void*)) titleJobCmp ) ) {
queue( G, J );
printf("DEBUG: Inserer %s vers G\n", job_name);
} else {
printf("DEBUG: Job %s déja existé dans G\n", job_name);
}
//NOUVEAU
fscanf( fd, " %lf", &(J->life) );
fscanf ( fd, " %s", job_name );
}
/** @note valeurs par défaut des autres champs */
/** @note
Enregistrement des préséances
*/
job_t * predJ;
fscanf( fd, " %s", job_name );
printf("DEBUG: job_name lire = %s\n", job_name);
while ( strcmp( job_name, "NIL" ) ) {
predJ = new_job( job_name );
//SOUVIENS SI &TITTLEJOBCMP = &SETJOBTITLE
find( G, (void **) &predJ, &titleJobCmp, &free_job );
// NOUVEAU
if( !is_in_list( G, predJ, (int (*)(void*, void*)) titleJobCmp ) ) {
queue( G, predJ );
printf("DEBUG: Inserer pred %s vers G\n", job_name);
} else {
printf("DEBUG: Pred %s déja existé dans G\n", job_name);
}
//NOUVEAU
ordered_insert( predJ->posteriority, J, &titleJobCmp );
incr_job_oDegree( predJ );
ordered_insert( J->precedence, predJ, &titleJobCmp );
incr_job_iDegree( J );
fscanf( fd, " %s", job_name );
printf("DEBUG: job_name lire = %s\n", job_name);
}
/** @note valeurs par défaut des autres champs */
J->dyn_input_degree = J->input_degree;
J->rank = UNDEF;
J->au_plus_tard = UNDEF;
......@@ -63,79 +82,6 @@ list_t * read_graph ( char * filename ) {
J->critique = false;
}
view_list(G,&view_job);
view_list( G, &view_job );
return G;
}
static void partition(list_t * L, elmlist_t * pivot, list_t * val_inf, list_t * val_sup, int (*cmpFct)(void*, void*)) {
for (elmlist_t * cur = L->head; cur != NULL; cur = cur->suc) {
if (cmpFct(get_data(cur), get_data(pivot)) < 0)
queue(val_inf, get_data(cur));
else
queue(val_sup, get_data(cur));
}
}
void quick_sort(list_t * L, int (*cmpFct)(void*, void*)) {
assert(L && cmpFct);
if (L->numelm > 1) {
//CONFIRMER LE STRUCT
struct list_elm_t * pivot = get_head(L);
L->head = get_suc(pivot);
pivot->pred = NULL;
pivot->suc = NULL;
/** @note
* La listes des données inférieures à pivot
* La listes des données supérieures à pivot
*/
list_t * val_inf_pivot = new_list();
list_t * val_sup_pivot = new_list();
/** @note Déplacement des données de L dans val_inf_pivot et val_sup_pivot */
partition(L,pivot,val_inf_pivot,val_sup_pivot,cmpFct);
/** @note On supprimer les éléments de L sans supprimer ni L ni les jobs */
// elmlist_t * S;
// for(elmlist_t * E = L->head; E; E = S){
// S = E->suc;
// free(E);
// }
/** @note
* Si la partie inf est vide alors L commence par le pivot
* Sinon on tri grâce à cmpFct la partie inf puis on ajoute en queue le pivot
*/
if (is_empty(val_inf_pivot)) {
L->head = pivot;
L->tail = pivot;
L->numelm = 1;
} else {
quick_sort(val_inf_pivot, cmpFct);
L->head = val_inf_pivot->head;
L->tail = val_inf_pivot->tail;
L->numelm = val_inf_pivot->numelm;
pivot->pred = L->tail;
L->tail->suc = pivot;
L->tail = pivot;
L->numelm += 1;
}
/** @note
* Si la partie sup n'est pas vide alors
* On la trie puis on la concatène à la partie inf
*/
if (!is_empty(val_sup_pivot)) {
quick_sort(val_sup_pivot, cmpFct);
val_sup_pivot->head->pred = pivot;
set_suc(pivot, val_sup_pivot->head);
L->tail = val_sup_pivot->tail;
L->numelm += val_sup_pivot->numelm;
}
free(val_inf_pivot);
free(val_sup_pivot);
}
}
\ No newline at end of file
......@@ -2,8 +2,11 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "job.h"
#include "rank.h"
#include "list.h"
#include "job.h"
#include "outils.h"
#include "io.h"
job_t * new_empty_job ( ) {
job_t * J = calloc ( 1, sizeof (job_t ) );
......@@ -29,16 +32,17 @@ void free_job(job_t ** ptrJ ) {
*ptrJ = NULL;
}
void view_job ( job_t * J ) {
printf ( "JOB %s\n\tpreceeded by [", get_job_tilte ( J ) );
printf ( "JOB %s\n\tpreceeded by [", get_job_title ( J ) );
for(elmlist_t * E = get_head ( J->precedence ); E; E = get_suc ( E ) ) {
printf ( " %s", get_job_tilte ( get_data ( E ) ) );
printf ( " %s", get_job_title ( get_data ( E ) ) );
}
printf ( " ]\n" );
// if ( !get_numelm ( J->posteriority ) ) printf ( "\t" );
printf ( "\tfollowed by [" );
for(elmlist_t * E = get_head(J->posteriority); E; E = get_suc(E)){
printf(" %s", get_job_tilte(get_data(E)));
printf(" %s", get_job_title(get_data(E)));
}
printf ( " ]\n" );
printf ( "\tiDeg=%d\toDeg=%d\tlife=%2.2lf", J->input_degree, J->output_degree, J->life );
......@@ -53,3 +57,106 @@ void view_job ( job_t * J ) {
printf ( "\tcritical= " );
if ( J->critique ) printf("Y\n"); else printf ( "N\n" );
}
char * get_job_title(job_t * J) {
assert(J);
return J->title;
}
int titleJobCmp(job_t * J1, job_t * J2){
assert(J1 && J2);
return strcmp(J1->title, J2->title);
}
void set_job_title(job_t * J, char * title) {
assert(J && title);
if(J->title)
free(J->title);
J->title = strdup(title);
}
double get_job_life(job_t * J) {
assert(J);
return J->life;
}
void set_job_life(job_t * J, double life) {
assert(J);
J->life = life;
}
int get_job_iDegree(job_t * J) {
assert(J);
return J->input_degree;
}
void set_job_iDegree(job_t * J, int iDegree) {
assert(J);
J->input_degree = iDegree;
}
void incr_job_iDegree(job_t * J) {
assert(J);
J->input_degree++;
}
void decr_job_iDegree(job_t * J) {
assert(J);
J->input_degree--;
}
int InverseRangJobCmp(job_t * J1, job_t * J2) {
assert(J1 && J2);
return J2->rank - J1->rank;
}
int get_job_oDegree(job_t * J) {
assert(J);
return J->output_degree;
}
void set_job_oDegree(job_t * J, int oDegree) {
assert(J);
J->output_degree = oDegree;
}
void incr_job_oDegree(job_t * J) {
assert(J);
J->output_degree++;
}
void decr_job_oDegree(job_t * J) {
assert(J);
J->output_degree--;
}
int get_job_rank(job_t * J) {
assert(J);
return J->rank;
}
void set_rank(job_t * J, int rank) {
assert(J);
J->rank = rank;
}
int iDegreeJobCmp(job_t * J1, job_t * J2) {
assert(J1 && J2);
return J1->input_degree - J2->input_degree;
}
int oDegreeJobCmp(job_t * J1, job_t * J2) {
assert(J1 && J2);
return J1->output_degree - J2->output_degree;
}
int rangJobCmp(job_t * J1, job_t * J2) {
assert(J1 && J2);
return J1->rank - J2->rank;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "rank.h"
#include "list.h"
#include "list_elm.h"
#include "job.h"
#include "outils.h"
#include "io.h"
list_t * new_list() {
list_t * new_list(void) {
list_t * L = calloc(1, sizeof(list_t));
assert(L);
L->head = NULL;
......@@ -12,49 +17,78 @@ list_t * new_list() {
return L;
}
void del_list(list_t ** L, void (*ptr_del)(void *)) {
assert(L && *L);
list_t * list = *L;
list_elm_t * E = list->head;
elmlist_t * new_list_elm(void * data) {
elmlist_t * E = calloc(1, sizeof(elmlist_t));
assert(E);
E->data = data;
E->pred = NULL;
E->suc = NULL;
return E;
}
void del_list(list_t ** ptrL, void (*ptrf)(void *)) {
assert(ptrL && *ptrL);
list_t * list = *ptrL;
elmlist_t * E = list->head;
while (E) {
list_elm_t * temp = E;
E = E->suc;
if(ptr_del) {
ptr_del(temp->data);
elmlist_t * temp = E;
E = get_suc(temp);
if (ptrf) {
ptrf(get_data(temp));
}
free(temp);
}
free(*L);
*L = NULL;
free(*ptrL);
*ptrL = NULL;
}
bool empty_list(list_t * L) {
bool is_empty(list_t * L) {
assert(L);
return L->numelm == 0;
}
list_elm_t * get_head(list_t * L) {
elmlist_t * get_head(list_t * L) {
assert(L);
return L->head;
}
list_elm_t * get_tail(list_t * L) {
elmlist_t * get_tail(list_t * L) {
assert(L);
return L->tail;
}
int get_numelm(list_t * L) {
assert(L);
return L->numelm;
}
void view_list(list_t * L, void (*ptr_view)(void *)) {
assert(L && ptr_view);
for (list_elm_t * E = L->head; E != NULL; E = get_suc(E)) {
ptr_view(E->data);
for (elmlist_t * E = L->head; E != NULL; E = get_suc(E)) {
ptr_view(get_data(E));
}
}
void clean(list_t * L) {
assert(L);
elmlist_t * curr = L->head;
while (curr != NULL) {
elmlist_t * temp = curr;
curr = get_suc(temp);
free(temp);
}
L->head = NULL;
L->tail = NULL;
L->numelm = 0;
}
void cons(list_t * L, void * data) {
list_elm_t * E = new_list_elm(data);
E->suc = L->head;
assert(L);
elmlist_t * E = new_list_elm(data);
set_suc(E, L->head);
if (L->head != NULL) {
L->head->pred = E;
set_pred(L->head, E);
}
L->head = E;
if (L->tail == NULL) {
......@@ -64,40 +98,172 @@ void cons(list_t * L, void * data) {
}
void queue(list_t * L, void * data) {
list_elm_t * E = new_list_elm(data);
if(empty_list(L)) {
assert(L);
elmlist_t * E = new_list_elm(data);
if (is_empty(L)) {
L->head = E;
L->tail = E;
} else {
L->tail->suc = E;
E->pred = L->tail;
set_suc(L->tail, E);
set_pred(E, L->tail);
L->tail = E;
}
L->numelm++;
}
void insert_after(list_t * L, void * data, list_elm_t * elm) {
if(elm == NULL) return;
list_elm_t * E = new_list_elm(data);
E->suc = elm->suc;
E->pred = elm;
if(elm->suc != NULL) {
elm->suc->pred = E;
void insert_after(list_t * L, void * data, elmlist_t * elm) {
if (elm == NULL) return;
elmlist_t * E = new_list_elm(data);
set_suc(E, get_suc(elm));
set_pred(E, elm);
if (get_suc(elm) != NULL) {
set_pred(get_suc(elm), E);
} else {
L->tail = E;
}
elm->suc = E;
set_suc(elm, E);
L->numelm++;
}
void ordered_insert(list_t * L, void * data, int (*cmpFct)(void*, void*)) {
if(empty_list(L) || cmpFct(L->head->data, data) > 0) {
assert(L && cmpFct);
if (is_empty(L) || cmpFct(get_data(L->head), data) > 0) {
cons(L, data);
} else {
list_elm_t * current = L->head;
while(get_suc(current) != NULL && cmpFct(get_suc(current)->data, data) <= 0) {
elmlist_t * current = L->head;
while (get_suc(current) != NULL && cmpFct(get_data(get_suc(current)), data) <= 0) {
current = get_suc(current);
}
insert_after(L, data, current);
}
}
void take_out(list_t * L, void * D) {
assert(L);
elmlist_t * current = L->head;
while (current != NULL) {
if (get_data(current) == D) {
elmlist_t * p = get_pred(current);
elmlist_t * s = get_suc(current);
if (p) set_suc(p, s);
else L->head = s;
if (s) set_pred(s, p);
else L->tail = p;
free(current);
L->numelm--;
return;
}
current = get_suc(current);
}
}
static void partition(list_t * L, elmlist_t * pivot, list_t * val_inf, list_t * val_sup, int (*cmpFct)(void*, void*)) {
elmlist_t * cur = L->head;
while (cur != NULL) {
if (cmpFct(get_data(cur), get_data(pivot)) < 0) {
queue(val_inf, get_data(cur));
} else {
queue(val_sup, get_data(cur));
}
cur = get_suc(cur);
}
}
void quick_sort(list_t * L, int (*cmpFct)(void*, void*)) {
assert(L && cmpFct);
if (L->numelm <= 1) return;
elmlist_t * pivot = get_head(L);
L->head = get_suc(pivot);
set_pred(pivot, NULL);
set_suc(pivot, NULL);
list_t * val_inf_pivot = new_list();
list_t * val_sup_pivot = new_list();
partition(L, pivot, val_inf_pivot, val_sup_pivot, cmpFct);
clean(L);
if (is_empty(val_inf_pivot)) {
L->head = pivot;
L->tail = pivot;
L->numelm = 1;
} else {
quick_sort(val_inf_pivot, cmpFct);
L->head = val_inf_pivot->head;
L->tail = val_inf_pivot->tail;
L->numelm = val_inf_pivot->numelm;
set_pred(pivot, L->tail);
set_suc(L->tail, pivot);
L->tail = pivot;
L->numelm++;
}
if (!is_empty(val_sup_pivot)) {
quick_sort(val_sup_pivot, cmpFct);
set_pred(val_sup_pivot->head, pivot);
set_suc(pivot, val_sup_pivot->head);
L->tail = val_sup_pivot->tail;
L->numelm += val_sup_pivot->numelm;
}
free(val_inf_pivot);
free(val_sup_pivot);
}
void find(list_t * L, void ** ptrKey, int (*cmpFct)(void*, void*), void (*delFct)(void*)) {
assert(L && ptrKey && cmpFct);
printf("DEBUG (find): trouvant pointer %p\n", *ptrKey);
elmlist_t * curr = L->head;
while (curr) {
if (cmpFct(get_data(curr), *ptrKey) == 0) {
printf("DEBUG (find): double trouvée. Element data vers %p\n", get_data(curr));
if (delFct) {
printf("DEBUG (find): Freeing pointer double %p\n", *ptrKey);
delFct(ptrKey);
}
*ptrKey = get_data(curr);
return;
}
curr = get_suc(curr);
}
printf("DEBUG (find): pas de double pour le pointer %p\n", *ptrKey);
}
//PENSER A CHANGER VERS ASSERT
elmlist_t * get_suc(elmlist_t * E) {
if (E == NULL) return NULL;
return E->suc;
}
elmlist_t * get_pred(elmlist_t * E) {
if (E == NULL) return NULL;
return E->pred;
}
void * get_data(elmlist_t * E) {
if (E == NULL) return NULL;
return E->data;
}
void set_suc(elmlist_t * E, elmlist_t * suc) {
if (E != NULL) E->suc = suc;
}
void set_pred(elmlist_t * E, elmlist_t * pred) {
if (E != NULL) E->pred = pred;
}
void set_data(elmlist_t * E, void * data) {
if (E != NULL) E->data = data;
}
bool is_in_list(list_t *L, void *key, int (*cmpFct)(void*, void*)) {
assert(L && cmpFct);
for (elmlist_t *E = L->head; E != NULL; E = E->suc) {
if (cmpFct(get_data(E), key) == 0) {
return true;
}
}
return false;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "job.h"
#include "list.h"
#include "outils.h"
#include "rank.h"
#include "io.h"
int main(int argc, char ** argv){
if(argc < 2) exit(-1);
list_t * G = read_graph(argv[1]);
printf("Liste des tâches lue\n");
view_list(G, &view_job);
printf("Liste des tâches triée par degré d'entrée croissant\n");
quick_sort(G, &iDegreeJobCmp);
view_list(G,&view_job);
printf("Liste des tâches triée par rang croissant\n");
ranking(G);
view_list(G,&view_job);
printf("Prune edges\n");
prune(G);
view_list(G,&view_job);
printf("\nMarges totales des tâches\n");
marges(G);
view_list(G,&view_job);
return 0;
}