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