[Quantproject-developers] QuantProject/b1_ADT/Optimizing/Genetic IGenomeManager.cs, 1.4, 1.5 Genome
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2007-01-03 23:20:47
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4394/b1_ADT/Optimizing/Genetic Modified Files: IGenomeManager.cs GenomeManagerTest.cs GenomeManagement.cs GeneticOptimizer.cs Log Message: Deleted the mutationRate parameter from the IGenomeManager's Mutate method. Now classes implementing Mutate method just need to pass only the genome that has to be mutated to the method. As the mutationRate is now used only by the GeneticOptimizer, all the methods that effectively mutate genes of a given genome don't need anymore the mutation rate parameter. Index: GenomeManagerTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagerTest.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenomeManagerTest.cs 7 Aug 2006 21:03:24 -0000 1.6 --- GenomeManagerTest.cs 3 Jan 2007 23:20:11 -0000 1.7 *************** *** 77,83 **** } ! public void Mutate(Genome genome, double mutationRate) { ! GenomeManagement.MutateAllGenes(genome, mutationRate); } --- 77,83 ---- } ! public void Mutate(Genome genome) { ! GenomeManagement.MutateAllGenes(genome); } Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** GeneticOptimizer.cs 22 Aug 2006 19:05:50 -0000 1.22 --- GeneticOptimizer.cs 3 Jan 2007 23:20:11 -0000 1.23 *************** *** 489,493 **** { foreach(Genome g in this.nextGeneration) ! this.genomeManager.Mutate(g,this.MutationRate); } --- 489,496 ---- { foreach(Genome g in this.nextGeneration) ! { ! if( GenomeManagement.RandomGenerator.Next(0,101) < (int)(this.mutationRate*100) ) ! this.genomeManager.Mutate(g); ! } } Index: IGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/IGenomeManager.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IGenomeManager.cs 7 Aug 2006 21:03:24 -0000 1.4 --- IGenomeManager.cs 3 Jan 2007 23:20:10 -0000 1.5 *************** *** 49,53 **** object Decode(Genome genome); Genome[] GetChilds(Genome parent1, Genome parent2); ! void Mutate(Genome genome, double mutationRate); } } --- 49,53 ---- object Decode(Genome genome); Genome[] GetChilds(Genome parent1, Genome parent2); ! void Mutate(Genome genome); } } Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GenomeManagement.cs 7 Aug 2006 21:03:24 -0000 1.10 --- GenomeManagement.cs 3 Jan 2007 23:20:11 -0000 1.11 *************** *** 173,204 **** } ! static public void MutateAllGenes(Genome genome, double mutationRate) { for (int pos = 0 ; pos < genome.Size; pos++) { ! if (GenomeManagement.RandomGenerator.Next(0,101) < (int)(mutationRate*100)) ! genome.SetGeneValue(GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(pos), ! genome.GetMaxValueForGenes(pos) + 1), pos); } } ! static public void MutateOneGene(Genome genome, double mutationRate, ! int genePosition) { ! ! if (GenomeManagement.RandomGenerator.Next(0,101) < (int)(mutationRate*100)) ! genome.SetGeneValue(GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), genome.GetMaxValueForGenes(genePosition) + 1), genePosition); - } ! static public void MutateOneGene(Genome genome, double mutationRate, ! int genePosition, int newValueOfGene) { ! if (GenomeManagement.RandomGenerator.Next(0,101) < (int)(mutationRate*100)) ! genome.SetGeneValue(newValueOfGene, genePosition); ! } #region MixGenesWithoutDuplicates --- 173,212 ---- } ! static public void MutateAllGenes(Genome genome) { for (int pos = 0 ; pos < genome.Size; pos++) { ! genome.SetGeneValue( GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(pos), ! genome.GetMaxValueForGenes(pos) + 1), pos ); } } ! static public void MutateOneGene(Genome genome, int genePosition) { ! genome.SetGeneValue(GenomeManagement.RandomGenerator.Next(genome.GetMinValueForGenes(genePosition), genome.GetMaxValueForGenes(genePosition) + 1), genePosition); } ! static public void MutateOneGene(Genome genome, ! int genePosition, int newValueOfGene) { ! genome.SetGeneValue(newValueOfGene, genePosition); } + static public void MutateGenes(Genome genome, + int[] positionsOfGenesToBeMutated, + int[] newValuesForGenes) + { + if(positionsOfGenesToBeMutated.Length > genome.Size || + positionsOfGenesToBeMutated.Length != newValuesForGenes.Length) + throw new Exception("Bad parameters: too many positions of genes to be mutated or " + + "newValueForGenes' length is different from positionsOfGenesToBeMutated's lenght"); + + for(int i = 0; i<positionsOfGenesToBeMutated.Length; i++) + genome.SetGeneValue(newValuesForGenes[i], positionsOfGenesToBeMutated[i]); + + } + + #region MixGenesWithoutDuplicates |