74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* score_utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/15 14:24:15 by tmaze #+# #+# */
|
|
/* Updated: 2019/04/15 17:50:56 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "lem_in.h"
|
|
|
|
void init_paths(t_path *ret)
|
|
{
|
|
int nb_paths;
|
|
int i;
|
|
int nb_nodes;
|
|
t_ind *it;
|
|
|
|
nb_paths = 0;
|
|
while (ret[nb_paths].nodes)
|
|
{
|
|
ret[nb_paths].nb_ants = 0;
|
|
ret[nb_paths].score = 0;
|
|
nb_paths++;
|
|
}
|
|
i = 0;
|
|
while (ret[i].nodes && !(nb_nodes = 0))
|
|
{
|
|
it = ret[i].nodes;
|
|
while (it && ++nb_nodes)
|
|
it = it->next;
|
|
ret[i].score = nb_nodes;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
int get_score(t_lmdata *data, t_path *ret)
|
|
{
|
|
int i;
|
|
int ant_c;
|
|
int max;
|
|
|
|
init_paths(ret);
|
|
i = -1;
|
|
max = 0;
|
|
while (ret[++i].nodes)
|
|
{
|
|
if (ret[max].score < ret[i].score)
|
|
max = i;
|
|
}
|
|
ant_c = 0;
|
|
while (ant_c < data->nbants && !(i = 0))
|
|
{
|
|
while (ret[i].nodes && ((ret[i].nb_ants > 0) * (ret[i].score + ret[i].nb_ants - 1)) < ret[max].score && ant_c < data->nbants)
|
|
{
|
|
ret[i].nb_ants++;
|
|
ant_c++;
|
|
ret[i].score = (ret[i].nb_ants > 0) * (ret[i].score + ret[i].nb_ants - 1);
|
|
i++;
|
|
}
|
|
i = -1;
|
|
max = 0;
|
|
while (ret[++i].nodes)
|
|
{
|
|
if (ret[max].score < ret[i].score)
|
|
max = i;
|
|
}
|
|
}
|
|
return (ret[max].score);
|
|
}
|