Compare commits

..

43 Commits

Author SHA1 Message Date
Tanguy MAZE
94a1cdaffc more cleanup 2019-05-10 13:19:24 +02:00
Tanguy MAZE
c672ca1205 Merge branch 'master' of https://github.com/tvdu29/lem_in 2019-05-09 18:46:01 +02:00
Tanguy MAZE
ca1abc4990 repo cleanup
removing test maps & test files
2019-05-09 18:40:19 +02:00
Mthandazo Ndhlovu
ea99e7b1fc norm errors eliminated and parser modified 2019-05-09 17:41:07 +02:00
Tanguy MAZE
94145d3d17 minor modifications to map printing and ant paths
print map if look ok and has path
if start & end linked, only 1 operation
2019-05-09 16:26:35 +02:00
Mthandazo Ndhlovu
f44cda2833 another commit 2019-05-09 13:09:22 +02:00
Mthandazo Ndhlovu
a21860983e Cleaned the seg faults and normed the code, only
lm_mem_utils has a norm error.
2019-05-06 08:05:37 +02:00
Tanguy MAZE
5894c0cdd0 correted invalid free
invalid free occuring with invalid chars in ant number
2019-05-02 14:55:46 +02:00
Tanguy MAZE
3156bddf27 added start-end check
if start and end are linked, push all the ants through
2019-05-02 14:35:37 +02:00
Mthandazo Ndhlovu
a40b6b00e7 no more leaks on all maps 2019-05-02 13:25:41 +02:00
Mthandazo Ndhlovu
8552cf8a32 semi-final parser 2019-05-02 12:58:28 +02:00
Mthandazo Ndhlovu
4bb3b45781 a bit of code cleaning on the parser 2019-04-30 12:07:28 +02:00
Mthandazo Ndhlovu
ee59b79e75 a bit of code cleaning on the parser 2019-04-30 12:06:58 +02:00
Tanguy MAZE
b22a1a5af7 corrected invalid read on print_map
caused by exessive ft_strdel instruction in lm_parser
2019-04-29 13:08:08 +02:00
Mthandazo Ndhlovu
a51c8ad81d code cleaning done on 80 percent of the parser functions, whats left is to re structure the syntax struct and do furthure tests to eliminate level 0 errors 2019-04-29 12:47:14 +02:00
Mthandazo Ndhlovu
6ad8cd2d95 current parser version ready for breaking.. 2019-04-26 13:37:32 +02:00
Mthandazo Ndhlovu
9a386b315b segfaults have been eliminated 2019-04-26 12:00:28 +02:00
Mthandazo Ndhlovu
ba1cea020d merged print_map 2019-04-26 11:46:35 +02:00
Tanguy MAZE
0b4c310374 modify map printing system
added functions to create, print and clear map when it's valid

