[Quantproject-developers] QuantProject/b7_Scripts/TickerSelectionTesting GenomeManipulator.cs,1.2,1.
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-08-03 23:12:33
|
Update of /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16620/b7_Scripts/TickerSelectionTesting Modified Files: GenomeManipulator.cs Log Message: MixGenesWithoutDuplicates is now "stronger": exchange of genes occurs (if possible) in next gene position, if it hasn't in previous. Index: GenomeManipulator.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b7_Scripts/TickerSelectionTesting/GenomeManipulator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenomeManipulator.cs 3 Aug 2005 18:59:19 -0000 1.2 --- GenomeManipulator.cs 3 Aug 2005 23:12:25 -0000 1.3 *************** *** 31,35 **** /// <summary> /// Class providing static methods for manipulating Genomes ! /// (used by th IGenomeManagerForEfficientPortfolio) /// </summary> [Serializable] --- 31,35 ---- /// <summary> /// Class providing static methods for manipulating Genomes ! /// (used by IGenomeManagerForEfficientPortfolio) /// </summary> [Serializable] *************** *** 51,58 **** { genomeSize = parent1.Size; ! 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++) --- 51,56 ---- { genomeSize = parent1.Size; ! childs[0]=parent1.Clone(); ! childs[1]=parent2.Clone(); maskForChilds = new int[childs.Length, genomeSize]; for(int i = 0; i<genomeSize; i++) *************** *** 61,131 **** maskForChilds[1,i]=2; } } - private static void assignFitnessAndMeaningToChilds() - { - foreach(Genome child in childs) - { - child.AssignMeaning(); - child.CalculateFitness(); - } - } - - /*old - private static int firstGenePositionOfParent1NotPresentInParent2(Genome parent1, - Genome parent2) - { - int returnValue = -1; - for(int genePos = 0 ; - genePos < GenomeManipulator.genomeSize && returnValue == -1; - genePos++) - { - int geneValue = parent1.GetGeneValue(genePos); - if(geneValue >= 0) - { - if(!parent2.HasGene(geneValue) && - !parent2.HasGene(-Math.Abs(geneValue) - 1)) - returnValue = genePos; - } - else - { - if(!parent2.HasGene(geneValue) && - !parent2.HasGene(Math.Abs(geneValue) - 1)) - returnValue = genePos; - } - } - return returnValue; - } - */ - /* old - 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 ) - //there is at least a gene in parent1 not present in parent2 and viceversa - { - for(int genePos = 0 ; genePos < GenomeManipulator.genomeSize ; genePos++) - { - if(genePos == firstGenePosOfParent1NotPresentInParent2) - maskForChilds[0, genePos] = 1; - else - maskForChilds[0, genePos] = 2; - - if(genePos == firstGenePosOfParent2NotPresentInParent1) - maskForChilds[1, genePos] = 2; - else - maskForChilds[1, genePos] = 1; - } - returnValue = true; - } - return returnValue; - } - */ private static int[] genePositionsOfParent1NotPresentInParent2(Genome parent1, Genome parent2) --- 59,66 ---- maskForChilds[1,i]=2; } + //maskForChilds has been set in order to re-create + //a copy of parents by using setChildsUsingMaskForChilds() } private static int[] genePositionsOfParent1NotPresentInParent2(Genome parent1, Genome parent2) *************** *** 159,166 **** 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) --- 94,104 ---- int[] genePlacesOfParent2NotPresentInParent1 = genePositionsOfParent1NotPresentInParent2(parent2, parent1); + bool justExchangedAtPreviousPosition = false; for(int i = 0;i<parent1.Size;i++) { ! if(!justExchangedAtPreviousPosition) ! //exchanges between genes of parents in childs ! //must follow an alternate pattern, in order to ! //avoid plain copy of parents in childs { if(genePlacesOfParent2NotPresentInParent1[i]!= - 1) *************** *** 168,171 **** --- 106,110 ---- maskForChilds[0, i] = 2;//the change between genes maskForChilds[1, i] = 1;//creates a child different from parents + justExchangedAtPreviousPosition = true; } else if(genePlacesOfParent1NotPresentInParent2[i]!= - 1) //see 1st if *************** *** 173,178 **** --- 112,120 ---- maskForChilds[0, i] = 1; maskForChilds[1, i] = 2; + justExchangedAtPreviousPosition = true; } } + else + justExchangedAtPreviousPosition = false; } } |