diff --git a/.gitignore b/.gitignore index ffe3ca0..4ed587c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/convergence/elete1.pdf b/convergence/elete1.pdf new file mode 100644 index 0000000..612fedd Binary files /dev/null and b/convergence/elete1.pdf differ diff --git a/convergence/elete1s.pdf b/convergence/elete1s.pdf new file mode 100644 index 0000000..8f2bf92 Binary files /dev/null and b/convergence/elete1s.pdf differ diff --git a/convergence/elete2.pdf b/convergence/elete2.pdf new file mode 100644 index 0000000..2b0b88d Binary files /dev/null and b/convergence/elete2.pdf differ diff --git a/convergence/only_mutation1.pdf b/convergence/only_mutation1.pdf new file mode 100644 index 0000000..bbd36c4 Binary files /dev/null and b/convergence/only_mutation1.pdf differ diff --git a/convergence/tour1.pdf b/convergence/tour1.pdf new file mode 100644 index 0000000..f0e3d82 Binary files /dev/null and b/convergence/tour1.pdf differ diff --git a/convergence/tour2.pdf b/convergence/tour2.pdf new file mode 100644 index 0000000..156042e Binary files /dev/null and b/convergence/tour2.pdf differ diff --git a/generation.plt b/generation.plt index 0abc89b..e02fa1d 100644 --- a/generation.plt +++ b/generation.plt @@ -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" diff --git a/kadai1.png b/kadai1.png new file mode 100644 index 0000000..42bd188 Binary files /dev/null and b/kadai1.png differ diff --git a/path_length_plot.pdf b/path_length_plot.pdf new file mode 100644 index 0000000..6e12a5a Binary files /dev/null and b/path_length_plot.pdf differ diff --git a/tsp.c b/tsp.c index c0b2cbb..595a37a 100644 --- a/tsp.c +++ b/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; -} +} \ No newline at end of file diff --git a/tsp_jikken.c b/tsp_jikken.c index 432e4a4..96d663d 100644 --- a/tsp_jikken.c +++ b/tsp_jikken.c @@ -1,5 +1,4 @@ -#include -#include +#include #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;