1 | using System.Collections.Generic;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Optimization;
|
---|
4 |
|
---|
5 | namespace 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 | }
|
---|