Skip to content

Commit

Permalink
one big commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGresset committed Jun 28, 2024
1 parent 7673fa0 commit 0ea0bfb
Show file tree
Hide file tree
Showing 29 changed files with 1,543 additions and 1,499 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/bin/
/.vscode/
docs/
latex/
latex/
out/
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CC ?= gcc
CFLAGS ?= -Wall -g -Wextra -O1
LDLIBS ?= -lm -ltps -lSDL2 -lSDL2_ttf
CFLAGS ?= -Wall -g -Wextra -O3
LDLIBS ?= -lm
INCLUDE_PATH = ./include

TARGET =arbres
TARGET =main

SRCDIR = src
OBJDIR = obj
Expand All @@ -14,6 +14,10 @@ SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(INCLUDE_PATH)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)

TEST_DIR = test
TEST_SRC = $(TEST_DIR)/test.c
TEST_BIN = $(TEST_DIR)/test


$(BINDIR)/$(TARGET): $(OBJECTS)
mkdir -p $(BINDIR)
Expand All @@ -27,6 +31,11 @@ $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
doc:
doxygen Doxyfile

test: $(TEST_BIN)

$(TEST_BIN): $(TEST_SRC)
$(CC) $(CFLAGS) -o $(TEST_BIN) $(TEST_SRC)

.PHONY: clean
clean:
rm -rf obj/*.o
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# paris-trees-mst

we'll take a dive into the utilization of this program
This project is an academical project which aims to compute minimum spanning tree algorithm on Paris trees from a csv database.

One year after, I come back on the database to try to enhance coding quality and review my past mistakes.

## to be modified

- CLI parsing, use [vrgcli](https://dev.to/rdentato/vrg-for-comand-lines-5hmm), it seems easier
- gui library : use sdl2 instead, more universal and portable

taking a first look at the basecode shows there are plenty of modifications to be done !

A test framework needs to be used, why not [this one](https://github.com/rdentato/tst/blob/main/src/tst.h)
let's write some unit tests
32 changes: 15 additions & 17 deletions include/algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
#include <stdio.h>



/**
* @brief Une fonction qui calcule l'arbre recouvrant minimal du graphe
* structure passé en paramètre
*
* @param forest le graphe dont on calcule l'arbre
* @param size la taille du graphe
* @return arete* : la liste des arètes constituant l'arbre recouvrant
* minimal
* @brief Compute the minimum spanning tree (MST) for the given forest
* considered as a complete graph using Prim's algorithm
*
* @param forest
* @param MST
*/
edge* minimumSpanningTree(tree* forest, size_t size);

void computeMST(forest *forest, MST *MST);

/**
* @brief Get the Forest Max Composante object Renvoie la liste d'arbres "forêt" composée de la plus grande composante connexe,
* paramétrée par la distance distmax
*
* @param forest
* @brief Get the Forest Max Composante object Renvoie la liste d'arbres
* "forêt" composée de la plus grande composante connexe, paramétrée par la
* distance distmax
*
* @param forest
* @param size la taille de forest
* @param distmax
* @param distmax
* @param newsize pointeur vers la nouvelle taille de la forêt
* @return tree*
* @return tree*
*/
tree* getForestMaxComposante(tree* forest, size_t size, double distmax, size_t* newsize);
tree *getForestMaxComposante(tree *forest, size_t size, double distmax,
size_t *newsize);
70 changes: 13 additions & 57 deletions include/array-list.h
Original file line number Diff line number Diff line change
@@ -1,81 +1,37 @@
#include <stdio.h>

typedef struct list_t list_t ;


typedef struct list dynamic_list;

/**
* @brief Crée une liste vide
*
*
* @return list_t* ou NULL en cas de problème
*/
list_t* list_create(void);

dynamic_list *list_create(void);

/**
* @brief Ajoute un élément à la fin de la liste
*
* @return 0 en cas de problème, 1 sinon
*/
int list_append(list_t*, void*);

