Ignore:
Timestamp:
08/25/15 14:22:22 (6 years ago)
Author:
gkronber
Message:

#2422 reverse merge of r12900 (unintended commit)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs

    r12900 r12901  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HeuristicLab.Common;
     
    5150    }
    5251
    53     public abstract double Evaluate(ISymbolicExpressionTree tree, IRandom random);
     52    public abstract double Evaluate(ISymbolicExpressionTree vector, IRandom random);
    5453    public sealed override double Evaluate(Individual individual, IRandom random) {
    5554      return Evaluate(individual.SymbolicExpressionTree(), random);
    5655    }
    5756
    58     public virtual void Analyze(ISymbolicExpressionTree[] trees, double[] qualities, ResultCollection results, IRandom random) {
    59       var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    60       var bestIdx = Array.IndexOf(qualities, bestQuality);
    61       var best = trees[bestIdx];
     57    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     58      base.Analyze(individuals, qualities, results, random);
     59      var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);
     60      var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;
     61
    6262      if (!results.ContainsKey("Best Solution")) {
    6363        results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree)));
    6464      }
    65       results["Best Solution"].Value = (IItem)best.Clone();
    66     }
    67     public sealed override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    68       Analyze(individuals.Select(ind => ind.SymbolicExpressionTree()).ToArray(), qualities, results, random);
     65      results["Best Solution"].Value = (IItem)best.SymbolicExpressionTree().Clone();
    6966    }
    7067  }
Note: See TracChangeset for help on using the changeset viewer.