[Quantproject-developers] QuantProject/b1_ADT/Optimizing/Genetic GenomeManagement.cs,1.2,1.3
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-06-24 22:26:09
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2946/b1_ADT/Optimizing/Genetic Modified Files: GenomeManagement.cs Log Message: Fixed bugs in MixGenesWithoutDuplicates static method. Index: GenomeManagement.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagement.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManagement.cs 10 Jun 2005 18:48:44 -0000 1.2 --- GenomeManagement.cs 24 Jun 2005 22:25:49 -0000 1.3 *************** *** 118,122 **** private static int firstGenePositionOfParent1NotPresentInParent2(Genome parent1, ! Genome parent2) { int returnValue = -1; --- 118,123 ---- private static int firstGenePositionOfParent1NotPresentInParent2(Genome parent1, ! Genome parent2, ! int constToDiscoverGenesDuplicates) { int returnValue = -1; *************** *** 125,129 **** genePos++) { ! if(!parent2.HasGene(parent1.GetGeneValue(genePos))) returnValue = genePos; } --- 126,133 ---- genePos++) { ! int geneValue = parent1.GetGeneValue(genePos); ! if(!parent2.HasGene(geneValue) && ! !parent2.HasGene(geneValue + constToDiscoverGenesDuplicates) && ! !parent2.HasGene(geneValue - constToDiscoverGenesDuplicates)) returnValue = genePos; } *************** *** 131,141 **** } ! private static bool setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) { bool returnValue = false; int firstGenePosOfParent1NotPresentInParent2 = ! firstGenePositionOfParent1NotPresentInParent2(parent1, parent2); int firstGenePosOfParent2NotPresentInParent1 = ! firstGenePositionOfParent1NotPresentInParent2(parent2, parent1); if(firstGenePosOfParent1NotPresentInParent2 > -1 && firstGenePosOfParent2NotPresentInParent1 > -1 ) --- 135,146 ---- } ! private static bool setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2, ! int constToDiscoverGenesDuplicates) { bool returnValue = false; int firstGenePosOfParent1NotPresentInParent2 = ! firstGenePositionOfParent1NotPresentInParent2(parent1, parent2, constToDiscoverGenesDuplicates); int firstGenePosOfParent2NotPresentInParent1 = ! firstGenePositionOfParent1NotPresentInParent2(parent2, parent1, constToDiscoverGenesDuplicates); if(firstGenePosOfParent1NotPresentInParent2 > -1 && firstGenePosOfParent2NotPresentInParent1 > -1 ) *************** *** 204,208 **** return childs; } ! /// <summary> /// This method returns an array of genomes based on --- 209,222 ---- return childs; } ! ! private static void launchExIfAChildHasDuplicateGenes(int constToDiscoverGenesDuplicates) ! { ! foreach(Genome gen in childs) ! { ! if(gen.HasSomeDuplicateGenes(constToDiscoverGenesDuplicates)) ! throw new Exception("A child with duplicate genes has been generated!"); ! } ! ! } /// <summary> /// This method returns an array of genomes based on *************** *** 211,215 **** /// the same time, childs' genes are not duplicated /// </summary> ! public static Genome[] MixGenesWithoutDuplicates(Genome parent1, Genome parent2) { initializeStaticMembers(parent1, parent2); --- 225,233 ---- /// the same time, childs' genes are not duplicated /// </summary> ! /// <param name="parent1">First genome parent from which genes are to be mixed in offspring</param> ! /// <param name="parents">Second genome parent from which genes are to be mixed in offspring</param> ! /// <param name="constToDiscoverGenesDuplicates">Gene y is a duplicate of gene x iff y = x or y = x + constToDiscoverGenesDuplicates</param> ! public static Genome[] MixGenesWithoutDuplicates(Genome parent1, Genome parent2, ! int constToDiscoverGenesDuplicates) { initializeStaticMembers(parent1, parent2); *************** *** 221,227 **** throw new Exception("Genomes must have the same size!"); ! if(setMaskForChildsForMixingWithoutDuplicates(parent1, parent2)) setChildsUsingMaskForChilds(parent1, parent2); ! return childs; } --- 239,246 ---- throw new Exception("Genomes must have the same size!"); ! if(setMaskForChildsForMixingWithoutDuplicates(parent1, parent2, ! constToDiscoverGenesDuplicates)) setChildsUsingMaskForChilds(parent1, parent2); ! launchExIfAChildHasDuplicateGenes(constToDiscoverGenesDuplicates); return childs; } |