Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/SingleObjective/CompiledSingleObjectiveOptimizationSupport.cs @ 16816

Last change on this file since 16816 was 16816, checked in by abeham, 5 years ago

#2521: Refactored external evaluation problem

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