fuckinlem_in/srcs/score_utils.c
Tanguy MAZE 54be2278c0 It finnaly kinda works
algorithm with no double nodes and nearly efficient enough
still some optimizations to find for --big-superposition maps
2019-04-18 20:18:50 +02:00

90 lines
2.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* score_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void init_scores(t_ind **ret, int *scores)
{
int i;
i = 0;
while (ret[i])
{
scores[i] = ret[i]->weight;
ret[i]->weight = 0;
i++;
}
}
static int get_nb_nodes(t_ind *lst)
{
t_ind *it;
int i;
i = 0;
it = lst;
while (it && (++i))
it = it->next;
return (i);
}
int get_score(t_lmdata *data, t_ind **ret, int nb_paths)
{
int nbants;
int i;
int min;
int scores[nb_paths];
if (nb_paths == 1)
{
ret[0]->weight = data->nbants;
min = (ret[0]->weight > 0) * (get_nb_nodes(ret[0]) + ret[0]->weight - 1);
}
else
{
min = FT_INT_MAX;
i = -1;
nbants = data->nbants;
init_scores(ret, scores);
while (ret[++i])
if (min > scores[i])
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);
}
i++;
}
i = -1;
min = FT_INT_MAX;
while (ret[++i])
if (min > scores[i])
min = scores[i];
}
i = -1;
min = 0;
while (ret[++i])
if (min < scores[i])
min = scores[i];
}
return (min);
}