All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgap.eval.PopulationHistoryIndexed Maven / Gradle / Ivy

/*
 * This file is part of JGAP.
 *
 * JGAP offers a dual license model containing the LGPL as well as the MPL.
 *
 * For licensing 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 org.jgap.eval;

import java.io.*;
import java.util.*;
import org.jgap.*;

/**
 * Manages populations. See class EvolutionMonitor for a description of events
 * and how populations are tracked.
 *
 * @author Klaus Meffert
 * @since 3.5
 */
public class PopulationHistoryIndexed
    implements Serializable {
  /** String containing the CVS revision. Read out via reflection!*/
  private final static String CVS_REVISION = "$Revision: 1.2 $";

  private Map m_evolutions;

  /**
   *
   * @author Klaus Meffert
   * @since 3.5
   */
  public PopulationHistoryIndexed() {
    m_evolutions = new HashMap();
  }

  /**
   *
   * @param a_index evolution number or any other appropriate index
   * @param a_event unique identifier of an event (if needed). See class
   * EvolutionMonitor for event constants
   * @param a_pop the population to add
   *
   * @author Klaus Meffert
   * @since 3.5
   */
  public void addPopulation(int a_index, int a_event, PopulationContext a_pop) {
    Map entry = m_evolutions.get(a_index);
    if (entry == null) {
      entry = new HashMap();
    }
    entry.put(a_event, a_pop);
    m_evolutions.put(a_index, entry);
  }

  /**
   *
   * @param a_index evolution number or any other appropriate index
   * @return Map with tuples 
   *
   * @author Klaus Meffert
   * @since 3.5
   */
  public Map getPopulations(int a_index) {
    return m_evolutions.get(a_index);
  }

  /**
   * @return complete population history
   *
   * @author Klaus Meffert
   * @since 3.5
   */
  public Map getPopulationsHistory() {
    return m_evolutions;
  }

  /**
   *
   * @param a_index evolution number or any other appropriate index
   * @param a_event unique identifier of an event (if needed). See class
   * EvolutionMonitor for event constants
   * @return the population together with its context
   *
   * @author Klaus Meffert
   * @since 3.5
   */
  public PopulationContext getPopulation(int a_index, int a_event) {
    Map entry = getPopulations(a_index);
    if (entry != null) {
      Iterator it = entry.keySet().iterator();
      while(it.hasNext()) {
        Integer key = it.next();
        if(key == a_event) {
          return entry.get(key);
        }
      }
      return null;
    }
    else {
      return null;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy