Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushEncoding.cs @ 14746

Last change on this file since 14746 was 14746, checked in by pkimmesw, 7 years ago

#2665 PooledPushProgram reduces memory usage and increases performance

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
5  using System.Linq;
6
7  using HeuristicLab.Common;
8  using HeuristicLab.Core;
9  using HeuristicLab.Encodings.IntegerVectorEncoding;
10  using HeuristicLab.Optimization;
11  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12  using HeuristicLab.Problems.ProgramSynthesis.Push.Creator;
13  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
14
15  [Item("PushEncoding", "Describes a push program encoding.")]
16  [StorableClass]
17  public sealed class PushEncoding : Encoding<IPushProgramCreator> {
18
19    [StorableConstructor]
20    public PushEncoding(bool deserializing)
21      : base(deserializing) {
22    }
23
24    public PushEncoding(PushEncoding origin, Cloner cloner)
25      : base(origin, cloner) {
26
27    }
28
29    public override IDeepCloneable Clone(Cloner cloner) {
30      return new PushEncoding(this, cloner);
31    }
32
33    public override void ConfigureOperators(IEnumerable<IOperator> operators) {
34      throw new NotImplementedException();
35    }
36  }
37
38  public static class IndividualExtensionMethods {
39    public static PushProgram PushProgram(this Individual individual, IReadOnlyList<string> enabledExpressions) {
40      return individual.IntegerVector().MapToPushProgram(enabledExpressions);
41    }
42
43    public static PushProgram MapToPushProgram(this IntegerVector vector, IReadOnlyList<string> enabledExpressions) {
44      //var expressions = vector
45      //  .Select(i => ExpressionTable.GetExpression(enabledExpressions[i]))
46      //  .ToArray();
47
48      var expressions = new Expression[vector.Length];
49      for (var i = 0; i < vector.Length; i++)
50      {
51        expressions[i] = ExpressionTable.GetExpression(enabledExpressions[vector[i]]);
52      }
53
54      return new Expressions.PushProgram(expressions);
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.