01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licensing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
10: package examples.supergene;
11:
12: import java.io.*;
13: import org.jgap.super genes.*;
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: *
22: * @author Audrius Meskauskas
23: * @since 2.0
24: */
25: public final class SupergenesPerformanceTest {
26: /** String containing the CVS revision. Read out via reflection!*/
27: private final static String CVS_REVISION = "$Revision: 1.3 $";
28:
29: /**
30: * Starts the performance test.
31: *
32: * @param args ignored
33: */
34: public static void main(String[] args) {
35: try {
36: AbstractSupergeneTest.REPORT_ENABLED = false;
37: SupergeneSample st = new SupergeneSample();
38: WithoutSupergeneSample wt = new WithoutSupergeneSample();
39: FileOutputStream fo = new FileOutputStream(
40: "Test_result.prn");
41: PrintStream out = new PrintStream(fo);
42: String s = "Popsize\t MaxIter\t t,supergene"
43: + "\t t,control"
44: + "\t Err,supergene \t Err,control";
45: out.println(s);
46: System.out.println(s);
47: int maxiter, popsize, i;
48: for (maxiter = 1; maxiter <= 256; maxiter = maxiter * 4) {
49: AbstractSupergeneTest.MAX_ALLOWED_EVOLUTIONS = maxiter;
50: for (popsize = 16; popsize < 2000; popsize = popsize * 2) {
51: AbstractSupergeneTest.POPULATION_SIZE = popsize;
52: int e_s = 0;
53: int e_w = 0;
54: long t_s = 0;
55: long t_w = 0;
56: for (i = 0; i < 10; i++) {
57: AbstractSupergene.reset();
58: long s_started;
59: // Test with Supergene.
60: // --------------------
61: s_started = System.currentTimeMillis();
62: int E_s = st.test();
63: long d_super gene = System.currentTimeMillis()
64: - s_started;
65: // Test without Supergene.
66: // -----------------------
67: s_started = System.currentTimeMillis();
68: /*int E_w = */wt.test();
69: long d_without = System.currentTimeMillis()
70: - s_started;
71: t_s += d_super gene;
72: t_w += d_without;
73: e_s += E_s;
74: }
75: String r = (popsize + "\t " + maxiter + "\t " + t_s
76: + "\t " + t_w + "\t " + e_s + "\t " + e_w);
77: out.println(r);
78: System.out.println(r);
79: }
80: }
81: out.flush();
82: out.close();
83: } catch (FileNotFoundException ex) {
84: ex.printStackTrace();
85: }
86: }
87: }
|