corrected map del in print_map
2019-04-26 11:31:49 +02:00
Tanguy MAZE
5b4e0c0150 modify map printing system
added functions to create, print and clear map when it's valid
2019-04-24 18:24:34 +02:00
Tanguy MAZE
fe1c85371f bug found
found bug in parser that made link adding impossible
2019-04-24 09:54:24 +02:00
Mthandazo Ndhlovu
c35deace58 Trying to trace the source of the segfault
I will breakdown the parser for a slight moment then relink it.
2019-04-22 16:00:16 +02:00
Tanguy MAZE
a8b2e31701 added finished algorithm
merged algorithm from other personnal repo
2019-04-22 10:13:09 +02:00
Mthandazo Ndhlovu
c6339a00e9 fixed lm_check_errors 2019-04-22 09:56:09 +02:00
Mthandazo Ndhlovu
bfb125f503 Adding more protection to the parser, leaving it at this state for now whilst i branch out to work on a new parser 2019-04-20 13:38:13 +02:00
Tanguy MAZE
4a5c798b25 rework on score system
need to score with correct amount of ants on each paths
also secured ft_atois
2019-04-14 14:45:38 +02:00
Tanguy MAZE
9b75432c2e Added scoring system to algorithm
still need testing and optimisations
not norm-compliant
2019-04-13 14:56:39 +02:00
Tanguy MAZE
d85e0873cb added protection on double pipes 2019-04-11 22:34:35 +02:00
Mthandazo Ndhlovu
0495ba9e55 clean up code for when an error occurs
testing with all maps is what is left
2019-04-11 14:11:25 +02:00
Mthandazo Ndhlovu
eb85b914a4 Leaks and error checking almost done
function to clean traces of holder is done.
Error checking before adjacency list creation is done also.
Now focusing on breaking the parser with
invalid maps. It should be ready in a day.
2019-04-11 12:52:14 +02:00
Tanguy MAZE
86b0530bf7 clean up still in progress
eliminated most of the leaks of the parser
norming still need to be done
2019-04-11 11:40:26 +02:00
Tanguy MAZE
8c4a6aac25 a bit more of normalising
normalising lem_in WIP
2019-04-10 15:35:23 +02:00
Tanguy MAZE
5d094ebcaf Massive clean up
cleaned up unused code
normalised push_ants
libft is no longer a submodule
still need to normalise lem_in
2019-04-10 14:34:59 +02:00
Tanguy MAZE
fb66233265 sry =S
forgot 3 files in last commitP
2019-04-09 19:10:47 +02:00
Tanguy MAZE
3b893147e5 IT WORKS !
functionning ./lem_in that can read maps and display ants path
still need to clean leaks
still need remove debug info
2019-04-09 19:09:29 +02:00
Tanguy MAZE
434b629055 better featured API for t_lmdata adj
added function to help create and clear the adjacency list
2019-04-09 14:36:30 +02:00
Tanguy MAZE
08e622a4f0 a bit of management
added push_ants in its own file
2019-04-08 19:18:56 +02:00
Tanguy MAZE
a2fd180398 some light work today
corrected invalid read in update_weights() when tab[i].parent was
equal to -1
2019-04-07 12:51:40 +02:00
Tanguy MAZE
ae93873452 push_ants done need to test
done all mechanism to display ants moving in the graph
still need testing
still need norming
2019-04-06 14:03:22 +02:00
Tanguy MAZE
c36f501b08 testing things
thinking of how to display the ants moving and optimise by moving at
least one on each path
2019-04-05 17:43:17 +02:00
Tanguy MAZE
0a9d7b816d Merge branch 'tmaze'
merging algorithm to master of project
2019-04-05 14:06:42 +02:00
Tanguy MAZE
ea0eda89d0 aaaaaaand it's done !
algorithm finished and normed
more testing might be needed
2019-04-03 17:20:29 +02:00
Tanguy MAZE
15669b7402 not quite there yet but nearly ^^
WIP for the algorithm not to pass on previously used node
2019-04-01 19:06:19 +02:00
170 changed files with 1258 additions and 4183 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "libft"]
path = libft
url = https://github.com/tvdu29/libft

View File

@ -6,11 +6,11 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
# Updated: 2019/03/31 19:48:45 by tmaze ### ########.fr #
# Updated: 2019/05/09 18:39:33 by tmaze ### ########.fr #
# #
#******************************************************************************#
NAME = lem_in
NAME = lem-in
# Make options
MAKEFLAGS += --no-print-directory
@ -27,7 +27,7 @@ endif
# Compilator
CC = gcc
FLAGS = -Wall -Wextra -Werror -g -O0 -fsanitize=address
FLAGS = -Wall -Wextra -Werror
# Folders
LIBDIR = libft
@ -36,7 +36,25 @@ OBJDIR = objs
INCDIR = includes libft/includes
# Source files
SRC = lem_in.c lm_parser.c lm_mem_utils.c lm_graph_utils.c lm_check_errors.c \
SRC = lm_parser.c \
lm_mem_utils.c \
lm_check_errors.c \
lm_data_utils.c \
lm_initdata.c \
lm_mem_utils.c \
lm_graph_utils.c \
lm_parser_error_check.c \
lm_utils_parser.c \
lm_utils_algo.c \
bfs.c \
lst_ind.c \
edmonds_karp.c \
push_ants.c \
push_ants_utils.c \
score_utils.c \
print_map.c \
lem_in.c
OBJ = $(SRC:.c=.o)

BIN
Oglibft/.DS_Store vendored

Binary file not shown.

View File

