[Quantproject-developers] QuantProject/b1_ADT/Optimizing/Genetic GeneticOptimizer.cs,1.3,1.4
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-06-02 18:04:33
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18636/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Minor changes for the GeneticOptimizer class Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GeneticOptimizer.cs 17 May 2005 23:00:57 -0000 1.3 --- GeneticOptimizer.cs 2 Jun 2005 18:03:59 -0000 1.4 *************** *** 37,48 **** { #region fields ! private double mutationRate = 0.02; ! private double crossoverRate = 0.85; ! private double elitismRate = 0.01; ! private double minConvergenceRate = 0.80; ! private bool keepOnRunningUntilConvergenceIsReached = false; ! private int populationSize = 1000; ! private int generationNumber = 100; private int genomeSize; private int minValueForGenes; --- 37,49 ---- { #region fields + private static Random random = new Random((int)DateTime.Now.Ticks); ! private double mutationRate; ! private double crossoverRate; ! private double elitismRate; ! private double minConvergenceRate; ! private bool keepOnRunningUntilConvergenceIsReached; ! private int populationSize; ! private int generationNumber; private int genomeSize; private int minValueForGenes; *************** *** 59,63 **** private ArrayList cumulativeFitnessList; - private static Random random = new Random((int)DateTime.Now.Ticks); private int generationCounter; #endregion --- 60,63 ---- *************** *** 158,162 **** private void commonInitialization() { ! this.genomeSize = this.genomeManager.GenomeSize; this.minValueForGenes = this.genomeManager.MinValueForGenes; this.maxValueForGenes = this.genomeManager.MaxValueForGenes; --- 158,167 ---- private void commonInitialization() { ! this.mutationRate = 0.02; ! this.crossoverRate = 0.85; ! this.elitismRate = 0.01; ! this.minConvergenceRate = 0.80; ! this.keepOnRunningUntilConvergenceIsReached = false; ! this.genomeSize = this.genomeManager.GenomeSize; this.minValueForGenes = this.genomeManager.MinValueForGenes; this.maxValueForGenes = this.genomeManager.MaxValueForGenes; *************** *** 164,176 **** this.cumulativeFitnessList = new ArrayList(this.PopulationSize); this.currentGeneration = new ArrayList(this.PopulationSize); ! this.nextGeneration = new ArrayList(); ! this.currentEliteToTransmitToNextGeneration = ! new ArrayList((int)(this.ElitismRate*(double)this.PopulationSize)); ! this.generationCounter = 1; } /// <summary> ! /// Method which starts the GeneticOptmizer /// </summary> public void Run(bool showOutputToConsole) --- 169,181 ---- this.cumulativeFitnessList = new ArrayList(this.PopulationSize); this.currentGeneration = new ArrayList(this.PopulationSize); ! int eliteNumber = (int)(this.ElitismRate*(double)this.PopulationSize); ! this.currentEliteToTransmitToNextGeneration = new ArrayList(eliteNumber); ! this.nextGeneration = new ArrayList(this.populationSize + ! eliteNumber); this.generationCounter = 1; } /// <summary> ! /// Method to start the GeneticOptmizer /// </summary> public void Run(bool showOutputToConsole) *************** *** 252,263 **** double randomFitness = this.totalFitness *(double)GeneticOptimizer.random.Next(1,1001)/1000; int idx = -1; - int mid; int first = 0; int last = this.populationSize -1; ! mid = (last - first)/2; ! // Need to implement a specific search, because the // ArrayList's BinarySearch is for exact values only - while (idx == -1 && first <= last) { --- 257,265 ---- double randomFitness = this.totalFitness *(double)GeneticOptimizer.random.Next(1,1001)/1000; int idx = -1; int first = 0; int last = this.populationSize -1; ! int mid = (last - first)/2; // Need to implement a specific search, because the // ArrayList's BinarySearch is for exact values only while (idx == -1 && first <= last) { *************** *** 270,279 **** first = mid; } - mid = (first + last)/2; if ((last - first) == 1) idx = last; ! ! } return idx; } --- 272,279 ---- first = mid; } mid = (first + last)/2; if ((last - first) == 1) idx = last; ! } return idx; } *************** *** 285,289 **** private void calculateTotalFitness() { ! this.totalFitness = 0; for (int i = 0; i < this.populationSize; i++) { --- 285,289 ---- private void calculateTotalFitness() { ! this.totalFitness = 0.0; for (int i = 0; i < this.populationSize; i++) { |