src/GenFx.Components/Plugins/MetricLogger.cs
/// <summary>
/// Handles the event when a generation has been created.
/// </summary>
/// <param name="environment">The environment representing the generation that was created.</param>
/// <param name="generationIndex">Index value of the generation that was created.</param>
Handles the event when a generation has been created.
Handles the event when a generation has been created .
protected override void OnFitnessEvaluated(GeneticEnvironment environment, int generationIndex)
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }
            if (this.Algorithm == null)
            {
                return;
            }
            foreach (Population population in environment.Populations)
            {
                foreach (Metric metric in this.Algorithm.Metrics)
                {
                    string? metricVal = metric.GetResultValue(population)?.ToString();
                    string metricName;
                    DisplayNameAttribute attrib = (DisplayNameAttribute)TypeDescriptor.GetAttributes(metric)[typeof(DisplayNameAttribute)];
                    if (!String.IsNullOrEmpty(attrib.DisplayName))
                    {
                        metricName = attrib.DisplayName;
                    }
                    else
                    {
                        metricName = metric.ToString();
                    }
                    if (metricVal == null)
                    {
                        metricVal = "<null>";
                    }
                    this.WriteTrace(String.Format(CultureInfo.CurrentCulture, Resources.MetricLogger_StatTrace,
                        metricName, metricVal, population.Index, generationIndex));
                }
            }
        }
protected override void OnFitnessEvaluated ( GeneticEnvironment environment , int generationIndex ) { if ( environment == null ) { throw new ArgumentNullException ( nameof ( environment ) ) ; } if ( this . Algorithm == null ) { return ; } foreach ( Population population in environment . Populations ) { foreach ( Metric metric in this . Algorithm . Metrics ) { string ? metricVal = metric . GetResultValue ( population ) ? . ToString ( ) ; string metricName ; DisplayNameAttribute attrib = ( DisplayNameAttribute ) TypeDescriptor . GetAttributes ( metric ) [ typeof ( DisplayNameAttribute ) ] ; if ( ! String . IsNullOrEmpty ( attrib . DisplayName ) ) { metricName = attrib . DisplayName ; } else { metricName = metric . ToString ( ) ; } if ( metricVal == null ) { metricVal = " " ; } this . WriteTrace ( String . Format ( CultureInfo . CurrentCulture , Resources . MetricLogger_StatTrace , metricName , metricVal , population . Index , generationIndex ) ) ; } } }
Handles the event when a generation has been created.
Handles the event when a generation has been created .
// TypeDescriptor will always provide a DisplayNameAttribute, even if one isn't declared on the type.
environment
GeneticEnvironment
The environment representing the generation that was created.
The environment representing the generation that was created .
generationIndex
int
Index value of the generation that was created.
Index value of the generation that was created .