@ -6,16 +6,14 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/23 17:31:19 by tmaze #+# #+# */
/* Updated: 2019/03/31 17:58:52 by tmaze ### ########.fr */
/* Updated: 2019/05/09 17:39:33 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LEM_IN_H
# define LEM_IN_H
# include "libft.h"
# include "limits.h"
# include <fcntl.h>
typedef struct s_node
{
@ -34,99 +32,125 @@ typedef struct s_ind
struct s_ind *next;
} t_ind;
typedef struct s_lmdata
{
int nbants;
int nb_nodes;
t_list *nodes;
t_node *nodes_data;
t_ind **adj;
} t_lmdata;
typedef struct s_bfs
{
int parent;
char visited;
char old_visited;
int queue;
} t_bfs;
//LEM_IN MT STRUCTS
typedef struct s_syntax
typedef struct s_ants
{
int nb_ant;
int nb_path;
int nb_node;
char end;
struct s_ants *next;
} t_ants;
typedef struct s_temp
{
int src_ind;
int dest_ind;
struct s_temp *next;
} t_temp;
typedef struct s_holder
{
int count;
int nb_state;
int s_cmd;
int s_pos;
int error;
int s_error;
int state;
int e_error;
int v_error;
int l_error;
int gr_status;
int s_vert;
int e_vert;
int gr_status;
int e_cmd;
int e_pos;
int v_flag;
} t_syntax;
t_temp *data;
} t_holder;
typedef struct s_AdjListNode
typedef struct s_rdata
{
int dest;
struct s_AdjListNode *next;
} t_adjlist;
char *line;
struct s_rdata *next;
} t_rdata;
typedef struct s_temp
typedef struct s_lmdata
{
int src_ind;
int dest_ind;
struct s_temp *next;
} t_temp;
typedef struct s_holder
{
int count;
t_temp *data;
} t_holder;
typedef struct s_AdjList
{
t_adjlist *head;
} t_adj;
typedef struct s_graph
{
int v;
t_adj *array;
} t_graph;
typedef struct s_neighbour
{
int vertnum;
struct s_neighbor *next;
} t_neighbor;
//MT-FUNCTIONS
int lm_error_exit(int flag);
int lm_validate(t_syntax *synt, t_lmdata *lmdata);
void lm_parser(int fd, t_syntax *synt, t_lmdata *ldata,
t_holder *holder);
int lm_check_room_before(char **tab, t_syntax *synt);
void lm_init_data(t_syntax *synt, t_lmdata *ldata, t_holder *holder);
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag, t_syntax *synt);
t_adjlist *lm_new_node(int dest);
t_graph *lm_creategraph(int v);
void lm_add_edge(t_graph *graph, int src, int dest);
int lm_ext_conn(t_holder *holder, t_lmdata *data, char *raw);
int lm_find_index(t_lmdata *data, char *str);
int nbants;
int nb_nodes;
int nb_paths_max;
t_node *nodes_data;
t_ind **adj;
t_rdata *map;
} t_lmdata;
int lm_parser(t_lmdata *ldata
, t_holder *holder);
int lm_check_room_before(char **tab, t_holder *holder
, char **name);
void lm_clear_unv(t_holder *holder);
int lm_add_vertex(t_lmdata *ldata, char *raw, char flag
, t_holder *holder);
int lm_ext_conn(t_holder *holder, t_lmdata *data
, char *raw);
void lm_ext_conn_sub(t_holder *holder, t_temp *new_data);
int lm_init_src_dest(int *src, int *dest, t_lmdata *data
, char *raw);
int lm_find_index(t_lmdata *data, char *str);
void lm_get_cmd_vertices(int count, t_holder *holder
, t_lmdata *ldata, char *line);
int lm_get_value(char *line);
void lm_check_start_vert(int count, t_holder *hol
, t_lmdata *ldata, char *line);
void lm_check_end_vert(int count, t_holder *hol
, t_lmdata *ldata, char *line);
void lm_get_vert_link(int count, t_lmdata *ldata
, t_holder *holder, char *line);
int lm_validate_rooms(char *name, char *x, char *y);
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder);
void lm_init_data(t_holder *holder, t_lmdata *ldata);
int lm_verify_cmd(t_holder *holder, t_lmdata *data);
void lm_initdata(t_lmdata *data);
int lm_error_nbr(char *raw);
int lm_getparams(t_lmdata *data);
void lm_clean_data(t_lmdata *data);
int lm_check_forbiden_chars(char *line, int flag);
t_ind **lst_indinit(t_lmdata *data);
int lst_indadd_link(t_lmdata *data, int n1, int n2);
t_ind *lst_indadd(t_ind **lst, int ind);
void lst_inddel(t_ind **lst);
void tablst_inddel(t_ind **tab);
void bfs(t_lmdata *data, t_bfs *tab, int start_ind, int end_ind);
t_ind **edmunds_karp(t_lmdata *data, int start_ind, int end_ind);
t_ants *add_ant(t_ants **ants, int nb_ant, int nb_path
, t_ind **paths);
void del_ants(t_ants **ants);
t_node *get_node(t_lmdata *data, int index);
t_ind *get_node_path(t_ind *lst, int index);
void bfs(t_lmdata *data, t_bfs *tab, int start_ind
, int end_ind);
t_ind **edmonds_karp(t_lmdata *data, int s_ind, int e_ind);
int get_score(t_lmdata *data, t_ind **ret, int nb_paths);
void print_paths(t_lmdata *data, t_ind **ret);
int push_ants(t_lmdata *data, t_ind **paths
, int nb_paths);
void push_ants_end(t_lmdata *data, char *e_name);
void del_map(t_lmdata *data);
int add_line_map(t_lmdata *data, char *line);
void print_map(t_lmdata *data);
t_node *get_node_role(t_lmdata *data, char role);
int get_nb_paths(t_ind **ret);
void get_nb_paths_max(t_lmdata *data, int start, int end);
#endif

1
libft

@ -1 +0,0 @@
Subproject commit 51295179f30451f2c2d6cbc8653c5accd9fb8a8a

View File

@ -6,12 +6,12 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/04/07 12:47:06 by tmaze #+# #+# #
# Updated: 2019/03/27 17:46:28 by tmaze ### ########.fr #
# Updated: 2019/05/09 18:39:42 by tmaze ### ########.fr #
# #
#******************************************************************************#
CC = gcc
CCFLAGS = -Wall -Werror -Wextra -g -O0 -fsanitize=address
CCFLAGS = -Wall -Werror -Wextra
CCSTD =
NAME = libft.a
@ -32,6 +32,7 @@ SRCS = ft_memalloc.c \
ft_isascii.c \
ft_isprint.c \
ft_toupper.c \
ft_isnumeric.c \
ft_tolower.c \
ft_isupper.c \
ft_islower.c \

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
/* Updated: 2019/03/20 16:46:41 by tmaze ### ########.fr */
/* Updated: 2019/04/26 10:36:51 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
@ -266,6 +266,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_atoi(const char *str);
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isnumeric(char *str);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/04 11:33:35 by tmaze #+# #+# */
/* Updated: 2018/04/04 11:34:10 by tmaze ### ########.fr */
/* Updated: 2019/04/29 11:16:40 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */

