[11753] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 | using HeuristicLab.Common;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
[13348] | 7 | using ENCODING_NAMESPACE;
|
---|
[11753] | 8 | using HeuristicLab.Optimization;
|
---|
| 9 | using HeuristicLab.Problems.Programmable;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Problems.Programmable {
|
---|
[13348] | 12 | public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<ENCODING_CLASS, SOLUTION_CLASS> {
|
---|
| 13 | public override bool Maximization { get { return false; } }
|
---|
[11753] | 14 |
|
---|
| 15 | public override void Initialize() {
|
---|
[11880] | 16 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
[13345] | 17 | // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
|
---|
[11880] | 18 | // Add additional initialization code e.g. private variables that you need for evaluating
|
---|
[11753] | 19 | }
|
---|
| 20 |
|
---|
[13348] | 21 | public override double Evaluate(SOLUTION_CLASS solution, IRandom random) {
|
---|
[11880] | 22 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
[11753] | 23 | var quality = 0.0;
|
---|
| 24 | return quality;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[13348] | 27 | public override void Analyze(SOLUTION_CLASS[] solution, double[] qualities, ResultCollection results, IRandom random) {
|
---|
[11880] | 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
|
---|
[12001] | 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")) {
|
---|
[13348] | 36 | // results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS)));
|
---|
[12001] | 37 | //}
|
---|
[13345] | 38 | //results["Best Solution"].Value = (IItem)best.Clone();
|
---|
[11753] | 39 | }
|
---|
| 40 |
|
---|
[13348] | 41 | public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {
|
---|
[11880] | 42 | // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
|
---|
[11753] | 43 | // Create new vectors, based on the given one that represent small changes
|
---|
[11880] | 44 | // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
|
---|
[11753] | 45 | while (true) {
|
---|
[11880] | 46 | // Algorithm will draw only a finite amount of samples
|
---|
| 47 | // Change to a for-loop to return a concrete amount of neighbors
|
---|
[13348] | 48 | var neighbor = (SOLUTION_CLASS)individual.Clone();
|
---|
[13345] | 49 | // modify the solution specified as neighbor
|
---|
[11753] | 50 | yield return neighbor;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[11880] | 54 | // Implement further classes and methods
|
---|
[11753] | 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|