isowncolor.java

来自「jgap3.2 遗传算法工具包,嘿嘿,笨鸟先飞哦」· Java 代码 · 共 73 行

JAVA
73
字号
/*
 * This file is part of JGAP.
 *
 * JGAP offers a dual license model containing the LGPL as well as the MPL.
 *
 * For licencing information please see the file license.txt included with JGAP
 * or have a look at the top of class org.jgap.Chromosome which representatively
 * includes the JGAP license policy applicable for any file delivered with JGAP.
 */
package examples.gp.tictactoe;

import org.jgap.gp.*;
import org.jgap.*;
import org.jgap.gp.impl.*;
import org.jgap.util.*;

public class IsOwnColor
    extends CommandGene implements ICloneable {
  /** String containing the CVS revision. Read out via reflection!*/
  private final static String CVS_REVISION = "$Revision: 1.3 $";

  private int m_color;

  private int m_subChildType; // Only needed for cloning!

  public IsOwnColor(final GPConfiguration a_conf, int a_color)
      throws InvalidConfigurationException {
    this(a_conf, a_color, 0, 0);
  }

  public IsOwnColor(final GPConfiguration a_conf, int a_color,
                    int a_subReturnType, int a_subChildType)
      throws InvalidConfigurationException {
    super(a_conf, 1, CommandGene.BooleanClass, a_subReturnType, a_subChildType);
    m_subChildType = a_subChildType;
    m_color = a_color;
  }

  public String toString() {
    return "isOwnColor(&1)";
  }

  public boolean execute_boolean(ProgramChromosome c, int n, Object[] args) {
    check(c);
    int color = c.execute_int(n, 0, args);
    return color == m_color;
  }

  /**
   * @return textual name of this command
   *
   * @author Klaus Meffert
   * @since 3.2
   */
  public String getName() {
    return "If Color";
  }

  public Object clone() {
    try {
      IsOwnColor result = new IsOwnColor(getGPConfiguration(), m_color,
          getSubReturnType(), m_subChildType);
      return result;
    } catch (Throwable t) {
      throw new CloneException(t);
    }
  }

  public Class getChildType(IGPProgram a_ind, int a_chromNum) {
    return CommandGene.IntegerClass;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?