/**
* @brief Ajoute un élément en début de liste
*
*
* @return 0 en cas de problème, 1 sinon
*/
int list_prepend(list_t*, void*);

int list_append(dynamic_list *list, size_t elem);

/**
* @brief retourne le (idx+1)ème élément
* comportement indéfini en cas de dépassemnt
*
* @return void*
*
* @return void*
*/
void* list_get(list_t*, int);
size_t list_get(dynamic_list *list, int index);

size_t list_pop(dynamic_list *list);

/**
* @brief remplace l'élément à la position donnée par l'élément donné
*
*/
void list_set(list_t*, int, void*);

/**
* @brief remplace l'élément à la position donnée par l'élément donné et free l'élément remplacé
*
*/
void list_set2(list_t* it, int pos, void* element);

/**
* @brief revoie la taille de la liste
*
* @return size_t
*/
size_t list_size(list_t*);

/**
* @brief insère un élément à la position idx
*
* @return 0 en cas de problème, 1 sinon
*/
int list_insert(list_t*, size_t, void*);

/**
* @brief retourne l'élément à la position idc, puis enlève cet élément de la liste
*
* @return void*
*/
void* list_take(list_t*, int);

/**
* @brief libère la liste et tous ses éléments
*
*
*/
void list_free(list_t*);

void list_set(dynamic_list *, int index, size_t new_value);

size_t* create_size_t(size_t i);
size_t list_size(dynamic_list *list);

void list_free2(list_t* it);
void list_free(dynamic_list *list);
16 changes: 8 additions & 8 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include <time.h>


/**
* @brief Une fonction qui permet d'afficher l'arbre recouvrant minimal
*
* @param listeAretes la liste des aretes de l'arbre
* @param size la taille du graphe (la structure)
* @param structure la structure de l'arbre de taille size + 1
*/
void displayTrees(edge* listeAretes, size_t size, tree* structure);
// /**
// * @brief Une fonction qui permet d'afficher l'arbre recouvrant minimal
// *
// * @param listeAretes la liste des aretes de l'arbre
// * @param size la taille du graphe (la structure)
// * @param structure la structure de l'arbre de taille size + 1
// */
// void displayTrees(edge* listeAretes, size_t size, tree* structure);



Expand Down
14 changes: 14 additions & 0 deletions include/erreur.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>

/**
A convenient way to handle errors : will call raler if condition is true
--> means bad return code
*/
#define CHK(condition) \
do { \
if (condition) \
raler(#condition, __FILE__, __LINE__); \
} while (0);

void raler(const char *msg, const char *file, int line);
18 changes: 6 additions & 12 deletions include/fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
#include "struct.h"
#include <stdio.h>
#include <stdlib.h>
#include <tps.h>

#define RAYON 6378137.0
#define RAYON_TERRE 6378137.0 // exprimé en mètres

/**
* @brief Cette fonction renvoie la distance en mètres entre deux arbres repérés par leurs coordonnées latitude et longitude
*
* @param tree1 premier arbre à comparer
* @param tree2 second arbre à comparer
* @return double
*
*/
double distanceTrees(tree * tree1, tree * tree2);
// renvoie le carré de la distance entre deux arbres (en mètres), sans compter le rayon de la terre
double squaredDistanceTrees(tree * tree1, tree * tree2);

double distanceTrees(tree *tree1, tree *tree2);


/**
Expand All @@ -31,6 +25,6 @@ double radians(double);
* @param forest
* @param size
*/
void projectionTrees(tree* forest, size_t size);
void equirectangularProjection(forest *forest);

void manageActions(tree* forest, size_t size, edge** MST, opt handlingOptions);
2 changes: 1 addition & 1 deletion include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* @param options pointeur vers une structure stockant chaque option mise en argument
*
*/
void options(int argc, char ** argv, opt * options);
void handleCLI(int argc, char ** argv, opt * options);
Loading

0 comments on commit 0ea0bfb

Please sign in to comment.