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 org.jgap.impl;
11:
12: import java.io.*;
13: import java.util.*;
14:
15: import org.jgap.*;
16: import org.jgap.util.*;
17:
18: /**
19: * The stock random generator uses the java.util.Random class to
20: * provide a simple implementation of the RandomGenerator interface.
21: * No actual code is provided here.
22: *
23: * @author Neil Rotstan
24: * @author Klaus Meffert
25: * @since 1.0
26: */
27: public class StockRandomGenerator extends Random implements
28: RandomGenerator, ICloneable, Comparable {
29: /** String containing the CVS revision. Read out via reflection!*/
30: private final static String CVS_REVISION = "$Revision: 1.8 $";
31:
32: /**
33: * When deserializing, initialize the seed because otherwise we could get
34: * duplicate evolution results when doing distributed computing!
35: *
36: * @param a_inputStream the ObjectInputStream provided for deserialzation
37: *
38: * @throws IOException
39: * @throws ClassNotFoundException
40: *
41: * @author Klaus Meffert
42: * @since 3.01
43: */
44: private void readObject(ObjectInputStream a_inputStream)
45: throws IOException, ClassNotFoundException {
46: //always perform the default de-serialization first
47: a_inputStream.defaultReadObject();
48: setSeed(System.currentTimeMillis());
49: }
50:
51: /**
52: * @return deep clone of this instance
53: *
54: * @author Klaus Meffert
55: * @since 3.2
56: */
57: public Object clone() {
58: StockRandomGenerator result = new StockRandomGenerator();
59: result.setSeed(System.currentTimeMillis());
60: return result;
61: }
62:
63: /**
64: * @param a_other sic
65: * @return as always
66: *
67: * @author Klaus Meffert
68: * @since 3.2
69: */
70: public int compareTo(Object a_other) {
71: if (a_other.getClass().equals(getClass())) {
72: return 0;
73: } else {
74: return getClass().getName().compareTo(
75: a_other.getClass().getName());
76: }
77: }
78: }
|