| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| EvolutionaryAlgorithmEvent |
|
| 1.0;1 |
| 1 | /* | |
| 2 | ||
| 3 | dsh-evolve Framework for evolutionary algorithms. | |
| 4 | Copyright (c) 2005-2013 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 | */ | |
| 37 | public final class EvolutionaryAlgorithmEvent<I> | |
| 38 | extends EventObject | |
| 39 | { | |
| 40 | /** Population of individuals. */ | |
| 41 | private Collection<I> population; | |
| 42 | ||
| 43 | /** Fitness scores. */ | |
| 44 | private WeightedMap<I> scores; | |
| 45 | ||
| 46 | /** Time (in number of generations), for exit events. */ | |
| 47 | private int time; | |
| 48 | ||
| 49 | /** Collection of recombined individuals, for recombined or mutated events. */ | |
| 50 | private Collection<I> recombined; | |
| 51 | ||
| 52 | /** Collection of mutated individuals, for mutated events. */ | |
| 53 | private Collection<I> mutated; | |
| 54 | ||
| 55 | /** Collection of selected individuals, for selected events. */ | |
| 56 | private Collection<I> selected; | |
| 57 | ||
| 58 | /** Individual, for fitness calculated events. */ | |
| 59 | private I individual; | |
| 60 | ||
| 61 | /** Score, for fitness calculated events. */ | |
| 62 | private Double score; | |
| 63 | ||
| 64 | ||
| 65 | /** | |
| 66 | * Create a new evolutionary algorithm event with the specified evolutionary | |
| 67 | * algorithm function as the source of this event. | |
| 68 | * | |
| 69 | * @param source source of this event | |
| 70 | */ | |
| 71 | private EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source) | |
| 72 | { | |
| 73 | 12 | super(source); |
| 74 | 12 | } |
| 75 | ||
| 76 | /** | |
| 77 | * Create a new evolutionary algorithm event with the specified parameters. | |
| 78 | * | |
| 79 | * @param source source of this event | |
| 80 | * @param population population of individuals, for exit events | |
| 81 | * @param scores fitness scores, for exit events | |
| 82 | * @param time time (in number of generations), for exit events | |
| 83 | */ | |
| 84 | public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source, | |
| 85 | final Collection<I> population, | |
| 86 | final WeightedMap<I> scores, | |
| 87 | final int time) | |
| 88 | { | |
| 89 | 4 | this(source); |
| 90 | 4 | this.population = population; |
| 91 | 4 | this.scores = scores; |
| 92 | 4 | this.time = time; |
| 93 | 4 | } |
| 94 | ||
| 95 | /** | |
| 96 | * Create a new evolutionary algorithm event with the specified parameters. | |
| 97 | * | |
| 98 | * @param source source of this event | |
| 99 | * @param population population of individuals, for recombined events | |
| 100 | * @param recombined collection of recombined individuals, for recombined or mutated events | |
| 101 | * @param mutated collection of mutated individuals, for mutated events | |
| 102 | */ | |
| 103 | public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source, | |
| 104 | final Collection<I> population, | |
| 105 | final Collection<I> recombined, | |
| 106 | final Collection<I> mutated) | |
| 107 | { | |
| 108 | 4 | this(source); |
| 109 | 4 | this.population = population; |
| 110 | 4 | this.recombined = recombined; |
| 111 | 4 | this.mutated = mutated; |
| 112 | 4 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Create a new evolutionary algorithm event with the specified parameters. | |
| 116 | * | |
| 117 | * @param source source of this event | |
| 118 | * @param individual individual, for fitness calculated events | |
| 119 | * @param score score, for fitness calculated events | |
| 120 | */ | |
| 121 | public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source, | |
| 122 | final I individual, | |
| 123 | final Double score) | |
| 124 | { | |
| 125 | 2 | this(source); |
| 126 | 2 | this.individual = individual; |
| 127 | 2 | this.score = score; |
| 128 | 2 | } |
| 129 | ||
| 130 | /** | |
| 131 | * Create a new evolutionary algorithm event with the specified parameters. | |
| 132 | * | |
| 133 | * @param source source of this event | |
| 134 | * @param population population of individuals, for selected events | |
| 135 | * @param selected collection of selected individuals, for selected events | |
| 136 | * @param scores fitness scores, for selected events | |
| 137 | */ | |
| 138 | public EvolutionaryAlgorithmEvent(final EvolutionaryAlgorithm<I> source, | |
| 139 | final Collection<I> population, | |
| 140 | final Collection<I> selected, | |
| 141 | final WeightedMap<I> scores) | |
| 142 | { | |
| 143 | 2 | this(source); |
| 144 | 2 | this.population = population; |
| 145 | 2 | this.selected = selected; |
| 146 | 2 | this.scores = scores; |
| 147 | 2 | } |
| 148 | ||
| 149 | ||
| 150 | /** | |
| 151 | * Return the source of this event as an evolutionary algorithm function. | |
| 152 | * | |
| 153 | * @return the source of this event as an evolutionary algorithm function | |
| 154 | */ | |
| 155 | public EvolutionaryAlgorithm<I> getEvolutionaryAlgorithm() | |
| 156 | { | |
| 157 | 5 | return (EvolutionaryAlgorithm<I>) super.getSource(); |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Return the population of individuals. May be null. | |
| 162 | * | |
| 163 | * @return the population of individuals | |
| 164 | */ | |
| 165 | public Collection<I> getPopulation() | |
| 166 | { | |
| 167 | 4 | return population; |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * Return the fitness scores. May be null. | |
| 172 | * | |
| 173 | * @return the fitness scores | |
| 174 | */ | |
| 175 | public WeightedMap<I> getScores() | |
| 176 | { | |
| 177 | 2 | return scores; |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Return the time (in number of generations), for exit events. Defaults to <code>0</code>. | |
| 182 | * | |
| 183 | * @return the time (in number of generations), for exit events | |
| 184 | */ | |
| 185 | public int getTime() | |
| 186 | { | |
| 187 | 1 | return time; |
| 188 | } | |
| 189 | ||
| 190 | /** | |
| 191 | * Return the collection of recombined individuals, for recombined or mutated events. May be null. | |
| 192 | * | |
| 193 | * @return the collection of recombined individuals, for recombined or mutated events | |
| 194 | */ | |
| 195 | public Collection<I> getRecombined() | |
| 196 | { | |
| 197 | 2 | return recombined; |
| 198 | } | |
| 199 | ||
| 200 | /** | |
| 201 | * Return the collection of mutated individuals, for mutated events. May be null. | |
| 202 | * | |
| 203 | * @return the collection of mutated individuals, for mutated events | |
| 204 | */ | |
| 205 | public Collection<I> getMutated() | |
| 206 | { | |
| 207 | 2 | return mutated; |
| 208 | } | |
| 209 | ||
| 210 | /** | |
| 211 | * Return the individual, for fitness calculated events. May be null. | |
| 212 | * | |
| 213 | * @return the individual, for fitness calculated events | |
| 214 | */ | |
| 215 | public I getIndividual() | |
| 216 | { | |
| 217 | 1 | return individual; |
| 218 | } | |
| 219 | ||
| 220 | /** | |
| 221 | * Return the score, for fitness calculated events. May be null. | |
| 222 | * | |
| 223 | * @return the score, for fitness calculated events | |
| 224 | */ | |
| 225 | public Double getScore() | |
| 226 | { | |
| 227 | 1 | return score; |
| 228 | } | |
| 229 | ||
| 230 | /** | |
| 231 | * Return the collection of selected individuals, for selected events. May be null. | |
| 232 | * | |
| 233 | * @return the collection of selected individuals, for selected events | |
| 234 | */ | |
| 235 | public Collection<I> getSelected() | |
| 236 | { | |
| 237 | 1 | return selected; |
| 238 | } | |
| 239 | } |