/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ Franz Wilhelmstötter
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 *     
 */
package org.jenetics.examples;

import static java.lang.System.out;

import org.jenetics.GeneticAlgorithm;
import org.jenetics.Statistics;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version $Id: GAUtils.java,v 1.14 2010-01-14 15:00:10 fwilhelm Exp $
 */
public class GAUtils {

	private GAUtils() {
	}
	
	public static void execute(final GeneticAlgorithm<?, ?> ga, int generations) {
		ga.setup();	
		System.out.println(ga);
		for (int i = 1; i < generations; ++i) {
			ga.evolve();
			System.out.println(ga);
			System.out.flush();
		}
		
		final Statistics.Time time = ga.getTimeStatistics();
		
		out.println();
		out.println("               Select time: " + time.selection);
		out.println("                Alter time: " + time.alter);
		out.println("  Fitness calculation time: " + time.evaluation);
		out.println("Statistic calculation time: " + time.statistics);
		out.println("----------------------------");
		out.println("    Overall execution time: " + time.execution);
		out.println();
		out.println(ga.getBestStatistic());
		out.flush();
	}
	
}

@@ -993,16 +993,120 @@
 m.out;%0A%0A
+import javax.measure.Measurable;%0Aimport javax.measure.quantity.Duration;%0Aimport javax.measure.unit.SI;%0A%0A
 import o
@@ -1289,17 +1289,17 @@
 va,v 1.1
-4
+5
  2010-01
@@ -1304,18 +1304,18 @@
 01-1
-4 15:00:10
+5 10:39:13
  fwi
@@ -1697,36 +1697,15 @@
 ;%0A%09%09
-out.
 print
-ln(%22               
+(%22
 Sele
@@ -1707,29 +1707,26 @@
 %22Select time
-: %22 +
+%22,
  time.select
@@ -1732,42 +1732,26 @@
 tion
+.get()
 );%0A%09%09
-out.
 print
-ln(%22                
+(%22
 Alte
@@ -1752,29 +1752,26 @@
 (%22Alter time
-: %22 +
+%22,
  time.alter)
@@ -1769,36 +1769,34 @@
 me.alter
+.get()
 );%0A%09%09
-out.
 print
-ln(%22  
+(%22
 Fitness 
@@ -1807,29 +1807,26 @@
 ulation time
-: %22 +
+%22,
  time.evalua
@@ -1829,32 +1829,32 @@
 aluation
+.get()
 );%0A%09%09
-out.
 print
-ln
 (%22Statis
@@ -1869,29 +1869,26 @@
 ulation time
-: %22 +
+%22,
  time.statis
@@ -1891,16 +1891,22 @@
 atistics
+.get()
 );%0A%09%09out
@@ -1947,31 +1947,40 @@
 ----
+-------------------
 %22);%0A%09%09
-out.
 print
-ln(%22    
+(%22
 Over
@@ -2001,13 +2001,10 @@
 time
-: %22 +
+%22,
  tim
@@ -2014,16 +2014,22 @@
 xecution
+.get()
 );%0A%09%09out
@@ -2098,10 +2098,192 @@
 );%0A%09%7D%0A%09%0A
+%09%0A%09private static void print(final String label, final Measurable%3CDuration%3E value) %7B%0A%09%09out.println(String.format(%22%2530s: %2511.11f %25s%22, label, value.doubleValue(SI.SECOND), %22s%22));%0A%09%7D%0A%09%0A
 %7D%0A

Improve execution time output.