src/GenFx/GeneticAlgorithm.cs
/// <summary>
/// Sorts the metrics according to their dependencies.
/// </summary>
Sorts the metrics according to their dependencies.
Sorts the metrics according to their dependencies .
private void SortMetrics()
        {
            this.sortedMetrics = new List<Metric>();
            List<MetricNode> roots = new List<MetricNode>();
            Dictionary<Type, MetricNode> collectedMetricTypes = new Dictionary<Type, GenFx.GeneticAlgorithm.MetricNode>();
            foreach (Type metricType in this.metrics.Select(m => m.GetType()))
            {
                CollectMetricTypeGraphs(metricType, roots, collectedMetricTypes);
            }
            Queue<MetricNode> nodesToIterate = new Queue<MetricNode>(roots);
            while (nodesToIterate.Any())
            {
                MetricNode node = nodesToIterate.Dequeue();
                Metric metric = this.metrics.First(m => m.GetType() == node.MetricType);
                this.sortedMetrics.Add(metric);
                foreach (MetricNode dependentNode in node.Dependencies)
                {
                    nodesToIterate.Enqueue(dependentNode);
                }
            }
        }
private void SortMetrics ( ) { this . sortedMetrics = new List < Metric > ( ) ; List < MetricNode > roots = new List < MetricNode > ( ) ; Dictionary < Type , MetricNode > collectedMetricTypes = new Dictionary < Type , GenFx . GeneticAlgorithm . MetricNode > ( ) ; foreach ( Type metricType in this . metrics . Select ( m => m . GetType ( ) ) ) { CollectMetricTypeGraphs ( metricType , roots , collectedMetricTypes ) ; } Queue < MetricNode > nodesToIterate = new Queue < MetricNode > ( roots ) ; while ( nodesToIterate . Any ( ) ) { MetricNode node = nodesToIterate . Dequeue ( ) ; Metric metric = this . metrics . First ( m => m . GetType ( ) == node . MetricType ) ; this . sortedMetrics . Add ( metric ) ; foreach ( MetricNode dependentNode in node . Dependencies ) { nodesToIterate . Enqueue ( dependentNode ) ; } } }
Sorts the metrics according to their dependencies.
Sorts the metrics according to their dependencies .
// Iterate through the nodes in the graphs, breadth first, and add them to the list // of sorted metric.  Since we're iterating them in this way, they are inherently sorted.