29
libft/srcs/ft_isnumeric.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnumeric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/26 10:17:04 by mndhlovu #+# #+# */
/* Updated: 2019/04/29 11:20:54 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isnumeric(char *str)
{
int index;
index = 0;
if (str[index] == '-' || str[index] == '+')
index++;
while (str[index] != '\0')
{
if (!ft_isdigit(str[index]))
return (0);
index++;
}
return (1);
}

View File

@ -3,26 +3,22 @@
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/03 15:38:27 by tmaze #+# #+# */
/* Updated: 2018/04/08 15:30:24 by tmaze ### ########.fr */
/* Created: 2018/11/07 17:33:42 by mndhlovu #+# #+# */
/* Updated: 2018/11/09 17:56:30 by mndhlovu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
int ft_strcmp(const char *s1, const char *s2)
int ft_strcmp(const char *s1, const char *s2)
{
int i;
int diff;
size_t len;
i = 1;
diff = (unsigned char)s1[0] - (unsigned char)s2[0];
while (diff == 0 && s1[i - 1] && s2[i - 1])
{
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
i++;
}
return (diff);
len = 0;
while (s1[len] && s2[len] && s1[len] == s2[len])
len++;
return ((unsigned char)s1[len] - (unsigned char)s2[len]);
}

Some files were not shown because too many files have changed in this diff Show More