Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition_Template.cs @ 13348

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

#2521: Refactored single-objective programmable problem.

File size: 2.6 KB
Line 
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using ENCODING_NAMESPACE;
8using HeuristicLab.Optimization;
9using HeuristicLab.Problems.Programmable;
10
11namespace HeuristicLab.Problems.Programmable {
12  public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<ENCODING_CLASS, SOLUTION_CLASS> {
13    public override 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 override double Evaluate(SOLUTION_CLASS solution, 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 override void Analyze(SOLUTION_CLASS[] solution, 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(SOLUTION_CLASS)));
37      //}
38      //results["Best Solution"].Value = (IItem)best.Clone();
39    }
40
41    public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS 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 = (SOLUTION_CLASS)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.