source: branches/ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs @ 13372

Last change on this file since 13372 was 13372, checked in by mkommend, 7 years ago

#2521: Fixed all problems.

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(ISolution[] 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<ISolution> GetNeighbors(ISolution 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 = (ISolution)individual.Clone();
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.