Skip to content

Commit fa35ea2

Browse files
author
A. Wilke
committed
enhanced output
1 parent dec93dc commit fa35ea2

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/de/adrianwilke/acotspjava/AcoTsp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public static void main(String[] args) {
553553
Ants.total = Utilities.generate_double_matrix(Tsp.n, Tsp.n);
554554

555555
InOut.time_used = Timer.elapsed_time();
556-
System.out.println("Initialization took " + InOut.time_used + " seconds");
556+
System.out.println("Initialization took " + InOut.time_used + " seconds\n");
557557

558558
for (InOut.n_try = 0; InOut.n_try < InOut.max_tries; InOut.n_try++) {
559559

src/de/adrianwilke/acotspjava/InOut.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum Distance_type {
7474

7575
static Distance_type distance_type;
7676

77-
public static final String PROG_ID_STR = "ACO algorithms for the TSP, v1.02";
77+
public static final String PROG_ID_STR = "ACO algorithms for the TSP";
7878

7979
static int[] best_in_try;
8080
static int[] best_found_at;
@@ -136,7 +136,7 @@ static Tsp.point[] read_etsp(String tsp_file_name) throws IOException
136136
System.exit(1);
137137
}
138138

139-
System.out.println("reading tsp-file " + tsp_file_name + " ... ");
139+
System.out.println("\nreading tsp-file " + tsp_file_name + " ... ");
140140

141141
i = 0;
142142
boolean found_coord_section = false;
@@ -201,6 +201,8 @@ static Tsp.point[] read_etsp(String tsp_file_name) throws IOException
201201

202202
// TRACE ( System.out.println("number of cities is %ld\n",Tsp.n); )
203203
// TRACE ( System.out.println("\n... done\n"); )
204+
System.out.println();
205+
204206
return (nodeptr);
205207
}
206208

@@ -417,9 +419,9 @@ static void population_statistics()
417419
avg_distance /= ((double) Ants.n_ants * (double) (Ants.n_ants - 1) / 2.);
418420

419421
if (stat_report != null) {
420-
printToFile(stat_report, iteration + "\t" + pop_mean + "\t" + pop_stddev + "\t" + pop_stddev + "\t"
421-
+ pop_mean + "\t" + branching_factor + "\t" + (branching_factor - 1.) * (double) Tsp.n + "\t"
422-
+ avg_distance + "\t" + avg_distance / (double) Tsp.n);
422+
printToFile(stat_report, iteration + "\t" + pop_mean + "\t" + pop_stddev + "\t" + (pop_stddev / pop_mean)
423+
+ "\t" + branching_factor + "\t" + ((branching_factor - 1.) * (double) Tsp.n) + "\t" + avg_distance
424+
+ "\t" + (avg_distance / (double) Tsp.n));
423425
}
424426
}
425427

@@ -550,8 +552,8 @@ static void exit_program()
550552

551553
if (report != null) {
552554
printToFile(report, "\nAverage-Best: " + avg_sol_quality + "\t Average-Iterations: " + avg_cyc_to_bst);
553-
printToFile(report, "\nStddev-Best: " + stddev_best + " \t Stddev Iterations: " + stddev_iterations);
554-
printToFile(report, "\nBest try: " + best_tour_length + "\t\t Worst try: " + worst_tour_length);
555+
printToFile(report, "Stddev-Best: " + stddev_best + " \t Stddev Iterations: " + stddev_iterations);
556+
printToFile(report, "Best try: " + best_tour_length + "\t\t Worst try: " + worst_tour_length);
555557
printToFile(report, "\nAvg.time-best: " + t_avgbest + " stddev.time-best: " + t_stdbest);
556558
printToFile(report, "\nAvg.time-Ants.total: " + t_avgtotal + " stddev.time-Ants.total: " + t_stdtotal);
557559

@@ -655,14 +657,14 @@ static void init_program(String[] args)
655657
stat_report = null;
656658
}
657659

658-
System.out.println("calculating distance matrix ..\n\n");
660+
System.out.println("calculating distance matrix ..");
659661
Tsp.instance.distance = Tsp.compute_distances();
660662
System.out.println(" .. done\n");
661663
write_params();
662664

663665
if (comp_report != null)
664666
printToFile(comp_report, "begin problem " + name_buf);
665-
System.out.println("allocate ants' memory ..\n\n");
667+
System.out.println("allocate ants' memory ..");
666668
Ants.allocate_ants();
667669
System.out.println(" .. done\n");
668670
}
@@ -860,30 +862,30 @@ static void write_params()
860862
* OUTPUT: none
861863
*/
862864
{
863-
System.out.println("\nParameter-settings: \n\n");
865+
System.out.println("Parameter-settings:\n");
864866
fprintf_parameters(null);
865867
System.out.println("\n");
866868

867869
if (report != null) {
868-
printToFile(report, "\nParameter-settings: \n\n");
870+
printToFile(report, "Parameter-settings: \n\n");
869871
fprintf_parameters(report);
870872
printToFile(report, "\n");
871873
}
872874

873875
if (comp_report != null) {
874876
printToFile(comp_report, PROG_ID_STR);
875-
printToFile(comp_report, "\nParameter-settings: \n\n");
877+
printToFile(comp_report, "Parameter-settings: \n\n");
876878
fprintf_parameters(comp_report);
877879
printToFile(comp_report, "\n");
878880
}
879881
}
880882

881883
static void printToFile(File file, String string) {
882884
if (file == null) {
883-
System.out.println(string + "\n");
885+
System.out.println(string);
884886
} else {
885887
try {
886-
writer.get(file.getName()).write(string);
888+
writer.get(file.getName()).write(string + "\n");
887889
} catch (IOException e) {
888890
System.err.print("Could not write file " + file.getName() + " " + e.getMessage());
889891
System.exit(1);

0 commit comments

Comments
 (0)