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