KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > supergene > TotalSupergeneTest


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
14 import junit.framework.*;
15 import org.jgap.supergenes.*;
16
17 /**
18  * Total test of the supported Supergene classes. Due to slow run it is not
19  * included into AllTests.
20  *
21  * @author Audrius Meskauskas
22  * @since 2.0
23  */

24 public class TotalSupergeneTest
25     extends TestCase {
26   /** String containing the CVS revision. Read out via reflection!*/
27   private final static String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
28
29   /**
30    * Test supported Supegene features, including performance tests.
31    * @throws Exception
32    */

33   public void testSupergeneTotal() throws Exception JavaDoc {
34       System.out.println("Testing Supergene...");
35       AbstractSupergeneTest.EXISTING_SOLUTIONS_ONLY = true;
36       AbstractSupergeneTest.REPORT_ENABLED = false;
37       Force.REPORT_ENABLED = false;
38       System.out.println("Testing Persistent representation");
39 // assertTrue("Persistent representation",
40
// SupergenePersistentRepresentationTest.testRepresentation());
41
System.out.println("Testing Supergene 150 % performance benefit ");
42       AbstractSupergeneTest.MAX_ALLOWED_EVOLUTIONS = 512;
43       AbstractSupergeneTest.POPULATION_SIZE = 256;
44       long abe = 0;
45       int N = 12;
46       for (int i = 1; i <= N; i++) {
47         System.out.println("Iteration " + i + " of " + N);
48         AbstractSupergene.reset();
49         long s_started;
50         // Test with Supergene
51
System.out.print(" evaluating Supergene... ");
52         s_started = System.currentTimeMillis();
53         int E_s = new SupergeneSample().test();
54         long d_supergene = System.currentTimeMillis() - s_started;
55         // Test without Supergene
56
System.out.println("control...");
57         s_started = System.currentTimeMillis();
58         int E_w = new WithoutSupergeneSample().test();
59         long d_without = System.currentTimeMillis() - s_started;
60         assertTrue("Correctness of solution: supergene " + E_s
61                    + " control " + E_w, E_s == 0 && E_w == 0);
62         long benefit = (100 * d_without) / d_supergene;
63         assertTrue("Computation speed: supergene " + d_supergene
64                    + " control " + d_without + ", benefit " + benefit, 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 }
73
Popular Tags