/// <summary> /// Raises the CalculateObjective event. /// </summary> /// <param name="e"></param> protected virtual void OnCalculateObjective(CalculateObjectiveEventArgs e) { if (CalculateObjective != null) { CalculateObjective(this, e); } }
void Evaluate() { // // Calculate the normalized objective value of each chromosome. If we have // an objective value that is actually a measure of error (Inverted // objective), we negate it before passing it to the Scaler. // foreach (Chromosome c in Population.Chromosomes) { // // Give the Objective delegate first crack at supplying the objective, // then call any attached event handlers. This way, an event handler // can be used to supply the RawObjective (which is friendly from a // visual designer point of view), or the delegate can be installed // manually to avoid the performance overhead of all of those events // being raised. // if (Objective != null) { c.RawObjective = Objective(c); } if (CalculateObjective != null) { CalculateObjectiveEventArgs e = new CalculateObjectiveEventArgs(); e.Chromosome = c; OnCalculateObjective(e); } if (c.RawObjective > highestObjective) { highestObjective = c.RawObjective; } if (c.RawObjective < lowestObjective) { lowestObjective = c.RawObjective; } } double bias = (objectiveType == ObjectiveType.MinimizeObjective) ? Math.Abs(highestObjective) : Math.Abs(lowestObjective); foreach (Chromosome c in Population.Chromosomes) { // // If the objective is a measure of error, invert it. // c.NormalizedObjective = (objectiveType == ObjectiveType.MinimizeObjective) ? -c.RawObjective : c.RawObjective; // // Now add in the constant bias that forces all[*] values to // be positive. // c.NormalizedObjective += bias; } // // Sort the chromosomes by objective value. // Array.Sort(Population.Chromosomes, new Scaling.ObjectiveComparer()); // // Now that all the objective values have been calculated, // determine the fitness of each individual. // Scaler(Population.Chromosomes); // TODO: Track the total fitness here so that it can be passed to // the selection routine. }
void Evaluate() { // // Calculate the normalized objective value of each chromosome. If we have // an objective value that is actually a measure of error (Inverted // objective), we negate it before passing it to the Scaler. // foreach(Chromosome c in Population.Chromosomes) { // // Give the Objective delegate first crack at supplying the objective, // then call any attached event handlers. This way, an event handler // can be used to supply the RawObjective (which is friendly from a // visual designer point of view), or the delegate can be installed // manually to avoid the performance overhead of all of those events // being raised. // if ( Objective != null ) { c.RawObjective = Objective(c); } if ( CalculateObjective != null ) { CalculateObjectiveEventArgs e = new CalculateObjectiveEventArgs(); e.Chromosome = c; OnCalculateObjective( e ); } if ( c.RawObjective > highestObjective ) { highestObjective = c.RawObjective; } if ( c.RawObjective < lowestObjective ) { lowestObjective = c.RawObjective; } } double bias = (objectiveType == ObjectiveType.MinimizeObjective) ? Math.Abs(highestObjective) : Math.Abs(lowestObjective); foreach(Chromosome c in Population.Chromosomes) { // // If the objective is a measure of error, invert it. // c.NormalizedObjective = (objectiveType == ObjectiveType.MinimizeObjective) ? -c.RawObjective : c.RawObjective; // // Now add in the constant bias that forces all[*] values to // be positive. // c.NormalizedObjective += bias; } // // Sort the chromosomes by objective value. // Array.Sort( Population.Chromosomes, new Scaling.ObjectiveComparer() ); // // Now that all the objective values have been calculated, // determine the fitness of each individual. // Scaler(Population.Chromosomes); // TODO: Track the total fitness here so that it can be passed to // the selection routine. }
/// <summary> /// Raises the CalculateObjective event. /// </summary> /// <param name="e"></param> protected virtual void OnCalculateObjective(CalculateObjectiveEventArgs e) { if ( CalculateObjective != null ) { CalculateObjective(this, e); } }