[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManipulator.cs,1.1,1.
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-08-03 18:59:28
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13377/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: MixGenesWithoutDuplicates has been definitively fixed (I hope ...). Now, a complete crossover (with an alternate fixed pattern) takes place when all parents' genes are different. A partial crossover (or no crossover at all, if parents are equal) takes place if some genes are duplicated. Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenomeManipulator.cs 31 Jul 2005 19:53:44 -0000 1.1 --- GenomeManipulator.cs 3 Aug 2005 18:59:19 -0000 1.2 *************** *** 53,58 **** childs[0] = parent1.Clone(); childs[1] = parent2.Clone(); ! //the two childs now points to their parents maskForChilds = new int[childs.Length, genomeSize]; } --- 53,64 ---- childs[0] = parent1.Clone(); childs[1] = parent2.Clone(); ! //the two childs now points to their parents, ! //and so do maskForChilds maskForChilds = new int[childs.Length, genomeSize]; + for(int i = 0; i<genomeSize; i++) + { + maskForChilds[0,i]=1; + maskForChilds[1,i]=2; + } } *************** *** 146,181 **** } ! private static bool setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) { - bool returnValue = false; int[] genePlacesOfParent1NotPresentInParent2 = genePositionsOfParent1NotPresentInParent2(parent1, parent2); int[] genePlacesOfParent2NotPresentInParent1 = genePositionsOfParent1NotPresentInParent2(parent2, parent1); ! for(int i = 0; i<genePlacesOfParent1NotPresentInParent2.Length; i++) { ! for(int genePos = 0 ; genePos < GenomeManipulator.genomeSize ; genePos++) ! { ! if(genePos == genePlacesOfParent1NotPresentInParent2[i]) ! { ! maskForChilds[0, genePos] = 1; ! returnValue = true; ! } ! else ! maskForChilds[0, genePos] = 2; ! ! if(genePos == genePlacesOfParent2NotPresentInParent1[i]) ! { ! maskForChilds[1, genePos] = 2; ! returnValue = true; ! } ! else ! maskForChilds[1, genePos] = 1; } } - return returnValue; } ! private static void setChildsUsingMaskForChilds(Genome parent1, Genome parent2) { --- 152,182 ---- } ! private static void setMaskForChildsForMixingWithoutDuplicates(Genome parent1, Genome parent2) { int[] genePlacesOfParent1NotPresentInParent2 = genePositionsOfParent1NotPresentInParent2(parent1, parent2); int[] genePlacesOfParent2NotPresentInParent1 = genePositionsOfParent1NotPresentInParent2(parent2, parent1); ! for(int i = 0;i<parent1.Size;i++) { ! if(i%2 == 0) ! //genes are ex-changed only at even positions ! { ! if(genePlacesOfParent2NotPresentInParent1[i]!= - 1) ! { ! maskForChilds[0, i] = 2;//the change between genes ! maskForChilds[1, i] = 1;//creates a child different from parents ! } ! else if(genePlacesOfParent1NotPresentInParent2[i]!= - 1) //see 1st if ! { ! maskForChilds[0, i] = 1; ! maskForChilds[1, i] = 2; ! } } } } ! ! private static void setChildsUsingMaskForChilds(Genome parent1, Genome parent2) { *************** *** 238,243 **** throw new Exception("Genomes must have the same size!"); ! if(setMaskForChildsForMixingWithoutDuplicates(parent1, parent2)) ! setChildsUsingMaskForChilds(parent1, parent2); //throwExcIfAChildHasDuplicateGenes(); //just for debugging purposes return childs; --- 239,244 ---- throw new Exception("Genomes must have the same size!"); ! setMaskForChildsForMixingWithoutDuplicates(parent1, parent2); ! setChildsUsingMaskForChilds(parent1, parent2); //throwExcIfAChildHasDuplicateGenes(); //just for debugging purposes return childs; |