1 10 package org.jgap.eval; 11 12 import java.util.*; 13 import org.jgap.*; 14 15 22 public class PopulationHistory { 23 24 private final static String CVS_REVISION = "$Revision: 1.4 $"; 25 26 private List m_populations; 27 28 private int m_maxSize; 29 30 37 public PopulationHistory(final int a_maxSize) { 38 m_populations = new Vector(); 39 if (a_maxSize < 0) { 40 throw new IllegalArgumentException ("Maximum size must be greater" 41 + " or equal to zero!"); 42 } 43 m_maxSize = a_maxSize; 44 } 45 46 public Population getPopulation(final int a_count) { 47 if (a_count >= m_populations.size()) { 48 return null; 49 } 50 else { 51 return (Population) m_populations.get(a_count); 52 } 53 } 54 55 63 public void addPopulation(final Population a_population) { 64 m_populations.add(0, a_population); 65 int popSize = m_populations.size(); 66 if (m_maxSize != 0 && popSize > m_maxSize) { 67 m_populations.remove(popSize - 1); 68 } 69 } 70 71 75 public void removeAllPopulations() { 76 m_populations.removeAll(m_populations); 77 } 78 79 public int size() { 80 return m_populations.size(); 81 } 82 83 public List getPopulations() { 84 return m_populations; 85 } 86 87 94 public void setPopulations(final List a_populations) { 95 m_populations = a_populations; 96 int popSize = m_populations.size(); 97 if (m_maxSize != 0 && popSize > m_maxSize) { 98 for (int i = m_maxSize; i < popSize; i++) { 99 m_populations.remove(m_maxSize); 100 } 101 } 102 } 103 } 104 | Popular Tags |