KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > gp > function > Add3


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 org.jgap.gp.function;
11
12 import org.jgap.*;
13 import org.jgap.gp.*;
14 import org.jgap.gp.impl.*;
15
16 /**
17  * The add operation with three parameters (X + Y + Z).
18  *
19  * @author Klaus Meffert
20  * @since 3.0
21  */

22 public class Add3
23     extends MathCommand {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.5 $";
26
27   public Add3(final GPConfiguration a_conf, Class JavaDoc type)
28       throws InvalidConfigurationException {
29     super(a_conf, 3, type);
30   }
31
32   public String JavaDoc toString() {
33     return "&1 + &2 + &3";
34   }
35
36   /**
37    * @return textual name of this command
38    *
39    * @author Klaus Meffert
40    * @since 3.2
41    */

42   public String JavaDoc getName() {
43     return "Add3";
44   }
45
46   public int execute_int(ProgramChromosome c, int n, Object JavaDoc[] args) {
47     return c.execute_int(n, 0, args) + c.execute_int(n, 1, args) +
48         c.execute_int(n, 2, args);
49   }
50
51   public long execute_long(ProgramChromosome c, int n, Object JavaDoc[] args) {
52     return c.execute_long(n, 0, args) + c.execute_long(n, 1, args) +
53         c.execute_long(n, 2, args);
54   }
55
56   public float execute_float(ProgramChromosome c, int n, Object JavaDoc[] args) {
57     return c.execute_float(n, 0, args) + c.execute_float(n, 1, args) +
58         c.execute_float(n, 2, args);
59   }
60
61   public double execute_double(ProgramChromosome c, int n, Object JavaDoc[] args) {
62     return c.execute_double(n, 0, args) + c.execute_double(n, 1, args) +
63         c.execute_double(n, 2, args);
64   }
65
66   public Object JavaDoc execute_object(ProgramChromosome c, int n, Object JavaDoc[] args) {
67     return ( (Compatible) ( (Compatible) c.execute_object(n, 0, args)).
68             execute_add3(c.execute_object(n, 1, args))).execute_add3(
69                 c.execute_object(n, 2, args));
70   }
71
72   protected interface Compatible {
73     public Object JavaDoc execute_add3(Object JavaDoc o);
74   }
75 }
76
Popular Tags