Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 17:27:35 (8 years ago)
Author:
abeham
Message:

#2521: adapted templates, fixed missing reference in outdated plugin lawnmower

File:
1 copied

Legend:

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

    r13363 r13373  
    55using HeuristicLab.Core;
    66using HeuristicLab.Data;
    7 using ENCODING_NAMESPACE;
    87using HeuristicLab.Optimization;
    98using HeuristicLab.Problems.Programmable;
     9//using HeuristicLab.Encodings.BinaryVectorEncoding;
     10//using HeuristicLab.Encodings.IntegerVectorEncoding;
     11//using HeuristicLab.Encodings.RealVectorEncoding;
     12//using HeuristicLab.Encodings.PermutationEncoding;
     13//using HeuristicLab.Encodings.LinearLinkageEncoding;
     14//using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    1015
    1116namespace HeuristicLab.Problems.Programmable {
    12   public class CompiledSingleObjectiveProblemDefinition : CompiledMultiObjectiveProblemDefinition<ENCODING_CLASS, SOLUTION_CLASS> {
    13     public override bool[] Maximization { get { return new[] { false, false }; } }
     17  public class CompiledSingleObjectiveProblemDefinition : CompiledMultiObjectiveProblemDefinition<CombinedEncoding, CombinedSolution> {
     18    public override bool[] Maximization { get { return new[] { true, false }; } }
    1419
    1520    public override void Initialize() {
     
    1722      // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property
    1823      // Add additional initialization code e.g. private variables that you need for evaluating
     24      //Encoding.Add(new BinaryVectorEncoding("b") { Length = 10 });
     25      //Encoding.Add(new IntegerVectorEncoding("i") { Length = 10, Bounds = new int[,] { { -100, 100 } } });
     26      //Encoding.Add(new RealVectorEncoding("r") { Length = 10, Bounds = new double[,] { { -100, 100 } } });
     27      //Encoding.Add(new PermutationEncoding("p") { Length = 20, PermutationType = PermutationTypes.Absolute });
     28      //Encoding.Add(new LinearLinkageEncoding("lle") { Length = 30 });
     29      //Encoding.Add(new SymbolicExpressionTreeEncoding("tree") { ... });
    1930    }
    2031
    21     public override double[] Evaluate(SOLUTION_CLASS solution, IRandom random) {
     32    public override double[] Evaluate(CombinedSolution solution, IRandom random) {
    2233      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    2334      var quality = new[] { 0.0, 0.0 };
     35      // var b = solution.GetSolution<BinaryVector>("b");
     36      // quality[0] = b.Count(x => x); // one max!
     37      // var r = solution.GetSolution<RealVector>("r");
     38      // quality[1] = r.Select((i, v) => new { Idx = i, Val = v }).Sum(x => b[x.Idx] ? x.Val * x.Val : 0.0); // sphere
     39
     40      // NOTE: Check the Maximization property above (true or false)!
    2441      return quality;
    2542    }
    2643
    27     public override void Analyze(SOLUTION_CLASS[] solution, double[][] qualities, ResultCollection results, IRandom random) {
     44    public override void Analyze(CombinedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random) {
    2845      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    2946      // 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
    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")) {
    36       //  results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS)));
    37       //}
    38       //results["Best Solution"].Value = (IItem)best.Clone();
     47      // Uncomment the following lines if you want to retrieve the best solution
    3948    }
    4049
    41     public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {
     50    public override IEnumerable<CombinedSolution> GetNeighbors(CombinedSolution solution, IRandom random) {
    4251      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    4352      // Create new vectors, based on the given one that represent small changes
     
    4655        // Algorithm will draw only a finite amount of samples
    4756        // Change to a for-loop to return a concrete amount of neighbors
    48         var neighbor = (SOLUTION_CLASS)individual.Clone();
     57        var neighbor = (CombinedSolution)solution.Clone();
    4958        // modify the solution specified as neighbor
    5059        yield return neighbor;
Note: See TracChangeset for help on using the changeset viewer.