소스 검색

Print values of inter and intra in results

Signed-off-by: wmb <wmb@teknik.io>
tags/v0.1.0
wmb 7 달 전
부모
커밋
8c326568d1
1개의 변경된 파일11개의 추가작업 그리고 12개의 파일을 삭제
  1. 11
    12
      main.c

+ 11
- 12
main.c 파일 보기

@@ -22,7 +22,7 @@ bool solution_valide(const solution s);
void print_solution(const solution s, const char *name);
vector *centres_gravite(const solution s);
int solution_voisine(solution *dest, const solution src);
double fonction_objective(const solution s);
double fonction_objective(const solution s, double *inter, double *intra);

static double calculer_inter(const vector *cgs);
static double calculer_intra(const solution s, const vector *cgs);
@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
{
int c;
int i;
double f0;
double f0, inter, intra;;

while ((c = getopt(argc, argv, ":c:i:h")) != -1) {
int k;
@@ -78,10 +78,10 @@ int main(int argc, char *argv[])
while (!trouver_solution_initiale())
continue; /* do it again */

f0 = fonction_objective(solution_opt);
f0 = fonction_objective(solution_opt, &inter, &intra);

print_solution(solution_opt, "initiale");
printf("F(solution) = %f\n", f0);
printf("F(solution) = %f - %f = %f\n", inter, intra, f0);

for (i = 0; i < n_iterations; i++) {
double f1;
@@ -89,9 +89,10 @@ int main(int argc, char *argv[])
while (!solution_voisine(&new_solution, solution_opt))
continue; /* do it again */

if ((f1 = fonction_objective(new_solution)) > f0) {
if ((f1 = fonction_objective(new_solution, &inter, &intra)) > f0) {
print_solution(new_solution, "optimale trouvée");
printf("F(solution) = %f (%f%% improvement)\n", f1, fabs((f1 - f0) / f0 * 100.0));
printf("F(solution) = %f - %f = %f (%f%% improvement)\n",
inter, intra, f1, fabs((f1 - f0) / f0 * 100.0));
free(solution_opt);
solution_opt = new_solution;
new_solution = NULL;
@@ -265,26 +266,24 @@ int solution_voisine(solution *dest, const solution src)
return valid;
}

double fonction_objective(const solution s)
double fonction_objective(const solution s, double *inter, double *intra)
{
int i;
double **cgs = centres_gravite(s);
double inter;
double intra;


if (!cgs)
abort();

inter = calculer_inter(cgs);
intra = calculer_intra(s, cgs);
*inter = calculer_inter(cgs);
*intra = calculer_intra(s, cgs);

for (i = 0; i < n_clusters + 1; i++)
free(cgs[i]);

free(cgs);

return inter - intra;
return *inter - *intra;
}

static double calculer_inter(const vector *cgs)

Loading…
취소
저장