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

Last change on this file since 14777 was 14777, checked in by pkimmesw, 3 years ago

#2665 simplifier, push solution results view, performance improvements, small bug fixes, ui fixes

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