Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs @ 14349

Last change on this file since 14349 was 13257, checked in by pfleck, 9 years ago

#1674

  • Adapted ItemName from ExternalEvaluationProblem and MultiObjectiveExternalEvaluationProblem.
  • Removed/Fixed the support script code in from the comments.
File size: 1.9 KB
RevLine 
[13257]1using System.Collections.Generic;
[11753]2using HeuristicLab.Core;
3using HeuristicLab.Optimization;
4
[11893]5namespace HeuristicLab.Problems.ExternalEvaluation {
6  public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
[11753]7
[11880]8    public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
9      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
10      // Write or update results given the range of vectors and resulting qualities
11      // Uncomment the following lines if you want to retrieve the best individual
[13257]12      // Maximization:
13      // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1;
14      // Minimization:
15      // var bestIndex = qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1;
16      // var best = individuals[bestIndex];
[11753]17    }
18
19    public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
[11880]20      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
[11753]21      // Create new vectors, based on the given one that represent small changes
[11880]22      // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
[11753]23      while (true) {
[11880]24        // Algorithm will draw only a finite amount of samples
25        // Change to a for-loop to return a concrete amount of neighbors
[11753]26        var neighbor = individual.Copy();
[11880]27        // For instance, perform a single bit-flip in a binary parameter
[11753]28        //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
29        //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
30        yield return neighbor;
31      }
32    }
33
[11880]34    // Implement further classes and methods
[11753]35  }
36}
Note: See TracBrowser for help on using the repository browser.