Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs @ 15016

Last change on this file since 15016 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
Line 
1using System.Collections.Generic;
2using HeuristicLab.Core;
3using HeuristicLab.Optimization;
4
5namespace HeuristicLab.Problems.ExternalEvaluation {
6  public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
7
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
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];
17    }
18
19    public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
20      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
21      // Create new vectors, based on the given one that represent small changes
22      // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
23      while (true) {
24        // Algorithm will draw only a finite amount of samples
25        // Change to a for-loop to return a concrete amount of neighbors
26        var neighbor = individual.Copy();
27        // For instance, perform a single bit-flip in a binary parameter
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
34    // Implement further classes and methods
35  }
36}
Note: See TracBrowser for help on using the repository browser.