From 5dd290bcf740439346d47267729dfaea18dc3cdf Mon Sep 17 00:00:00 2001 From: Tanguy MAZE Date: Sat, 20 Apr 2019 19:06:39 +0200 Subject: [PATCH] DONE !!!!!! fully functionning algorithm with good performance still need to normalize and integrate --- srcs/bfs.c | 4 ++-- srcs/edmonds_karp.c | 20 ++++++++++++++++---- srcs/lem_in.c | 4 ++-- srcs/push_ants.c | 6 +----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/srcs/bfs.c b/srcs/bfs.c index 2e1c6d1..cd6eea0 100644 --- a/srcs/bfs.c +++ b/srcs/bfs.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/18 09:25:05 by tmaze #+# #+# */ -/* Updated: 2019/04/19 12:51:55 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 18:04:48 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,7 +49,7 @@ void bfs(t_lmdata *data, t_bfs *tab, int s_ind, int e_ind) while (i < data->nb_nodes && tab[i].queue != -1 && tab[e_ind].parent == -1) { tab[tab[i].queue].visited = 1; - used = (tab[tab[i].queue].old_visited && !tab[tab[tab[i].queue].parent].old_visited); + used = (tab[tab[i].queue].old_visited && get_node_path(data->adj[tab[tab[i].queue].parent], tab[i].queue)->weight == 1); it = data->adj[tab[i].queue]; while (it) { diff --git a/srcs/edmonds_karp.c b/srcs/edmonds_karp.c index c9bc040..e93cce4 100644 --- a/srcs/edmonds_karp.c +++ b/srcs/edmonds_karp.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/18 09:59:11 by tmaze #+# #+# */ -/* Updated: 2019/04/19 12:53:52 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 18:58:38 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,20 @@ void print_paths(t_lmdata *data, t_ind **ret) } } +int check_if_visited(t_lmdata *data, int node) +{ + t_ind *it; + + it = data->adj[node]; + while (it) + { + if (it->weight != 1) + return (1); + it = it->next; + } + return (0); +} + t_ind **edmonds_karp(t_lmdata *data, int s_ind, int e_ind) { t_bfs tab[data->nb_nodes]; @@ -93,19 +107,17 @@ t_ind **edmonds_karp(t_lmdata *data, int s_ind, int e_ind) i = e_ind; while (i != s_ind) { - tab[i].old_visited = 0; it = data->adj[i]; while (it && it->index != tab[i].parent) it = it->next; if (it->index == tab[i].parent) it->weight++; - if (i != e_ind && it->weight == 2) - tab[i].old_visited = 1; it = data->adj[tab[i].parent]; while (it && it->index != i) it = it->next; if (it) it->weight--; + tab[i].old_visited = check_if_visited(data, i); i = tab[i].parent; } ret[1] = resolve_paths(data, nb_paths, s_ind, e_ind); diff --git a/srcs/lem_in.c b/srcs/lem_in.c index 11e073d..385bb1c 100644 --- a/srcs/lem_in.c +++ b/srcs/lem_in.c @@ -6,7 +6,7 @@ /* By: mndhlovu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */ -/* Updated: 2019/04/19 12:56:45 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 18:58:20 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ static int lem_in(t_syntax *synt, t_holder *holder, if ((*ret = edmonds_karp(lmdata, get_node_role(lmdata, 's')->ind , get_node_role(lmdata, 'e')->ind)) == NULL) return (0); - print_paths(lmdata, *ret); +// print_paths(lmdata, *ret); if (!push_ants(lmdata, *ret, get_nb_paths(*ret))) return (0); tablst_inddel(*ret); diff --git a/srcs/push_ants.c b/srcs/push_ants.c index 310dfa9..37c5b52 100644 --- a/srcs/push_ants.c +++ b/srcs/push_ants.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/06 11:37:56 by tmaze #+# #+# */ -/* Updated: 2019/04/18 19:38:55 by tmaze ### ########.fr */ +/* Updated: 2019/04/20 19:05:32 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,11 +70,7 @@ int push_ants(t_lmdata *data, t_ind **paths, int nb_paths) i = 0; ant_c = 2; while (paths[i] && paths[i]->weight == 0) - { - ft_printf("path: %d\n", i); i++; - } - ft_printf("ant path: %d\n", i); if (add_ant(&ants, 1, i, paths) == NULL) return (0); while (ants || ant_c <= data->nbants)