001 package org.jaga.reproduction.proteinLocation;
002
003 import org.jaga.reproduction.Mutation;
004 import org.jaga.individualRepresentation.proteinLocation.*;
005 import org.jaga.definitions.*;
006
007 /**
008 * TODO: Complete these comments.
009 *
010 * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
011 *
012 * <p><u>Company:</u> University College London and JAGA.Org
013 * (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
014 * </p>
015 *
016 * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
017 * This program is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU General Public License as published by
019 * the Free Software Foundation, ONLY if you include a note of the original
020 * author(s) in any redistributed/modified copy.<br/>
021 * This program is distributed in the hope that it will be useful,
022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
024 * GNU General Public License for more details.<br/>
025 * You should have received a copy of the GNU General Public License
026 * along with this program; if not, write to the Free Software
027 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
028 * or see http://www.gnu.org/licenses/gpl.html</p>
029 *
030 * @author Greg Paperin (greg@jaga.org)
031 *
032 * @version JAGA public release 1.0 beta
033 */
034
035 public class PolypeptidePatternElongation extends Mutation {
036
037 public PolypeptidePatternElongation() {
038 super();
039 }
040
041 public PolypeptidePatternElongation(double mutProb) {
042 super(mutProb);
043 }
044
045 public Individual reproduce(Individual parent, GAParameterSet params) {
046 ProteinLocationClassifier kid = (ProteinLocationClassifier)
047 params.getIndividualsFactory().createSpecificIndividual(parent, params);
048 PolypeptidePattern pattern = kid.getPattern();
049 RandomGenerator rnd = params.getRandomGenerator();
050 double mutProb = getMutationProbability();
051 ProteinLocationClassifierFactory factory = (ProteinLocationClassifierFactory) params.getIndividualsFactory();
052 for (int i = 0; i <= pattern.getLength(); i++)
053 if (rnd.nextDouble() < mutProb)
054 if (pattern.getLength() < factory.getMaxPatternLength())
055 pattern.insertItem(i, factory.createRandomPatternItem(params));
056 return kid;
057 }
058
059 public Individual[] reproduce(Individual[] parents, GAParameterSet params) {
060 Individual [] kids = new Individual[parents.length];
061 for (int i = 0; i < parents.length; i++)
062 kids[i] = reproduce(parents[i], params);
063 return kids;
064 }
065
066 public Class getApplicableClass() {
067 return ProteinLocationClassifier.class;
068 }
069 }