Coverage Report - org.dishevelled.evolve.EvolutionaryAlgorithmEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
EvolutionaryAlgorithmEvent
100%
30/30
N/A
1
 
 1  
 /*
 2  
 
 3  
     dsh-evolve  Framework for evolutionary algorithms.
 4  
     Copyright (c) 2005-2012 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.evolve;
 25  
 
 26  
 import java.util.Collection;
 27  
 import java.util.EventObject;
 28  
 
 29  
 import org.dishevelled.weighted.WeightedMap;
 30  
 
 31  
 /**
 32  
  * An event representing progress in an evolutionary algorithm function.
 33  
  *
 34  
  * @param <I> individual type
 35  
  * @author  Michael Heuer
 36  
  * @version $Revision: 1059 $ $Date: 2012-01-03 14:03:02 -0600 (Tue, 03 Jan 2012) $
 37  
  */
 38  
 public final class EvolutionaryAlgorithmEvent<I>
 39  
     extends EventObject
 40  
 {
 41  
     /** Population of individuals. */
 42  
     private Collection<I> population;
 43  
 
 44  
     /** Fitness scores. */
 45  
     private WeightedMap<I> scores;
 46  
 
 47  
     /** Time (in number of generations), for exit events. */
 48  
     private int time;
 49  
 
 50  
     /** Collection of recombined individuals, for recombined or mutated events. */
 51  
     private Collection<I> recombined;
 52  
 
 53  
     /** Collection of mutated individuals, for mutated events. */
 54  
     private Collection<I> mutated;
 55  
 
 56  
     /** Collection of selected individuals, for selected events. */
 57  
     private Collection<I> selected;
 58  
 
 59  
     /** Individual, for fitness calculated events. */
 60  
     private I individual;
 61  
 
 62  
     /** Score, for fitness calculated events. */
 63  
     private Double score;
 64  
 
 65  
 
 66  
     /**
 67  
      * Create a new evolutionary algorithm event with the specified evolutionary
 68  
      * algorithm function as the source of this event.
 69  
      *
 70  
      * @param source source of this event
 71  
      */
 72  
     private EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source)
 73  
     {
 74  12
         super(source);
 75  12
     }
 76  
 
 77  
     /**
 78  
      * Create a new evolutionary algorithm event with the specified parameters.
 79  
      *
 80  
      * @param source source of this event
 81  
      * @param population population of individuals, for exit events
 82  
      * @param scores fitness scores, for exit events
 83  
      * @param time time (in number of generations), for exit events
 84  
      */
 85  
     public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source,
 86  
                                       final Collection<I> population,
 87  
                                       final WeightedMap<I> scores,
 88  
                                       final int time)
 89  
     {
 90  4
         this(source);
 91  4
         this.population = population;
 92  4
         this.scores = scores;
 93  4
         this.time = time;
 94  4
     }
 95  
 
 96  
     /**
 97  
      * Create a new evolutionary algorithm event with the specified parameters.
 98  
      *
 99  
      * @param source source of this event
 100  
      * @param population population of individuals, for recombined events
 101  
      * @param recombined collection of recombined individuals, for recombined or mutated events
 102  
      * @param mutated collection of mutated individuals, for mutated events
 103  
      */
 104  
     public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source,
 105  
                                       final Collection<I> population,
 106  
                                       final Collection<I> recombined,
 107  
                                       final Collection<I> mutated)
 108  
     {
 109  4
         this(source);
 110  4
         this.population = population;
 111  4
         this.recombined = recombined;
 112  4
         this.mutated = mutated;
 113  4
     }
 114  
 
 115  
     /**
 116  
      * Create a new evolutionary algorithm event with the specified parameters.
 117  
      *
 118  
      * @param source source of this event
 119  
      * @param individual individual, for fitness calculated events
 120  
      * @param score score, for fitness calculated events
 121  
      */
 122  
     public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source,
 123  
                                       final I individual,
 124  
                                       final Double score)
 125  
     {
 126  2
         this(source);
 127  2
         this.individual = individual;
 128  2
         this.score = score;
 129  2
     }
 130  
 
 131  
     /**
 132  
      * Create a new evolutionary algorithm event with the specified parameters.
 133  
      *
 134  
      * @param source source of this event
 135  
      * @param population population of individuals, for selected events
 136  
      * @param selected collection of selected individuals, for selected events
 137  
      * @param scores fitness scores, for selected events
 138  
      */
 139  
     public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source,
 140  
                                       final Collection<I> population,
 141  
                                       final Collection<I> selected,
 142  
                                       final WeightedMap<I> scores)
 143  
     {
 144  2
         this(source);
 145  2
         this.population = population;
 146  2
         this.selected = selected;
 147  2
         this.scores = scores;
 148  2
     }
 149  
 
 150  
 
 151  
     /**
 152  
      * Return the source of this event as an evolutionary algorithm function.
 153  
      *
 154  
      * @return the source of this event as an evolutionary algorithm function
 155  
      */
 156  
     public EvolutionaryAlgorithm<I> getEvolutionaryAlgorithm()
 157  
     {
 158  5
         return (EvolutionaryAlgorithm<I>) super.getSource();
 159  
     }
 160  
 
 161  
     /**
 162  
      * Return the population of individuals.  May be null.
 163  
      *
 164  
      * @return the population of individuals
 165  
      */
 166  
     public Collection<I> getPopulation()
 167  
     {
 168  4
         return population;
 169  
     }
 170  
 
 171  
     /**
 172  
      * Return the fitness scores.  May be null.
 173  
      *
 174  
      * @return the fitness scores
 175  
      */
 176  
     public WeightedMap<I> getScores()
 177  
     {
 178  2
         return scores;
 179  
     }
 180  
 
 181  
     /**
 182  
      * Return the time (in number of generations), for exit events.  Defaults to <code>0</code>.
 183  
      *
 184  
      * @return the time (in number of generations), for exit events
 185  
      */
 186  
     public int getTime()
 187  
     {
 188  1
         return time;
 189  
     }
 190  
 
 191  
     /**
 192  
      * Return the collection of recombined individuals, for recombined or mutated events.  May be null.
 193  
      *
 194  
      * @return the collection of recombined individuals, for recombined or mutated events
 195  
      */
 196  
     public Collection<I> getRecombined()
 197  
     {
 198  2
         return recombined;
 199  
     }
 200  
 
 201  
     /**
 202  
      * Return the collection of mutated individuals, for mutated events.  May be null.
 203  
      *
 204  
      * @return the collection of mutated individuals, for mutated events
 205  
      */
 206  
     public Collection<I> getMutated()
 207  
     {
 208  2
         return mutated;
 209  
     }
 210  
 
 211  
     /**
 212  
      * Return the individual, for fitness calculated events.  May be null.
 213  
      *
 214  
      * @return the individual, for fitness calculated events
 215  
      */
 216  
     public I getIndividual()
 217  
     {
 218  1
         return individual;
 219  
     }
 220  
 
 221  
     /**
 222  
      * Return the score, for fitness calculated events.  May be null.
 223  
      *
 224  
      * @return the score, for fitness calculated events
 225  
      */
 226  
     public Double getScore()
 227  
     {
 228  1
         return score;
 229  
     }
 230  
 
 231  
     /**
 232  
      * Return the collection of selected individuals, for selected events.  May be null.
 233  
      *
 234  
      * @return the collection of selected individuals, for selected events
 235  
      */
 236  
     public Collection<I> getSelected()
 237  
     {
 238  1
         return selected;
 239  
     }
 240  
 }