Changeset 12904


Ignore:
Timestamp:
08/25/15 14:25:24 (4 years ago)
Author:
gkronber
Message:

#2469: implemented override for Analyze(...) method in SymbolicExpressionTreeProblem

File:
1 edited

Legend:

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

    r12901 r12904  
    2222#endregion
    2323
     24using System;
    2425using System.Linq;
    2526using HeuristicLab.Common;
     
    5051    }
    5152
    52     public abstract double Evaluate(ISymbolicExpressionTree vector, IRandom random);
     53    public abstract double Evaluate(ISymbolicExpressionTree tree, IRandom random);
    5354    public sealed override double Evaluate(Individual individual, IRandom random) {
    5455      return Evaluate(individual.SymbolicExpressionTree(), random);
    5556    }
    5657
    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 
     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];
    6262      if (!results.ContainsKey("Best Solution")) {
    6363        results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree)));
    6464      }
    65       results["Best Solution"].Value = (IItem)best.SymbolicExpressionTree().Clone();
     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);
    6669    }
    6770  }
Note: See TracChangeset for help on using the changeset viewer.