KickJava   Java API By Example, From Geeks To Geeks.

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


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 if-then construct.
18  *
19  * @author Klaus Meffert
20  * @since 3.0
21  */

22 public class If
23     extends CommandGene {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.4 $";
26
27   public If(final GPConfiguration a_conf, Class JavaDoc type)
28       throws InvalidConfigurationException {
29     super(a_conf, 2, type);
30   }
31
32   public String JavaDoc toString() {
33     return "if(&1) then (&2)";
34   }
35
36   public boolean execute_boolean(ProgramChromosome c, int n, Object JavaDoc[] args) {
37     boolean x = c.execute_boolean(n, 0, args);
38     boolean value = false;
39     if (x) {
40       value = c.execute_boolean(n, 1, args);
41     }
42     return value;
43   }
44
45   public int execute_int(ProgramChromosome c, int n, Object JavaDoc[] args) {
46     int x = c.execute_int(n, 0, args);
47     int value = 0;
48     if (x >= 0) {
49       value = c.execute_int(n, 1, args);
50     }
51     return value;
52   }
53
54   public long execute_long(ProgramChromosome c, int n, Object JavaDoc[] args) {
55     long x = c.execute_long(n, 0, args);
56     long value = 0;
57     if (x >= 0) {
58       value = c.execute_long(n, 1, args);
59     }
60     return value;
61   }
62
63   public float execute_float(ProgramChromosome c, int n, Object JavaDoc[] args) {
64     float x = c.execute_float(n, 0, args);
65     float value = 0;
66     if (x >= 0) {
67       value = c.execute_float(n, 1, args);
68     }
69     return value;
70   }
71
72   public double execute_double(ProgramChromosome c, int n, Object JavaDoc[] args) {
73     double x = c.execute_double(n, 0, args);
74     double value = 0;
75     if (x >= 0) {
76       value = c.execute_double(n, 1, args);
77     }
78     return value;
79   }
80
81   public void execute_void(ProgramChromosome c, int n, Object JavaDoc[] args) {
82     int x = c.execute_int(n, 0, args);/**@todo add option for type of first child to constructor*/
83     if (x >= 0) {
84       c.execute_void(n, 1, args);
85     }
86   }
87 }
88
Popular Tags