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

11295
map4 Normal file

File diff suppressed because it is too large Load Diff

BIN
maps/.DS_Store vendored Normal file

Binary file not shown.

3050
maps/big Normal file

File diff suppressed because it is too large Load Diff

11
maps/comments Normal file
View File

@ -0,0 +1,11 @@
3
#you
##start
start 0 0
#lost
##end
end 1 1
#the
#game
start-end
#!!

7
maps/duplicatepipe Normal file
View File

@ -0,0 +1,7 @@
3
##start
start 0 0
##end
end 0 0
start-end
end-start

7
maps/duplicatepipe1 Normal file
View File

@ -0,0 +1,7 @@
3
##start
start 0 0
##end
end 0 0
start-end
start-end

0
maps/empty Normal file
View File

7
maps/illegalname Normal file
View File

@ -0,0 +1,7 @@
3
Lillegalname 2 2
##start
start 0 0
##end
end 1 1
start-end

7
maps/illegalname1 Normal file
View File

@ -0,0 +1,7 @@
3
ill-egalname 2 2
##start
start 0 0
##end
end 1 1
start-end

25
maps/in0 Normal file
View File

@ -0,0 +1,25 @@
3
##start
1 23 3
2 16 7
#commentaire
3 16 3
4 16 5
5 9 3
6 1 5
7 4 8
##end
0 9 5
0-4
0-6
1-3
4-3
5-2
3-5
#autre commentaire
4-2
2-1
7-6
7-2
7-4
6-5

8
maps/invalidcommand Normal file
View File

@ -0,0 +1,8 @@
3
##start
start 0 0
##end
end 1 1
##invalidcommand
room 2 2
start-end

6
maps/invalidcommand1 Normal file
View File

@ -0,0 +1,6 @@
3
start 0 0
##end
end 1 1
##start
start-end

11
maps/loop Normal file
View File

@ -0,0 +1,11 @@
3
##start
start 0 0
##end
end 1 1
mid0 2 2
mid1 3 3
start-mid0
mid0-mid1
mid1-start
start-end

10
maps/loop1 Normal file
View File

@ -0,0 +1,10 @@
3
##start
start 0 0
##end
end 1 1
mid0 2 2
mid1 3 3
start-mid0
mid0-mid1
mid1-start

5
maps/noants Normal file
View File

@ -0,0 +1,5 @@
##start
start 0 0
##end
end 1 1
start-end

5
maps/noend Normal file
View File

@ -0,0 +1,5 @@
3
##start
start 0 0
end 1 1
start-end

5
maps/nopath Normal file
View File

@ -0,0 +1,5 @@
3
##start
start 0 0
##end
end 1 1

5
maps/nostart Normal file
View File

@ -0,0 +1,5 @@
3
start 0 0
##end
end 1 1
start-end

6
maps/overflow Normal file
View File

@ -0,0 +1,6 @@
3
##start
start 0 0
##end
end 999999999999999999999 9999999999999999999999999999
start-end

20
maps/shortest Normal file
View File

@ -0,0 +1,20 @@
3
##start
start 0 0
##end
end 1 1
long0 2 2
long1 3 3
short 4 4
longer0 5 5
longer1 6 6
longer2 7 7
start-long0
long0-long1
long1-end
start-short
short-end
start-longer0
longer0-longer1
longer1-longer2
longer2-end

6
maps/simple Normal file
View File

@ -0,0 +1,6 @@
3
##start
start 0 0
##end
end 1 1
start-end

10
maps/simple1 Normal file
View File

@ -0,0 +1,10 @@
4
##start
start 0 0
##end
end 1 1
dead0 2 2
dead1 3 3
start-dead0
start-dead1
start-end

16
maps/simple2 Normal file
View File

@ -0,0 +1,16 @@
4
##start
start 0 0
##end
end 1 1
dead0 2 2
dead1 3 3
mid0 4 4
mid1 5 5
mid2 6 6
start-dead0
start-mid0
mid0-dead0
start-mid1
mid1-mid2
mid2-end

4
maps/startisend Normal file
View File

@ -0,0 +1,4 @@
3
##start
##end
startend 0 0

13
maps/subject22.map Normal file
View File

@ -0,0 +1,13 @@
3
1 0 2
##start
0 2 0
##end
4 2 6
2 4 2
3 4 4
0-1
0-2
2-3
3-4
4-1

6
maps/underflow Normal file
View File

@ -0,0 +1,6 @@
3
##start
start 0 0
##end
end 1 -9999999999999999999999999
start-end

7
maps/whitespaces Normal file
View File

@ -0,0 +1,7 @@
3
# #end
##start
start 0 0
##end
end 1 1
start-end

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);
}