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 licencing 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 junit.framework.*;
13: import org.jgap.super genes.*;
14:
15: /**
16: * Total test of the supported Supergene classes. Due to slow run it is not
17: * included into the test suite.
18: *
19: * @author Audrius Meskauskas
20: * @since 2.0
21: */
22: public class TotalSupergeneTest extends TestCase {
23: /** String containing the CVS revision. Read out via reflection!*/
24: private final static String CVS_REVISION = "$Revision: 1.1 $";
25:
26: /**
27: * Test supported Supergene features, including performance tests.
28: * previously: return true if the Supergene tests succeded
29: * @throws Exception
30: */
31: public void testSupergeneTotal() throws Exception {
32: System.out.println("Testing Supergene...");
33: AbstractSupergeneTest.EXISTING_SOLUTIONS_ONLY = true;
34: AbstractSupergeneTest.REPORT_ENABLED = false;
35: Force.REPORT_ENABLED = false;
36: System.out.println("Testing Persistent representation");
37: // assertTrue("Persistent representation",
38: // SupergenePersistentRepresentationTest.testRepresentation());
39: System.out
40: .println("Testing Supergene 150 % performance benefit ");
41: AbstractSupergeneTest.MAX_ALLOWED_EVOLUTIONS = 512;
42: AbstractSupergeneTest.POPULATION_SIZE = 256;
43: long abe = 0;
44: int N = 12;
45: for (int i = 1; i <= N; i++) {
46: System.out.println("Iteration " + i + " of " + N);
47: AbstractSupergene.reset();
48: long s_started;
49: // Test with Supergene
50: System.out.print(" evaluating Supergene... ");
51: s_started = System.currentTimeMillis();
52: int E_s = new SupergeneSample().test();
53: long d_super gene = System.currentTimeMillis() - s_started;
54: // Test without Supergene
55: System.out.println("control...");
56: s_started = System.currentTimeMillis();
57: int E_w = new WithoutSupergeneSample().test();
58: long d_without = System.currentTimeMillis() - s_started;
59: assertTrue("Correctness of solution: supergene " + E_s
60: + " control " + E_w, E_s == 0 && E_w == 0);
61: long benefit = (100 * d_without) / d_super gene;
62: assertTrue("Computation speed: supergene " + d_super gene
63: + " control " + d_without + ", benefit " + benefit,
64: true);
65: abe += benefit;
66: }
67: abe = abe / N;
68: assertTrue("Averaged benefit " + abe, abe >= 150);
69: System.out.println("Supergene test complete.");
70: // return true;
71: }
72: }
|