Works a bit less but on in a better way

changed rules of queue addition
still problems on map4 with 2 merged paths
This commit is contained in:
Tanguy MAZE
2019-04-19 13:26:13 +02:00
parent 54be2278c0
commit 1f24922155
31 changed files with 14573 additions and 22 deletions

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/18 09:25:05 by tmaze #+# #+# */
/* Updated: 2019/04/18 15:49:17 by tmaze ### ########.fr */
/* Updated: 2019/04/19 12:51:55 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,6 +26,16 @@ void bfs_init(t_lmdata *data, t_bfs *tab)
}
}
int is_in_queue(t_lmdata *data, t_bfs *tab, int node)
{
int i;
i = 0;
while (i < data->nb_nodes && tab[i].queue != node)
i++;
return (i < data->nb_nodes && tab[i].queue == node);
}
void bfs(t_lmdata *data, t_bfs *tab, int s_ind, int e_ind)
{
int i;
@@ -36,23 +46,16 @@ void bfs(t_lmdata *data, t_bfs *tab, int s_ind, int e_ind)
i = 0;
bfs_init(data, tab);
tab[i].queue = s_ind;
used = 1;
while (i < data->nb_nodes && tab[i].queue != -1 && tab[e_ind].parent == -1)
{
tab[tab[i].queue].visited = 1;
it = data->adj[tab[i].queue];
while (it && used)
{
if (it->weight > 0 && !tab[it->index].visited && !tab[it->index].old_visited)
used = 0;
it = it->next;
}
used = (tab[tab[i].queue].old_visited && !tab[tab[tab[i].queue].parent].old_visited);
it = data->adj[tab[i].queue];
while (it)
{
if (it->weight > 0 && !tab[it->index].visited && ((tab[tab[i].queue].old_visited && tab[it->index].old_visited) || (used && tab[it->index].old_visited) || (!used && !tab[it->index].old_visited)))
if (it->weight > 0 && !tab[it->index].visited && (!used || (used && it->weight == 2)))
{
j = 0;
j = 0;
while (j < data->nb_nodes && tab[j].queue != -1 && tab[j].queue != it->index)
j++;
if (j < data->nb_nodes && tab[j].queue == -1)

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/18 09:59:11 by tmaze #+# #+# */
/* Updated: 2019/04/18 19:39:47 by tmaze ### ########.fr */
/* Updated: 2019/04/19 12:53:52 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -110,10 +110,6 @@ t_ind **edmonds_karp(t_lmdata *data, int s_ind, int e_ind)
}
ret[1] = resolve_paths(data, nb_paths, s_ind, e_ind);
scores[1] = get_score(data, ret[1], nb_paths);
ft_printf("scores[0]: %d\nscores[1]: %d\n\n", scores[0], scores[1]);
i = -1;
while (ret[1][++i])
ft_printf("ret[%d]->weight: %d\n\n", i, ret[1][i]->weight);
if (ret[0] == NULL || scores[1] < scores[0])
{
if (ret[0] != NULL)

View File

@@ -6,7 +6,7 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
/* Updated: 2019/04/18 17:34:32 by tmaze ### ########.fr */
/* Updated: 2019/04/19 12:56:45 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);

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/18 18:05:06 by tmaze #+# #+# */
/* Updated: 2019/04/18 20:13:29 by tmaze ### ########.fr */
/* Updated: 2019/04/19 12:52:45 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -60,13 +60,10 @@ int get_score(t_lmdata *data, t_ind **ret, int nb_paths)
min = scores[i];
while (nbants > 0 && !(i = 0))
{
ft_printf("=== debug score ===\nnb_paths: %d\nscore[%d]: %d\nmin: %d\nnbants: %d\n\n", nb_paths, i, scores[i], min, nbants);
while (i < nb_paths && nbants > 0)
{
ft_printf("score[%d]: %d\n\n", i, scores[i]);
if (scores[i] == min)
{
ft_printf("increment\n\n");
nbants--;
ret[i]->weight++;
scores[i] = (ret[i]->weight > 0) * (get_nb_nodes(ret[i]) + ret[i]->weight - 1);
@@ -82,8 +79,11 @@ int get_score(t_lmdata *data, t_ind **ret, int nb_paths)
i = -1;
min = 0;
while (ret[++i])
{
scores[i] = (ret[i]->weight > 0) * (get_nb_nodes(ret[i]) + ret[i]->weight - 1);
if (min < scores[i])
min = scores[i];
}
}
return (min);
}