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 |
|
---|
9 | namespace HeuristicLab.Problems.ExternalEvaluation {
|
---|
10 | public class CompiledSingleObjectiveOptimizationSupport : CompiledOptimizationSupport, ISingleObjectiveOptimizationSupport {
|
---|
11 |
|
---|
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];
|
---|
20 | }
|
---|
21 |
|
---|
22 | public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
|
---|
23 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
24 | // Create new vectors, based on the given one that represent small changes
|
---|
25 | // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
|
---|
26 | while (true) {
|
---|
27 | // Algorithm will draw only a finite amount of samples
|
---|
28 | // Change to a for-loop to return a concrete amount of neighbors
|
---|
29 | var neighbor = individual.Copy();
|
---|
30 | // For instance, perform a single bit-flip in a binary parameter
|
---|
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 |
|
---|
37 | // Implement further classes and methods
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|