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.gp.function;
11:
12: import org.jgap.*;
13: import org.jgap.gp.*;
14: import org.jgap.gp.impl.*;
15:
16: /**
17: * The exponential operation.
18: *
19: * @author Klaus Meffert
20: * @since 3.0
21: */
22: public class Exp extends MathCommand {
23: /** String containing the CVS revision. Read out via reflection!*/
24: private final static String CVS_REVISION = "$Revision: 1.7 $";
25:
26: public Exp(final GPConfiguration a_conf, Class a_type)
27: throws InvalidConfigurationException {
28: super (a_conf, 1, a_type);
29: }
30:
31: public String toString() {
32: return "Exp(&1)";
33: }
34:
35: /**
36: * @return textual name of this command
37: *
38: * @author Klaus Meffert
39: * @since 3.2
40: */
41: public String getName() {
42: return "Exp";
43: }
44:
45: public int execute_int(ProgramChromosome c, int n, Object[] args) {
46: int i = c.execute_int(n, 0, args);
47: // clip to -10000 -> 20
48: return (int) Math.exp(Math.max(-10000.0f, Math.min(i, 20.0f)));
49: }
50:
51: public float execute_float(ProgramChromosome c, int n, Object[] args) {
52: float f = c.execute_float(n, 0, args);
53: // clip to -10000 -> 20
54: return (float) Math
55: .exp(Math.max(-10000.0f, Math.min(f, 20.0f)));
56: }
57:
58: public double execute_double(ProgramChromosome c, int n,
59: Object[] args) {
60: double f = c.execute_double(n, 0, args);
61: // clip to -10000 -> 20
62: return Math.exp(Math.max(-10000.0, Math.min(f, 20.0)));
63: }
64:
65: public Object execute_object(ProgramChromosome c, int n,
66: Object[] args) {
67: return ((Compatible) c.execute_object(n, 0, args))
68: .execute_exp();
69: }
70:
71: protected interface Compatible {
72: public Object execute_exp();
73: }
74: }
|