DONE !!!!!!
fully functionning algorithm with good performance still need to normalize and integrate
This commit is contained in:
parent
1f24922155
commit
5dd290bcf7
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/18 09:25:05 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)
|
while (i < data->nb_nodes && tab[i].queue != -1 && tab[e_ind].parent == -1)
|
||||||
{
|
{
|
||||||
tab[tab[i].queue].visited = 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];
|
it = data->adj[tab[i].queue];
|
||||||
while (it)
|
while (it)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/18 09:59:11 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_ind **edmonds_karp(t_lmdata *data, int s_ind, int e_ind)
|
||||||
{
|
{
|
||||||
t_bfs tab[data->nb_nodes];
|
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;
|
i = e_ind;
|
||||||
while (i != s_ind)
|
while (i != s_ind)
|
||||||
{
|
{
|
||||||
tab[i].old_visited = 0;
|
|
||||||
it = data->adj[i];
|
it = data->adj[i];
|
||||||
while (it && it->index != tab[i].parent)
|
while (it && it->index != tab[i].parent)
|
||||||
it = it->next;
|
it = it->next;
|
||||||
if (it->index == tab[i].parent)
|
if (it->index == tab[i].parent)
|
||||||
it->weight++;
|
it->weight++;
|
||||||
if (i != e_ind && it->weight == 2)
|
|
||||||
tab[i].old_visited = 1;
|
|
||||||
it = data->adj[tab[i].parent];
|
it = data->adj[tab[i].parent];
|
||||||
while (it && it->index != i)
|
while (it && it->index != i)
|
||||||
it = it->next;
|
it = it->next;
|
||||||
if (it)
|
if (it)
|
||||||
it->weight--;
|
it->weight--;
|
||||||
|
tab[i].old_visited = check_if_visited(data, i);
|
||||||
i = tab[i].parent;
|
i = tab[i].parent;
|
||||||
}
|
}
|
||||||
ret[1] = resolve_paths(data, nb_paths, s_ind, e_ind);
|
ret[1] = resolve_paths(data, nb_paths, s_ind, e_ind);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* 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/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
|
if ((*ret = edmonds_karp(lmdata, get_node_role(lmdata, 's')->ind
|
||||||
, get_node_role(lmdata, 'e')->ind)) == NULL)
|
, get_node_role(lmdata, 'e')->ind)) == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
print_paths(lmdata, *ret);
|
// print_paths(lmdata, *ret);
|
||||||
if (!push_ants(lmdata, *ret, get_nb_paths(*ret)))
|
if (!push_ants(lmdata, *ret, get_nb_paths(*ret)))
|
||||||
return (0);
|
return (0);
|
||||||
tablst_inddel(*ret);
|
tablst_inddel(*ret);
|
||||||
|
@ -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/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;
|
i = 0;
|
||||||
ant_c = 2;
|
ant_c = 2;
|
||||||
while (paths[i] && paths[i]->weight == 0)
|
while (paths[i] && paths[i]->weight == 0)
|
||||||
{
|
|
||||||
ft_printf("path: %d\n", i);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
ft_printf("ant path: %d\n", i);
|
|
||||||
if (add_ant(&ants, 1, i, paths) == NULL)
|
if (add_ant(&ants, 1, i, paths) == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
while (ants || ant_c <= data->nbants)
|
while (ants || ant_c <= data->nbants)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user