KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > supergene > SupergenesPerformanceTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package examples.supergene;
11
12 import java.io.*;
13 import org.jgap.supergenes.*;
14
15 /**
16  * Tests the performance, comparing computing time and the sum of the
17  * computed change amount deviations from the required amount.
18  * <P>
19  * Result of test is briefly outputted to the console and to a file named
20  * "Test_result.prn"
21  * @author Audrius Meskauskas
22  * @since 2.0
23  */

24 public final class SupergenesPerformanceTest {
25   /** String containing the CVS revision. Read out via reflection!*/
26   private final static String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
27
28   /**
29    * Starts the performance test
30    * @param args ignored
31    */

32   public static void main(String JavaDoc[] args) {
33     try {
34       AbstractSupergeneTest.REPORT_ENABLED = false;
35       SupergeneSample st = new SupergeneSample();
36       WithoutSupergeneSample wt = new WithoutSupergeneSample();
37       FileOutputStream fo = new FileOutputStream("Test_result.prn");
38       PrintStream out = new PrintStream(fo);
39       String JavaDoc s = "Popsize\t MaxIter\t t,supergene"
40           + "\t t,control"
41           + "\t Err,supergene \t Err,control";
42       out.println(s);
43       System.out.println(s);
44       int maxiter, popsize, i;
45       for (maxiter = 1; maxiter <= 256; maxiter = maxiter * 4) {
46         AbstractSupergeneTest.MAX_ALLOWED_EVOLUTIONS = maxiter;
47         for (popsize = 16; popsize < 2000; popsize = popsize * 2) {
48           AbstractSupergeneTest.POPULATION_SIZE = popsize;
49           int e_s = 0;
50           int e_w = 0;
51           long t_s = 0;
52           long t_w = 0;
53           for (i = 0; i < 10; i++) {
54             AbstractSupergene.reset();
55             long s_started;
56             // Test with Supergene.
57
// --------------------
58
s_started = System.currentTimeMillis();
59             int E_s = st.test();
60             long d_supergene = System.currentTimeMillis() - s_started;
61             // Test without Supergene.
62
// -----------------------
63
s_started = System.currentTimeMillis();
64             /*int E_w = */wt.test();
65             long d_without = System.currentTimeMillis() - s_started;
66             t_s += d_supergene;
67             t_w += d_without;
68             e_s += E_s;
69 // e_w += E_w;
70
}
71           String JavaDoc r = (popsize + "\t " + maxiter + "\t " + t_s
72                       + "\t " + t_w + "\t " + e_s + "\t " + e_w);
73           out.println(r);
74           System.out.println(r);
75         }
76       }
77       out.flush();
78       out.close();
79     }
80     catch (FileNotFoundException ex) {
81       ex.printStackTrace();
82     }
83   }
84 }
85
Popular Tags