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