commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1385297 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/
Date Sun, 16 Sep 2012 16:05:58 GMT
Author: tn
Date: Sun Sep 16 16:05:57 2012
New Revision: 1385297

URL: http://svn.apache.org/viewvc?rev=1385297&view=rev
Log:
[MATH-854] fill throws clause for genetics package.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryChromosome.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryMutation.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CrossoverPolicy.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CycleCrossover.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedElapsedTime.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedGenerationCount.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/GeneticAlgorithm.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/MutationPolicy.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/NPointCrossover.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OrderedCrossover.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/Population.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKey.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKeyMutation.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/SelectionPolicy.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/TournamentSelection.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/UniformCrossover.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/AbstractListChromosome.java
Sun Sep 16 16:05:57 2012
@@ -38,7 +38,7 @@ public abstract class AbstractListChromo
      * @param representation inner representation of the chromosome
      * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public AbstractListChromosome(final List<T> representation) {
+    public AbstractListChromosome(final List<T> representation) throws InvalidRepresentationException
{
         checkValidity(representation);
         this.representation = Collections.unmodifiableList(new ArrayList<T> (representation));
     }
@@ -46,8 +46,9 @@ public abstract class AbstractListChromo
     /**
      * Constructor.
      * @param representation inner representation of the chromosome
+     * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public AbstractListChromosome(final T[] representation) {
+    public AbstractListChromosome(final T[] representation) throws InvalidRepresentationException
{
         this(Arrays.asList(representation));
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryChromosome.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryChromosome.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryChromosome.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryChromosome.java
Sun Sep 16 16:05:57 2012
@@ -34,7 +34,7 @@ public abstract class BinaryChromosome e
      * @param representation list of {0,1} values representing the chromosome
      * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public BinaryChromosome(List<Integer> representation) {
+    public BinaryChromosome(List<Integer> representation) throws InvalidRepresentationException
{
         super(representation);
     }
 
@@ -43,7 +43,7 @@ public abstract class BinaryChromosome e
      * @param representation array of {0,1} values representing the chromosome
      * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public BinaryChromosome(Integer[] representation) {
+    public BinaryChromosome(Integer[] representation) throws InvalidRepresentationException
{
         super(representation);
     }
 
@@ -51,8 +51,7 @@ public abstract class BinaryChromosome e
      * {@inheritDoc}
      */
     @Override
-    protected void checkValidity(List<Integer> chromosomeRepresentation)
-        throws InvalidRepresentationException {
+    protected void checkValidity(List<Integer> chromosomeRepresentation) throws InvalidRepresentationException
{
         for (int i : chromosomeRepresentation) {
             if (i < 0 || i >1) {
                 throw new InvalidRepresentationException(LocalizedFormats.INVALID_BINARY_DIGIT,
@@ -75,9 +74,6 @@ public abstract class BinaryChromosome e
         return rList;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected boolean isSame(Chromosome another) {
         // type check

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryMutation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryMutation.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryMutation.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/BinaryMutation.java
Sun Sep 16 16:05:57 2012
@@ -37,7 +37,7 @@ public class BinaryMutation implements M
      * @return the mutated chromosome.
      * @throws MathIllegalArgumentException if <code>original</code> is not an
instance of {@link BinaryChromosome}.
      */
-    public Chromosome mutate(Chromosome original) {
+    public Chromosome mutate(Chromosome original) throws MathIllegalArgumentException {
         if (!(original instanceof BinaryChromosome)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_BINARY_CHROMOSOME);
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CrossoverPolicy.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CrossoverPolicy.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CrossoverPolicy.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CrossoverPolicy.java
Sun Sep 16 16:05:57 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.genetics;
 
+import org.apache.commons.math3.exception.MathIllegalArgumentException;
+
 /**
  * Policy used to create a pair of new chromosomes by performing a crossover
  * operation on a source pair of chromosomes.
@@ -31,6 +33,7 @@ public interface CrossoverPolicy {
      * @param first the first chromosome.
      * @param second the second chromosome.
      * @return the pair of new chromosomes that resulted from the crossover.
+     * @throws MathIllegalArgumentException if the given chromosomes are not compatible with
this {@link CrossoverPolicy}
      */
-    ChromosomePair crossover(Chromosome first, Chromosome second);
+    ChromosomePair crossover(Chromosome first, Chromosome second) throws MathIllegalArgumentException;
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CycleCrossover.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CycleCrossover.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CycleCrossover.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/CycleCrossover.java
Sun Sep 16 16:05:57 2012
@@ -95,9 +95,14 @@ public class CycleCrossover<T> implement
 
     /**
      * {@inheritDoc}
+     *
+     * @throws MathIllegalArgumentException if the chromosomes are not an instance of {@link
AbstractListChromosome}
+     * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     @SuppressWarnings("unchecked")
-    public ChromosomePair crossover(final Chromosome first, final Chromosome second) {
+    public ChromosomePair crossover(final Chromosome first, final Chromosome second)
+        throws DimensionMismatchException, MathIllegalArgumentException {
+
         if (!(first instanceof AbstractListChromosome<?> && second instanceof
AbstractListChromosome<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
         }
@@ -112,7 +117,9 @@ public class CycleCrossover<T> implement
      * @return the pair of new chromosomes that resulted from the crossover
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
-    protected ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T>
second) {
+    protected ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T>
second)
+        throws DimensionMismatchException {
+
         final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ElitisticListPopulation.java
Sun Sep 16 16:05:57 2012
@@ -19,6 +19,9 @@ package org.apache.commons.math3.genetic
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.math3.exception.NotPositiveException;
+import org.apache.commons.math3.exception.NullArgumentException;
+import org.apache.commons.math3.exception.NumberIsTooLargeException;
 import org.apache.commons.math3.exception.OutOfRangeException;
 import org.apache.commons.math3.exception.util.LocalizedFormats;
 import org.apache.commons.math3.util.FastMath;
@@ -41,13 +44,18 @@ public class ElitisticListPopulation ext
      * @param chromosomes list of chromosomes in the population
      * @param populationLimit maximal size of the population
      * @param elitismRate how many best chromosomes will be directly transferred to the next
generation [in %]
+     * @throws NullArgumentException if the list of chromosomes is {@code null}
+     * @throws NotPositiveException if the population limit is not a positive number (&lt;
1)
+     * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population
limit
      * @throws OutOfRangeException if the elitism rate is outside the [0, 1] range
      */
-    public ElitisticListPopulation(final List<Chromosome> chromosomes,
-                                   final int populationLimit,
-                                   final double elitismRate) {
+    public ElitisticListPopulation(final List<Chromosome> chromosomes, final int populationLimit,
+                                   final double elitismRate)
+        throws NullArgumentException, NotPositiveException, NumberIsTooLargeException, OutOfRangeException
{
+
         super(chromosomes, populationLimit);
         setElitismRate(elitismRate);
+
     }
 
     /**
@@ -55,11 +63,15 @@ public class ElitisticListPopulation ext
      *
      * @param populationLimit maximal size of the population
      * @param elitismRate how many best chromosomes will be directly transferred to the next
generation [in %]
+     * @throws NotPositiveException if the population limit is not a positive number (&lt;
1)
      * @throws OutOfRangeException if the elitism rate is outside the [0, 1] range
      */
-    public ElitisticListPopulation(final int populationLimit, final double elitismRate) {
+    public ElitisticListPopulation(final int populationLimit, final double elitismRate)
+        throws NotPositiveException, OutOfRangeException {
+
         super(populationLimit);
         setElitismRate(elitismRate);
+
     }
 
     /**
@@ -90,7 +102,7 @@ public class ElitisticListPopulation ext
      * @param elitismRate how many best chromosomes will be directly transferred to the next
generation [in %]
      * @throws OutOfRangeException if the elitism rate is outside the [0, 1] range
      */
-    public void setElitismRate(final double elitismRate) {
+    public void setElitismRate(final double elitismRate) throws OutOfRangeException {
         if (elitismRate < 0 || elitismRate > 1) {
             throw new OutOfRangeException(LocalizedFormats.ELITISM_RATE, elitismRate, 0,
1);
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedElapsedTime.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedElapsedTime.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedElapsedTime.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedElapsedTime.java
Sun Sep 16 16:05:57 2012
@@ -43,7 +43,7 @@ public class FixedElapsedTime implements
      * @param maxTime maximum number of seconds generations are allowed to evolve
      * @throws NumberIsTooSmallException if the provided time is &lt; 0
      */
-    public FixedElapsedTime(final long maxTime) {
+    public FixedElapsedTime(final long maxTime) throws NumberIsTooSmallException {
         this(maxTime, TimeUnit.SECONDS);
     }
 
@@ -54,7 +54,7 @@ public class FixedElapsedTime implements
      * @param unit {@link TimeUnit} of the maxTime argument
      * @throws NumberIsTooSmallException if the provided time is &lt; 0
      */
-    public FixedElapsedTime(final long maxTime, final TimeUnit unit) {
+    public FixedElapsedTime(final long maxTime, final TimeUnit unit) throws NumberIsTooSmallException
{
         if (maxTime < 0) {
             throw new NumberIsTooSmallException(maxTime, 0, true);
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedGenerationCount.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedGenerationCount.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedGenerationCount.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/FixedGenerationCount.java
Sun Sep 16 16:05:57 2012
@@ -39,7 +39,7 @@ public class FixedGenerationCount implem
      * @param maxGenerations number of generations to evolve
      * @throws NumberIsTooSmallException if the number of generations is &lt; 1
      */
-    public FixedGenerationCount(final int maxGenerations) {
+    public FixedGenerationCount(final int maxGenerations) throws NumberIsTooSmallException
{
         if (maxGenerations <= 0) {
             throw new NumberIsTooSmallException(maxGenerations, 1, true);
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/GeneticAlgorithm.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/GeneticAlgorithm.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/GeneticAlgorithm.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/GeneticAlgorithm.java
Sun Sep 16 16:05:57 2012
@@ -69,7 +69,7 @@ public class GeneticAlgorithm {
                             final double crossoverRate,
                             final MutationPolicy mutationPolicy,
                             final double mutationRate,
-                            final SelectionPolicy selectionPolicy) {
+                            final SelectionPolicy selectionPolicy) throws OutOfRangeException
{
 
         if (crossoverRate < 0 || crossoverRate > 1) {
             throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE,

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/ListPopulation.java
Sun Sep 16 16:05:57 2012
@@ -48,7 +48,7 @@ public abstract class ListPopulation imp
      * @param populationLimit maximal size of the population
      * @throws NotPositiveException if the population limit is not a positive number (&lt;
1)
      */
-    public ListPopulation(final int populationLimit) {
+    public ListPopulation(final int populationLimit) throws NotPositiveException {
         this(Collections.<Chromosome> emptyList(), populationLimit);
     }
 
@@ -63,7 +63,9 @@ public abstract class ListPopulation imp
      * @throws NotPositiveException if the population limit is not a positive number (&lt;
1)
      * @throws NumberIsTooLargeException if the list of chromosomes exceeds the population
limit
      */
-    public ListPopulation(final List<Chromosome> chromosomes, final int populationLimit)
{
+    public ListPopulation(final List<Chromosome> chromosomes, final int populationLimit)
+        throws NullArgumentException, NotPositiveException, NumberIsTooLargeException {
+
         if (chromosomes == null) {
             throw new NullArgumentException();
         }
@@ -91,7 +93,9 @@ public abstract class ListPopulation imp
      * @deprecated use {@link #addChromosomes(Collection)} instead
      */
     @Deprecated
-    public void setChromosomes(final List<Chromosome> chromosomes) {
+    public void setChromosomes(final List<Chromosome> chromosomes)
+        throws NullArgumentException, NumberIsTooLargeException {
+
         if (chromosomes == null) {
             throw new NullArgumentException();
         }
@@ -107,9 +111,9 @@ public abstract class ListPopulation imp
      * Add a {@link Collection} of chromosomes to this {@link Population}.
      * @param chromosomeColl a {@link Collection} of chromosomes
      * @throws NumberIsTooLargeException if the population would exceed the population limit
when
-     * adding this chromosome
+     *   adding this chromosome
      */
-    public void addChromosomes(final Collection<Chromosome> chromosomeColl) {
+    public void addChromosomes(final Collection<Chromosome> chromosomeColl) throws
NumberIsTooLargeException {
         if (chromosomes.size() + chromosomeColl.size() > populationLimit) {
             throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                                 chromosomes.size(), populationLimit, false);
@@ -140,7 +144,7 @@ public abstract class ListPopulation imp
      * @throws NumberIsTooLargeException if the population would exceed the {@code populationLimit}
after
      *   adding this chromosome
      */
-    public void addChromosome(final Chromosome chromosome) {
+    public void addChromosome(final Chromosome chromosome) throws NumberIsTooLargeException
{
         if (chromosomes.size() >= populationLimit) {
             throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE,
                                                 chromosomes.size(), populationLimit, false);
@@ -179,7 +183,7 @@ public abstract class ListPopulation imp
      * @throws NumberIsTooSmallException if the new population size is smaller than the current
number
      *   of chromosomes in the population
      */
-    public void setPopulationLimit(final int populationLimit) {
+    public void setPopulationLimit(final int populationLimit) throws NotPositiveException,
NumberIsTooSmallException {
         if (populationLimit <= 0) {
             throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE,
populationLimit);
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/MutationPolicy.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/MutationPolicy.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/MutationPolicy.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/MutationPolicy.java
Sun Sep 16 16:05:57 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.genetics;
 
+import org.apache.commons.math3.exception.MathIllegalArgumentException;
+
 /**
  * Algorithm used to mutate a chromosome.
  *
@@ -28,6 +30,7 @@ public interface MutationPolicy {
      * Mutate the given chromosome.
      * @param original the original chromosome.
      * @return the mutated chromosome.
+     * @throws MathIllegalArgumentException if the given chromosome is not compatible with
this {@link MutationPolicy}
      */
-    Chromosome mutate(Chromosome original);
+    Chromosome mutate(Chromosome original) throws MathIllegalArgumentException;
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/NPointCrossover.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/NPointCrossover.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/NPointCrossover.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/NPointCrossover.java
Sun Sep 16 16:05:57 2012
@@ -64,7 +64,7 @@ public class NPointCrossover<T> implemen
      * @param crossoverPoints the number of crossover points
      * @throws NotStrictlyPositiveException if the number of {@code crossoverPoints} is not
strictly positive
      */
-    public NPointCrossover(final int crossoverPoints) {
+    public NPointCrossover(final int crossoverPoints) throws NotStrictlyPositiveException
{
         if (crossoverPoints <= 0) {
             throw new NotStrictlyPositiveException(crossoverPoints);
         }
@@ -105,7 +105,9 @@ public class NPointCrossover<T> implemen
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     @SuppressWarnings("unchecked") // OK because of instanceof checks
-    public ChromosomePair crossover(final Chromosome first, final Chromosome second) {
+    public ChromosomePair crossover(final Chromosome first, final Chromosome second)
+        throws DimensionMismatchException, MathIllegalArgumentException {
+
         if (!(first instanceof AbstractListChromosome<?> && second instanceof
AbstractListChromosome<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
         }
@@ -122,7 +124,9 @@ public class NPointCrossover<T> implemen
      * @throws NumberIsTooLargeException if the number of crossoverPoints is too large for
the actual chromosomes
      */
     private ChromosomePair mate(final AbstractListChromosome<T> first,
-                                final AbstractListChromosome<T> second) {
+                                final AbstractListChromosome<T> second)
+        throws DimensionMismatchException, NumberIsTooLargeException {
+
         final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OnePointCrossover.java
Sun Sep 16 16:05:57 2012
@@ -76,7 +76,9 @@ public class OnePointCrossover<T> implem
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     @SuppressWarnings("unchecked") // OK because of instanceof checks
-    public ChromosomePair crossover(final Chromosome first, final Chromosome second) {
+    public ChromosomePair crossover(final Chromosome first, final Chromosome second)
+        throws DimensionMismatchException, MathIllegalArgumentException {
+
         if (! (first instanceof AbstractListChromosome<?> && second instanceof
AbstractListChromosome<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
         }
@@ -93,7 +95,7 @@ public class OnePointCrossover<T> implem
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     private ChromosomePair crossover(final AbstractListChromosome<T> first,
-                                     final AbstractListChromosome<T> second) {
+                                     final AbstractListChromosome<T> second) throws
DimensionMismatchException {
         final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OrderedCrossover.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OrderedCrossover.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OrderedCrossover.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/OrderedCrossover.java
Sun Sep 16 16:05:57 2012
@@ -62,9 +62,15 @@ public class OrderedCrossover<T> impleme
 
     /**
      * {@inheritDoc}
+     *
+     * @throws MathIllegalArgumentException iff one of the chromosomes is
+     *   not an instance of {@link AbstractListChromosome}
+     * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     @SuppressWarnings("unchecked")
-    public ChromosomePair crossover(final Chromosome first, final Chromosome second) {
+    public ChromosomePair crossover(final Chromosome first, final Chromosome second)
+        throws DimensionMismatchException, MathIllegalArgumentException {
+
         if (!(first instanceof AbstractListChromosome<?> && second instanceof
AbstractListChromosome<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
         }
@@ -79,7 +85,9 @@ public class OrderedCrossover<T> impleme
      * @return the pair of new chromosomes that resulted from the crossover
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
-    protected ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T>
second) {
+    protected ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T>
second)
+        throws DimensionMismatchException {
+
         final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/Population.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/Population.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/Population.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/Population.java
Sun Sep 16 16:05:57 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.genetics;
 
+import org.apache.commons.math3.exception.NumberIsTooLargeException;
+
 
 /**
  * A collection of chromosomes that facilitates generational evolution.
@@ -45,10 +47,10 @@ public interface Population extends Iter
     /**
      * Add the given chromosome to the population.
      * @param chromosome the chromosome to add.
-     * @throws org.apache.commons.math3.exception.NumberIsTooLargeException if the population
would exceed
-     *   the population limit when adding this chromosome
+     * @throws NumberIsTooLargeException if the population would exceed the population limit
when adding
+     *   this chromosome
      */
-    void addChromosome(Chromosome chromosome);
+    void addChromosome(Chromosome chromosome) throws NumberIsTooLargeException;
 
     /**
      * Access the fittest chromosome in this population.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKey.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKey.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKey.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKey.java
Sun Sep 16 16:05:57 2012
@@ -68,10 +68,9 @@ public abstract class RandomKey<T> exten
      * Constructor.
      *
      * @param representation list of [0,1] values representing the permutation
-     * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent
-     *   a valid chromosome
+     * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public RandomKey(final List<Double> representation) {
+    public RandomKey(final List<Double> representation) throws InvalidRepresentationException
{
         super(representation);
         // store the sorted representation
         List<Double> sortedRepr = new ArrayList<Double> (getRepresentation());
@@ -87,8 +86,9 @@ public abstract class RandomKey<T> exten
      * Constructor.
      *
      * @param representation array of [0,1] values representing the permutation
+     * @throws InvalidRepresentationException iff the <code>representation</code>
can not represent a valid chromosome
      */
-    public RandomKey(final Double[] representation) {
+    public RandomKey(final Double[] representation) throws InvalidRepresentationException
{
         this(Arrays.asList(representation));
     }
 
@@ -112,7 +112,9 @@ public abstract class RandomKey<T> exten
      *   <code>representation</code> or <code>sortedRepr</code> lists
are not equal
      */
     private static <S> List<S> decodeGeneric(final List<S> sequence, List<Double>
representation,
-                                             final List<Double> sortedRepr) {
+                                             final List<Double> sortedRepr)
+        throws DimensionMismatchException {
+
         int l = sequence.size();
 
         // the size of the three lists must be equal
@@ -230,7 +232,7 @@ public abstract class RandomKey<T> exten
      */
     public static <S> List<Double> comparatorPermutation(final List<S>
data,
                                                          final Comparator<S> comparator)
{
-        List<S> sortedData = new ArrayList<S> (data);
+        List<S> sortedData = new ArrayList<S>(data);
         Collections.sort(sortedData, comparator);
 
         return inducedPermutation(data, sortedData);
@@ -254,7 +256,8 @@ public abstract class RandomKey<T> exten
      *   <code>originalData</code> lists contain different data
      */
     public static <S> List<Double> inducedPermutation(final List<S> originalData,
-                                                      final List<S> permutedData) {
+                                                      final List<S> permutedData)
+        throws DimensionMismatchException, MathIllegalArgumentException {
 
         if (originalData.size() != permutedData.size()) {
             throw new DimensionMismatchException(permutedData.size(), originalData.size());

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKeyMutation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKeyMutation.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKeyMutation.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/RandomKeyMutation.java
Sun Sep 16 16:05:57 2012
@@ -36,7 +36,7 @@ public class RandomKeyMutation implement
      *
      * @throws MathIllegalArgumentException if <code>original</code> is not a
{@link RandomKey} instance
      */
-    public Chromosome mutate(final Chromosome original) {
+    public Chromosome mutate(final Chromosome original) throws MathIllegalArgumentException
{
         if (!(original instanceof RandomKey<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.RANDOMKEY_MUTATION_WRONG_CLASS,
                                                    original.getClass().getSimpleName());

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/SelectionPolicy.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/SelectionPolicy.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/SelectionPolicy.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/SelectionPolicy.java
Sun Sep 16 16:05:57 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math3.genetics;
 
+import org.apache.commons.math3.exception.MathIllegalArgumentException;
+
 /**
  * Algorithm used to select a chromosome pair from a population.
  *
@@ -27,6 +29,7 @@ public interface SelectionPolicy {
      * Select two chromosomes from the population.
      * @param population the population from which the chromosomes are choosen.
      * @return the selected chromosomes.
+     * @throws MathIllegalArgumentException if the population is not compatible with this
{@link SelectionPolicy}
      */
-    ChromosomePair select(Population population);
+    ChromosomePair select(Population population) throws MathIllegalArgumentException;
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/TournamentSelection.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/TournamentSelection.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/TournamentSelection.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/TournamentSelection.java
Sun Sep 16 16:05:57 2012
@@ -53,8 +53,9 @@ public class TournamentSelection impleme
      *
      * @param population the population from which the chromosomes are chosen.
      * @return the selected chromosomes.
+     * @throws MathIllegalArgumentException if the tournament arity is bigger than the population
size
      */
-    public ChromosomePair select(final Population population) {
+    public ChromosomePair select(final Population population) throws MathIllegalArgumentException
{
         return new ChromosomePair(tournament((ListPopulation) population),
                                   tournament((ListPopulation) population));
     }
@@ -67,7 +68,7 @@ public class TournamentSelection impleme
      * @return the selected chromosome.
      * @throws MathIllegalArgumentException if the tournament arity is bigger than the population
size
      */
-    private Chromosome tournament(final ListPopulation population) {
+    private Chromosome tournament(final ListPopulation population) throws MathIllegalArgumentException
{
         if (population.getPopulationSize() < this.arity) {
             throw new MathIllegalArgumentException(LocalizedFormats.TOO_LARGE_TOURNAMENT_ARITY,
                                                    arity, population.getPopulationSize());

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/UniformCrossover.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/UniformCrossover.java?rev=1385297&r1=1385296&r2=1385297&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/UniformCrossover.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/genetics/UniformCrossover.java
Sun Sep 16 16:05:57 2012
@@ -60,7 +60,7 @@ public class UniformCrossover<T> impleme
      * @param ratio the mixing ratio
      * @throws OutOfRangeException if the mixing ratio is outside the [0, 1] range
      */
-    public UniformCrossover(final double ratio) {
+    public UniformCrossover(final double ratio) throws OutOfRangeException {
         if (ratio < 0.0d || ratio > 1.0d) {
             throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE, ratio, 0.0d, 1.0d);
         }
@@ -78,9 +78,15 @@ public class UniformCrossover<T> impleme
 
     /**
      * {@inheritDoc}
+     *
+     * @throws MathIllegalArgumentException iff one of the chromosomes is
+     *   not an instance of {@link AbstractListChromosome}
+     * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     @SuppressWarnings("unchecked")
-    public ChromosomePair crossover(final Chromosome first, final Chromosome second) {
+    public ChromosomePair crossover(final Chromosome first, final Chromosome second)
+        throws DimensionMismatchException, MathIllegalArgumentException {
+
         if (!(first instanceof AbstractListChromosome<?> && second instanceof
AbstractListChromosome<?>)) {
             throw new MathIllegalArgumentException(LocalizedFormats.INVALID_FIXED_LENGTH_CHROMOSOME);
         }
@@ -96,7 +102,7 @@ public class UniformCrossover<T> impleme
      * @throws DimensionMismatchException if the length of the two chromosomes is different
      */
     private ChromosomePair mate(final AbstractListChromosome<T> first,
-                                final AbstractListChromosome<T> second) {
+                                final AbstractListChromosome<T> second) throws DimensionMismatchException
{
         final int length = first.getLength();
         if (length != second.getLength()) {
             throw new DimensionMismatchException(second.getLength(), length);



Mime
View raw message