It finnaly kinda works
algorithm with no double nodes and nearly efficient enough still some optimizations to find for --big-superposition maps
This commit is contained in:
68
srcs/bfs.c
Normal file
68
srcs/bfs.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bfs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void bfs_init(t_lmdata *data, t_bfs *tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < data->nb_nodes)
|
||||
{
|
||||
tab[i].queue = -1;
|
||||
tab[i].visited = 0;
|
||||
tab[i].parent = -1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void bfs(t_lmdata *data, t_bfs *tab, int s_ind, int e_ind)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int used;
|
||||
t_ind *it;
|
||||
|
||||
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;
|
||||
}
|
||||
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)))
|
||||
{
|
||||
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)
|
||||
{
|
||||
tab[j].queue = it->index;
|
||||
tab[it->index].parent = tab[i].queue;
|
||||
}
|
||||
}
|
||||
it = it->next;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user