Changeset 12904 for trunk/sources
- Timestamp:
- 08/25/15 14:25:24 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeProblem.cs
r12901 r12904 22 22 #endregion 23 23 24 using System; 24 25 using System.Linq; 25 26 using HeuristicLab.Common; … … 50 51 } 51 52 52 public abstract double Evaluate(ISymbolicExpressionTree vector, IRandom random);53 public abstract double Evaluate(ISymbolicExpressionTree tree, IRandom random); 53 54 public sealed override double Evaluate(Individual individual, IRandom random) { 54 55 return Evaluate(individual.SymbolicExpressionTree(), random); 55 56 } 56 57 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]; 62 62 if (!results.ContainsKey("Best Solution")) { 63 63 results.Add(new Result("Best Solution", typeof(ISymbolicExpressionTree))); 64 64 } 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); 66 69 } 67 70 }
Note: See TracChangeset
for help on using the changeset viewer.