⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testxml.java

📁 java实现的遗传算法
💻 JAVA
字号:
/*
 * 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.simpleBoolean;

import org.jgap.*;
import org.jgap.impl.*;
import org.jgap.xml.*;
import org.w3c.dom.*;

/**
 * Tests the XML capabilities of JGAP. Uses the simple boolean example for that.
 *
 * @author Neil Rotstan
 * @author Klaus Meffert
 * @since 2.0
 */
public class TestXML {

  /** String containing the CVS revision. Read out via reflection!*/
  private static final String CVS_REVISION = "$Revision: 1.4 $";

  public static void main(String[] args) {
    try {
      Configuration activeConfiguration = new DefaultConfiguration();

      activeConfiguration.setSampleChromosome(
          new Chromosome(new BooleanGene(), 8));
      activeConfiguration.setPopulationSize(10);
      activeConfiguration.setFitnessFunction(new MaxFunction());
      Genotype.setConfiguration(activeConfiguration);

      // Test Chromsome manipulation methods.
      // ------------------------------------
      Chromosome chromosome =
          Chromosome.randomInitialChromosome();

      Document chromosomeDoc =
          XMLManager.representChromosomeAsDocument(chromosome);

      Chromosome chromosomeFromXML =
          XMLManager.getChromosomeFromDocument(activeConfiguration,
                                               chromosomeDoc);

      if (! (chromosomeFromXML.equals(chromosome))) {
        System.out.println("Chromosome test failed.");
        System.exit( -1);
      }

      // Test Genotype manipulation methods.
      // -----------------------------------
      Genotype genotype =
          Genotype.randomInitialGenotype(activeConfiguration);

      Document genotypeDoc =
          XMLManager.representGenotypeAsDocument(genotype);

      Genotype genotypeFromXML =
          XMLManager.getGenotypeFromDocument(activeConfiguration, genotypeDoc);

      if (! (genotypeFromXML.equals(genotype))) {
        System.out.println("Genotype test failed.");
        System.exit( -1);
      }
    }
    catch (Exception e) {
      System.out.println("Test failed due to error:");
      e.printStackTrace();
    }

    System.out.println("Tests successful.");
  }
}

⌨️ 快捷键说明

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