Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.4/Programmable/CompiledSingleObjectiveOptimizationSupport.cs @ 12406

Last change on this file since 12406 was 11961, checked in by abeham, 10 years ago

#2174: Integrated programmable problem into trunk

  • Fixed build configuration
  • Fixed some assembly references that had CopyLocal set to true
  • Added a missing license header
  • Cleaned some usings
  • Fixed the version number in ExternalEvaluation.GP
  • Added ProgrammableProblem and new ExternalEvaluationProblem as a reference to unit tests
  • Fixed plugin dependencies and assembly references
  • Changed icon of programmable problem to script icon
  • Fixed name clash in VRP that also had defined a "PermutationEncoding" class
  • (Hopefully) fixed all output paths
File size: 1.9 KB
RevLine 
[11753]1using System;
2using System.Linq;
3using System.Collections.Generic;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Optimization;
8
[11893]9namespace 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
Note: See TracBrowser for help on using the repository browser.