a bit more of normalising

normalising lem_in WIP
This commit is contained in:
Tanguy MAZE 2019-04-10 15:35:23 +02:00
parent 5d094ebcaf
commit 8c4a6aac25
4 changed files with 35 additions and 32 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ # # By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# # # Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
# Updated: 2019/04/10 14:24:30 by tmaze ### ########.fr # # Updated: 2019/04/10 14:47:07 by tmaze ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#
@ -27,7 +27,7 @@ endif
# Compilator # Compilator
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror FLAGS = -Wall -Wextra -Werror -g
# Folders # Folders
LIBDIR = libft LIBDIR = libft

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/28 16:21:19 by tmaze #+# #+# */ /* Created: 2019/03/28 16:21:19 by tmaze #+# #+# */
/* Updated: 2019/04/08 18:49:53 by tmaze ### ########.fr */ /* Updated: 2019/04/10 15:00:16 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -93,7 +93,6 @@ t_ind **edmunds_karp(t_lmdata *data, int start_ind, int end_ind)
int nb_path; int nb_path;
nb_path = 0; nb_path = 0;
ft_printf("data: %p\ndata->adj: %p\n\n", data, data->adj);
if (data && data->adj) if (data && data->adj)
{ {
bfs(data, tab, start_ind, end_ind); bfs(data, tab, start_ind, end_ind);

View File

@ -6,16 +6,24 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */ /* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */ /* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
/* Updated: 2019/04/10 14:26:07 by tmaze ### ########.fr */ /* Updated: 2019/04/10 15:35:18 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "lem_in.h" #include "lem_in.h"
int lm_error_exit(void) static t_node *get_node_role(t_lmdata *data, char role)
{ {
ft_putendl_fd("ERROR", 2); t_node *it;
return (1);
it = data->nodes_data;
while (it)
{
if (it->role == role)
return (it);
it = it->next;
}
return (NULL);
} }
static int lem_in(t_syntax *synt, t_holder *holder, static int lem_in(t_syntax *synt, t_holder *holder,
@ -30,15 +38,18 @@ static int lem_in(t_syntax *synt, t_holder *holder,
return (1); return (1);
} }
int lm_error_exit(void)
{
ft_putendl_fd("ERROR", 2);
return (1);
}
int main(int ac, char **av) int main(int ac, char **av)
{ {
t_syntax synt; t_syntax synt;
t_lmdata ldata; t_lmdata ldata;
t_holder holder; t_holder holder;
t_ind **ret; t_ind **ret;
t_node *it;
t_node *start;
t_node *end;
int i; int i;
(void)av; (void)av;
@ -48,19 +59,12 @@ int main(int ac, char **av)
lm_init_data(&synt, &holder, &ldata); lm_init_data(&synt, &holder, &ldata);
if (!(lem_in(&synt, &holder, &ldata))) if (!(lem_in(&synt, &holder, &ldata)))
return (lm_error_exit()); return (lm_error_exit());
it = ldata.nodes_data; if ((ret = edmunds_karp(&ldata, get_node_role(&ldata, 's')->ind
start = NULL; , get_node_role(&ldata, 'e')->ind)) == NULL)
end = NULL;
while (it && (!start || !end))
{
if (it->role == 's')
start = it;
else if (it->role == 'e')
end = it;
it = it->next;
}
if ((!start) || (ret = edmunds_karp(&ldata, start->ind, end->ind)) == NULL)
return (lm_error_exit()); return (lm_error_exit());
i = 0;
while (ret[i])
i++;
push_ants(&ldata, ret, i); push_ants(&ldata, ret, i);
tablst_inddel(ret); tablst_inddel(ret);
i = 0; i = 0;

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/06 11:37:56 by tmaze #+# #+# */ /* Created: 2019/04/06 11:37:56 by tmaze #+# #+# */
/* Updated: 2019/04/10 14:15:59 by tmaze ### ########.fr */ /* Updated: 2019/04/10 14:53:01 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,8 +58,8 @@ static void print_ants(t_lmdata *data, t_ants **ants, char *has_start
ft_putchar('\n'); ft_putchar('\n');
has_start[it->nb_path] = 0; has_start[it->nb_path] = 0;
it = it->next; it = it->next;
clean_ants(ants);
} }
clean_ants(ants);
} }
void push_ants(t_lmdata *data, t_ind **paths, int nb_paths) void push_ants(t_lmdata *data, t_ind **paths, int nb_paths)