Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs @ 13345

Last change on this file since 13345 was 13345, checked in by mkommend, 9 years ago

#2521: refactored programmable problem

File size: 2.5 KB
Line 
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using {0}
8using HeuristicLab.Optimization;
9using HeuristicLab.Problems.Programmable;
10
11namespace HeuristicLab.Problems.Programmable {
12  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> {
13    public bool Maximization { get { return false; } }
14
15    public override void Initialize() {
16      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
17      // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
18      // Add additional initialization code e.g. private variables that you need for evaluating
19    }
20
21    public double Evaluate({2} individual, IRandom random) {
22      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
23      var quality = 0.0;
24      return quality;
25    }
26
27    public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) {
28      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
29      // Write or update results given the range of vectors and resulting qualities
30      // Uncomment the following lines if you want to retrieve the best individual
31
32      //var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);
33      //var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;
34
35      //if (!results.ContainsKey("Best Solution")) {
36      //  results.Add(new Result("Best Solution", typeof({20)));
37      //}
38      //results["Best Solution"].Value = (IItem)best.Clone();
39    }
40
41    public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) {
42      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
43      // Create new vectors, based on the given one that represent small changes
44      // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
45      while (true) {
46        // Algorithm will draw only a finite amount of samples
47        // Change to a for-loop to return a concrete amount of neighbors
48        var neighbor = ({2})individual.Clone();
49        // modify the solution specified as neighbor
50        yield return neighbor;
51      }
52    }
53
54    // Implement further classes and methods
55  }
56}
57
Note: See TracBrowser for help on using the repository browser.