Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/15 18:38:37 (9 years ago)
Author:
mkommend
Message:

#2521: refactored programmable problem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledSingleObjectiveProblemDefinition.cs

    r12731 r13345  
    55using HeuristicLab.Core;
    66using HeuristicLab.Data;
    7 using HeuristicLab.Encodings.BinaryVectorEncoding;
    8 using HeuristicLab.Encodings.IntegerVectorEncoding;
    9 using HeuristicLab.Encodings.RealVectorEncoding;
    10 using HeuristicLab.Encodings.PermutationEncoding;
    11 using HeuristicLab.Encodings.LinearLinkageEncoding;
    12 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     7using {0}
    138using HeuristicLab.Optimization;
    149using HeuristicLab.Problems.Programmable;
    1510
    1611namespace HeuristicLab.Problems.Programmable {
    17   public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
     12  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition<{1}, {2}>, ISingleObjectiveProblemDefinition<{1}, {2}> {
    1813    public bool Maximization { get { return false; } }
    1914
    2015    public override void Initialize() {
    2116      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    22       // Define the solution encoding which can also consist of multiple vectors, examples below
    23       //Encoding = new BinaryVectorEncoding("b", length: 5);
    24       //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
    25       //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
    26       //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    27       //Encoding = new LinearLinkageEncoding("l", length: 5);
    28       //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12);
    29       // The encoding can also be a combination
    30       //Encoding = new MultiEncoding()
    31       //.Add(new BinaryVectorEncoding("b", length: 5))
    32       //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
    33       //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
    34       //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    35       //.Add(new LinearLinkageEncoding("l", length: 5))
    36       //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12))
    37       ;
     17      // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
    3818      // Add additional initialization code e.g. private variables that you need for evaluating
    3919    }
    4020
    41     public double Evaluate(Individual individual, IRandom random) {
     21    public double Evaluate({2} individual, IRandom random) {
    4222      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    4323      var quality = 0.0;
    44       //quality = individual.RealVector("r").Sum(x => x * x);
    4524      return quality;
    4625    }
    4726
    48     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     27    public void Analyze({2}[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    4928      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    5029      // Write or update results given the range of vectors and resulting qualities
     
    5534
    5635      //if (!results.ContainsKey("Best Solution")) {
    57       //  results.Add(new Result("Best Solution", typeof(RealVector)));
     36      //  results.Add(new Result("Best Solution", typeof({20)));
    5837      //}
    59       //results["Best Solution"].Value = (IItem)best.RealVector("r").Clone();
     38      //results["Best Solution"].Value = (IItem)best.Clone();
    6039    }
    6140
    62     public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     41    public IEnumerable<{2}> GetNeighbors({2} individual, IRandom random) {
    6342      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    6443      // Create new vectors, based on the given one that represent small changes
     
    6746        // Algorithm will draw only a finite amount of samples
    6847        // Change to a for-loop to return a concrete amount of neighbors
    69         var neighbor = individual.Copy();
    70         // For instance, perform a single bit-flip in a binary parameter
    71         //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
    72         //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
     48        var neighbor = ({2})individual.Clone();
     49        // modify the solution specified as neighbor
    7350        yield return neighbor;
    7451      }
Note: See TracChangeset for help on using the changeset viewer.