KickJava   Java API By Example, From Geeks To Geeks.

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


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 boolean or operation.
18  *
19  * @author Klaus Meffert
20  * @since 3.0
21  */

22 public class Or
23     extends MathCommand implements IMutateable {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.6 $";
26
27   public Or(final GPConfiguration a_conf)
28       throws InvalidConfigurationException {
29     super(a_conf, 2, CommandGene.BooleanClass);
30   }
31
32   public CommandGene applyMutation(int index, double a_percentage)
33       throws InvalidConfigurationException {
34     CommandGene mutant;
35     if (a_percentage < 0.5d) {
36       mutant = new Xor(getGPConfiguration());
37     }
38     else {
39       mutant = new And(getGPConfiguration());
40     }
41     return mutant;
42   }
43
44   public String JavaDoc toString() {
45     return "&1 || &2";
46   }
47
48   /**
49    * @return textual name of this command
50    *
51    * @author Klaus Meffert
52    * @since 3.2
53    */

54   public String JavaDoc getName() {
55     return "Or";
56   }
57
58   public boolean execute_boolean(ProgramChromosome c, int n, Object JavaDoc[] args) {
59     if (c.execute_boolean(n, 0, args)) {
60       return true;
61     }
62     if (c.execute_boolean(n, 1, args)) {
63       return true;
64     }
65     return false;
66   }
67 }
68
Popular Tags