1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Individual {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
|
---|
8 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
9 | using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
|
---|
10 | using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator;
|
---|
11 |
|
---|
12 | public static class IndividualExtensions {
|
---|
13 |
|
---|
14 | public static PushProgram ToPushProgram(this Individual individual, IReadOnlyPushConfiguration config, IRandom random) {
|
---|
15 | return individual.IntegerVector().ToPushProgram(config, random);
|
---|
16 | }
|
---|
17 |
|
---|
18 | public static PushProgram ToPushProgram(this IntegerVector vector, IReadOnlyPushConfiguration config, IRandom random) {
|
---|
19 | //var currentIndex = 0;
|
---|
20 | //var close = 0;
|
---|
21 | var expressions = new List<Expression>(vector.Length);
|
---|
22 |
|
---|
23 | for (var i = vector.Length - 1; i >= 0; i--) {
|
---|
24 | var index = vector[i];
|
---|
25 |
|
---|
26 | if (index == PushSolutionEncoding.End)
|
---|
27 | break;
|
---|
28 |
|
---|
29 | // skip noops
|
---|
30 | if (index == PushSolutionEncoding.Noop)
|
---|
31 | continue;
|
---|
32 |
|
---|
33 | var expression = CodeGeneratorUtils.MapToExpression(
|
---|
34 | index,
|
---|
35 | random,
|
---|
36 | config.ErcOptions,
|
---|
37 | config);
|
---|
38 |
|
---|
39 | expressions.Add(expression);
|
---|
40 | }
|
---|
41 |
|
---|
42 | return new PushProgram(expressions);
|
---|
43 |
|
---|
44 | //using (var mapper = IndividualMapper.Create()) {
|
---|
45 | // return mapper.FromPlush(vector, ref currentIndex, ref close, 0, config, random);
|
---|
46 | //}
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|