1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | namespace 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 | }
|
---|