thinking of how to display the ants moving and optimise by moving at least one on each path
71 lines
2.5 KiB
C
71 lines
2.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* lem_in.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/03/25 06:31:05 by mndhlovu #+# #+# */
|
|
/* Updated: 2019/04/05 14:40:50 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "lem_in.h"
|
|
|
|
int lm_error_exit(int flag)
|
|
{
|
|
if (flag == 0)
|
|
ft_printf("Invalid Map\n");
|
|
if (flag == 1)
|
|
ft_printf("Usage ./lem_in < map-file\n");
|
|
if (flag == 2)
|
|
ft_printf("Error opening the Map file\n");
|
|
return (1);
|
|
}
|
|
|
|
int main(int ac, char **av)
|
|
{
|
|
t_syntax synt;
|
|
//t_graph graph;
|
|
t_lmdata ldata;
|
|
t_holder holder;
|
|
int fd;
|
|
t_node *it;
|
|
t_node *start;
|
|
t_node *end;
|
|
|
|
if (ac == 2)
|
|
{
|
|
if ((fd = open (av[1], O_RDONLY)) < -1)
|
|
return (lm_error_exit(2));
|
|
lm_init_data(&synt, &ldata, &holder);
|
|
lm_parser(fd, &synt, &ldata, &holder);
|
|
if (lm_validate(&synt, &ldata))
|
|
{
|
|
//validation works
|
|
ft_printf("Success\n");
|
|
ft_printf("=== ldata ===\nnbants: %d\nnb_nodes: %d\nnodes: %p\nnodes_data: %p\nadj: %d\n\n", ldata.nbants, ldata.nb_nodes, ldata.nodes, ldata.nodes_data, ldata.adj);
|
|
it = ldata.nodes_data;
|
|
while (it && it->role != 's')
|
|
{
|
|
ft_printf("=== node ===\nindex: %d\nrole: %c\n\n", it->ind, it->role);
|
|
it = it->next;
|
|
}
|
|
ft_printf("=== node ===\nindex: %d\nrole: %c\n\n", it->ind, it->role);
|
|
start = it;
|
|
it = ldata.nodes_data;
|
|
while (it && it->role != 'e')
|
|
{
|
|
ft_printf("=== node ===\nindex: %d\nrole: %c\n\n", it->ind, it->role);
|
|
it = it->next;
|
|
}
|
|
ft_printf("=== node ===\nindex: %d\nrole: %c\n\n", it->ind, it->role);
|
|
end = it;
|
|
edmunds_karp(&ldata, start->ind, end->ind);
|
|
}
|
|
else
|
|
ft_printf("Fail\n");
|
|
}
|
|
return (0);
|
|
}
|