001    package org.jaga.definitions;
002    
003    
004    /**
005     * Basis for all algorithms which perform the reproduction of individuals.
006     *
007     * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
008     *
009     * <p><u>Company:</u> University College London and JAGA.Org
010     *    (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
011     * </p>
012     *
013     * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
014     *    This program is free software; you can redistribute it and/or modify
015     *    it under the terms of the GNU General Public License as published by
016     *    the Free Software Foundation, ONLY if you include a note of the original
017     *    author(s) in any redistributed/modified copy.<br/>
018     *    This program is distributed in the hope that it will be useful,
019     *    but WITHOUT ANY WARRANTY; without even the implied warranty of
020     *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021     *    GNU General Public License for more details.<br/>
022     *    You should have received a copy of the GNU General Public License
023     *    along with this program; if not, write to the Free Software
024     *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
025     *    or see http://www.gnu.org/licenses/gpl.html</p>
026     *
027     * @author Greg Paperin (greg@jaga.org)
028     *
029     * @version JAGA public release 1.0 beta
030     */
031    
032    public interface ReproductionAlgorithm {
033    
034            /**
035             * Returns, how many individuals are required to produce one new individual
036             * whwn using this reproduction algorithm. If any number of parents is
037             * permitted (e.g. for most kinds of mutation), this method should
038             * return <code>-1</code>.
039             *
040             * @return The required length of the array-parameter <code>parents</code> to the
041             * method <code>reproduce</code> or <code>-1</code> if any length is parmitted.
042             *
043             */
044            public int getRequiredNumberOfParents();
045    
046            /**
047             * Returns the class of individuals handled by this reproduction algorithm.
048             *
049             * @return The required type of the array-members in the parameter
050             * <code>parents</code> to the method <code>ReproductionAlgorithm.reproduce</code>.
051             */
052            public Class getApplicableClass();
053    
054            /**
055             * Reproduces the specified individuals.
056             *
057             * @param parents The individuals to reproduce. The type of objects in this
058             * array must be the class returned by <code>getApplicableClass</code>.
059             * The number of objects in this array must be the same as returned by
060             * <code>getRequiredNumberOfParents</code>.
061             *
062             * @param params Experiment parameters.
063             *
064             * @return The children - i.e. the result of the reproduction of
065             * <code>parents</code>.
066             *
067             * @throws ClassCastException If a parent is not of a class which can be
068             * cast to the class returned by <code>getApplicableClass</code>.
069             *
070             * @throws ClassCastException If the number of parents does not correspond
071             * to the required number obtained via <code>getRequiredNumberOfParents</code>.
072             */
073            public Individual [] reproduce(Individual [] parents, GAParameterSet params)
074                                                            throws ClassCastException, IllegalArgumentException;
075    
076    }