レポート書いてます.あとは考察

main
KoyoNoguchi 2 months ago
parent e6d63bec59
commit 71dc0d33d2
  1. 2
      .gitignore
  2. BIN
      convergence/elete1.pdf
  3. BIN
      convergence/elete1s.pdf
  4. BIN
      convergence/elete2.pdf
  5. BIN
      convergence/only_mutation1.pdf
  6. BIN
      convergence/tour1.pdf
  7. BIN
      convergence/tour2.pdf
  8. 16
      generation.plt
  9. BIN
      kadai1.png
  10. BIN
      path_length_plot.pdf
  11. 33
      tsp.c
  12. 7
      tsp_jikken.c

2
.gitignore vendored

@ -77,7 +77,7 @@ dkms.conf
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
*.pdf
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,6 +1,11 @@
#
set terminal pdfcairo size 4in,3in font "Arial,12"
set output 'path_length_plot.pdf'
#
if (!exists("infile")) infile = 'output.dat'
if (!exists("outfile")) outfile = 'path_length_plot.pdf'
set output outfile
set xlabel "generation"
set ylabel "path length"
@ -12,9 +17,12 @@ set yrange [0:80]
set xtics 10
set ytics 10
#
set datafile separator ","
#
# $0 0
# 1:min, 2:avg, 3:max
plot 'output.dat' using 0:1 with lines title "Min", \
'' using 0:2 with lines title "Avg", \
'' using 0:3 with lines title "Max"
plot infile using 0:1 with lines title "Min", \
'' using 0:2 with lines title "Avg", \
'' using 0:3 with lines title "Max"

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

33
tsp.c

@ -28,8 +28,8 @@ void print_data(Gene_set gene_group[GENE_NUM]) /* データの表示 */
worst = gene_group[i].length; /* 最悪値 */
}
}
//printf("best = %g, ave = %g, worst = %g\n", best, sum/GENE_NUM, worst);
printf("%g, %g, %g\n", best, sum/GENE_NUM, worst);
printf("best = %g, ave = %g, worst = %g\n", best, sum/GENE_NUM, worst);
//printf("%g, %g, %g\n", best, sum/GENE_NUM, worst);
}
int main(int argc, char *argv[])
@ -78,26 +78,19 @@ int main(int argc, char *argv[])
fclose(fp);
}
printf("# Trial, MutationRate, SelectNum, BestLength, GenToBest\n");
for (int aaa = 0; aaa < 10; aaa++)
{
/* 各種データの初期化 */
initial_gene(gene_group); /* 遺伝子集団の生成 */
initial_fitness(gene_group, city); /* 初期適合度の計算 */
/* 初期データの表示 */
//print_city(city);
print_city(city);
#if PRINT_GENE /* 1/2 */
print_gene_group(gene_group);
#endif /* PRINT_GENE 1/2 */
// printf("INITIAL RESULT\n");
// print_best_data(gene_group);
printf("INITIAL RESULT\n");
print_best_data(gene_group);
double best = gene_group[0].length;
int bg = 0;
for(i = 0; i < GENERATION; i++) {
/* 選択 */
selection(gene_group); /* この関数を実験で作成 */
@ -107,29 +100,21 @@ int main(int argc, char *argv[])
/* 適合度計算 */
calculate_fitness(gene_group, city);
if (gene_group[0].length < best)
{
best = gene_group[0].length;
bg = i;
}
#if PRINT_PROCESS
/* 進化中のデータ表示 */
//printf("GENERATION %d\n", i);
//print_data(gene_group);
printf("GENERATION %d\n", i);
print_data(gene_group);
/* print_best_data(gene_group); */
#endif /* PRINT_PROCESS */
}
printf("%d, %.2f, %d, %.2f, %d\n", aaa, MUTATION_RATIO, SELECT_NUM, best, bg);
/* 進化終了時のデータ表示 */
//printf("FINAL RESULT\n");
printf("FINAL RESULT\n");
#if PRINT_GENE /* 2/2 */
print_gene_group(gene_group);
#endif /* PRINT_GENE 2/2 */
//print_best_data(gene_group);
}
print_best_data(gene_group);
return 0;
}

@ -1,5 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include "tsp.h"
#define ELETE_SELECTION YES /* エリート戦略で選択 */
@ -47,6 +46,7 @@ void selection(Gene_set gene_group[GENE_NUM])
#endif /* ELETE_SELECTION 2/2 */
}
/* トーナメント方式による選択 */
void tournament(Gene_set gene_group[GENE_NUM])
{
int i, j, k, l;
@ -92,6 +92,7 @@ void tournament(Gene_set gene_group[GENE_NUM])
copy_gene_group(gene_group, next_gene_group);
}
/* エリート戦略による選択 */
void elete(Gene_set gene_group[GENE_NUM])
{
int i, j, k, l;
@ -136,6 +137,7 @@ void elete(Gene_set gene_group[GENE_NUM])
copy_gene_group(gene_group, next_gene_group);
}
/* 遺伝子セットの複写 */
void copy_gene_set(Gene_set *gene_set_to, Gene_set *gene_set_from)
{
int i;
@ -148,6 +150,7 @@ void copy_gene_set(Gene_set *gene_set_to, Gene_set *gene_set_from)
gene_set_to->fitness = gene_set_from->fitness;
}
/* 遺伝子集団の複写 */
void copy_gene_group(Gene_set gene_group_to[GENE_NUM], Gene_set gene_group_from[GENE_NUM])
{
int i;

Loading…
Cancel
Save