Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Programmable/3.3/Templates/CompiledMultiObjectiveProblemDefinition.cs @ 13346

Last change on this file since 13346 was 12731, checked in by abeham, 9 years ago

#2426:

  • fixed template for multi-encoding
File size: 2.8 KB
RevLine 
[11767]1using System;
2using System.Linq;
3using System.Collections.Generic;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
[11949]7using HeuristicLab.Encodings.BinaryVectorEncoding;
8using HeuristicLab.Encodings.IntegerVectorEncoding;
[12731]9using HeuristicLab.Encodings.RealVectorEncoding;
[11767]10using HeuristicLab.Encodings.PermutationEncoding;
[12731]11using HeuristicLab.Encodings.LinearLinkageEncoding;
[12724]12using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[11753]13using HeuristicLab.Optimization;
[11767]14using HeuristicLab.Problems.Programmable;
[11753]15
16namespace HeuristicLab.Problems.Programmable {
17  public class CompiledMultiObjectiveProblemDefinition : CompiledProblemDefinition, IMultiObjectiveProblemDefinition {
18    public bool[] Maximization { get { return new[] { false, false }; } }
19
20    public override void Initialize() {
[11880]21      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
[11753]22      // Define the solution encoding which can also consist of multiple vectors, examples below
[11900]23      //Encoding = new BinaryVectorEncoding("b", length: 5);
24      //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4);
25      //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
[11753]26      //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
[12724]27      //Encoding = new LinearLinkageEncoding("l", length: 5);
28      //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12);
[11880]29      // The encoding can also be a combination
[11753]30      //Encoding = new MultiEncoding()
[11900]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))
[11753]34      //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
[12731]35      //.Add(new LinearLinkageEncoding("l", length: 5))
36      //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12))
[11753]37      ;
[11880]38      // Add additional initialization code e.g. private variables that you need for evaluating
[11753]39    }
40
41    public double[] Evaluate(Individual individual, IRandom random) {
[11880]42      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
[11753]43      var qualities = new[] { 0.0, 0.0 };
[11880]44      //qualities = new [] { individual.RealVector("r").Sum(x => x * x), individual.RealVector("r").Sum(x => x * x * x) };
[11753]45      return qualities;
46    }
47
[11880]48    public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) {
49      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
50      // Write or update results given the range of vectors and resulting qualities
[11753]51    }
[11880]52    // Implement further classes and methods
[11753]53  }
54}
55
Note: See TracBrowser for help on using the repository browser.