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