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 ENCODING_NAMESPACE;
|
---|
8 | using HeuristicLab.Optimization;
|
---|
9 | using HeuristicLab.Problems.Programmable;
|
---|
10 |
|
---|
11 | namespace 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 | // Encoding.Length = 100;
|
---|
19 | // Add additional initialization code e.g. private variables that you need for evaluating
|
---|
20 | }
|
---|
21 |
|
---|
22 | public override double Evaluate(SOLUTION_CLASS solution, IRandom random) {
|
---|
23 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
24 | var quality = 0.0;
|
---|
25 | return quality;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public override void Analyze(SOLUTION_CLASS[] solutions, double[] qualities, ResultCollection results, IRandom random) {
|
---|
29 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
30 | // Write or update results given the range of vectors and resulting qualities
|
---|
31 | // Uncomment the following lines if you want to retrieve the best solution
|
---|
32 |
|
---|
33 | //var orderedSolutions = solutions.Zip(qualities, (i, q) => new { Solution = i, Quality = q }).OrderBy(z => z.Quality);
|
---|
34 | //var best = Maximization ? orderedSolutions.Last().Solution : orderedSolutions.First().Solution;
|
---|
35 |
|
---|
36 | //if (!results.ContainsKey("Best Solution")) {
|
---|
37 | // results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS)));
|
---|
38 | //}
|
---|
39 | //results["Best Solution"].Value = (IItem)best.Clone();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS solution, IRandom random) {
|
---|
43 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
44 | // Create new vectors, based on the given one that represent small changes
|
---|
45 | // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
|
---|
46 | while (true) {
|
---|
47 | // Algorithm will draw only a finite amount of samples
|
---|
48 | // Change to a for-loop to return a concrete amount of neighbors
|
---|
49 | var neighbor = (SOLUTION_CLASS)solution.Clone();
|
---|
50 | // modify the solution specified as neighbor
|
---|
51 | yield return neighbor;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | // Implement further classes and methods
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|