コード例 #1
0
 /**
  * Marshall a Genotype instance into an XML Element representation, including its population of
  * Chromosome instances as sub-elements. This may be useful in scenarios where representation as
  * an entire Document is undesirable, such as when the representation of this Genotype is to be
  * combined with other elements in a single Document.
  *
  * @param a_subject the genotype to represent as an XML element
  * @param a_xmlDocument a Document instance that will be used to create the Element instance. Note
  *     that the element will NOT be added to the document by this method
  * @return an Element object representing the given Genotype
  * @author Neil Rotstan
  * @since 1.0
  * @deprecated use XMLDocumentBuilder instead
  */
 public static Element representGenotypeAsElement(
     final Genotype a_subject, final Document a_xmlDocument) {
   Population population = a_subject.getPopulation();
   // Start by creating the genotype element and its size attribute,
   // which represents the number of chromosomes present in the
   // genotype.
   // --------------------------------------------------------------
   Element genotypeTag = a_xmlDocument.createElement(GENOTYPE_TAG);
   genotypeTag.setAttribute(SIZE_ATTRIBUTE, Integer.toString(population.size()));
   // Next, add nested elements for each of the chromosomes in the
   // genotype.
   // ------------------------------------------------------------
   for (int i = 0; i < population.size(); i++) {
     Element chromosomeElement =
         representChromosomeAsElement(population.getChromosome(i), a_xmlDocument);
     genotypeTag.appendChild(chromosomeElement);
   }
   return genotypeTag;
 }
コード例 #2
0
  public boolean needsToRun(Run run, int generation) {
    Population pop = getPopulationFor(run, generation);
    int count = run.getIntProperty(GenetikConstants.POPULATION, Integer.MAX_VALUE, true);
    int scoreCount = 0;

    for (int i = 0, max = pop.size(); i < max; i++) {
      Individual ind = pop.get(i);

      if (ind.hasFitness() && ind.hasScores()) {
        scoreCount++;
      }
    }

    return scoreCount != count;
  }