Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs @ 15289

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

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

File size: 3.2 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
2  using System.Linq;
3
4  using Common;
5  using Configuration;
6  using HeuristicLab.Encodings.IntegerVectorEncoding;
7  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
8  using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator;
9  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
10  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
11  using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator;
12
13  using Optimization;
14  using Persistence.Default.CompositeSerializers.Storable;
15
16  [StorableClass]
17  public abstract class IntegerVectorPushProblem : PushProblemBase<IntegerVectorEncoding> {
18    protected IntegerVectorPushProblem(IPushEvaluator evaluator) : base(evaluator) {
19      InitEvents();
20      InitEncoding();
21      InitOperators();
22    }
23
24    [StorableConstructor]
25    protected IntegerVectorPushProblem(bool deserializing)
26      : base(deserializing) {
27    }
28
29    protected IntegerVectorPushProblem(IntegerVectorPushProblem original, Cloner cloner)
30      : base(original, cloner) {
31      InitEvents();
32    }
33
34    [StorableHook(HookType.AfterDeserialization)]
35    // ReSharper disable once UnusedMember.Local
36    private void AfterDeserialization() {
37      InitEvents();
38    }
39
40    private void InitEvents() {
41      Config.EnabledExpressionsChanged += EnabledExpressionsChanged;
42    }
43
44    private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) {
45      Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count;
46      Encoding.BoundsParameter.Value[0, 1] = Config.EnabledExpressions.Count;
47    }
48
49    //protected override void OnReset() {
50    //  base.OnReset();
51
52    //  // clear pools and free reserved memory
53    //  Pool.Clear();
54    //  IndividualMapper.Clear();
55    //  RandomPool.Clear();
56    //}
57
58    private void InitEncoding() {
59      Encoding.Bounds[0, 0] = 0;
60      Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count;
61      Encoding.Length = Config.MaxPointsInProgram;
62    }
63
64    private void InitOperators() {
65
66      var solutionCreator = Operators.OfType<PushSolutionCreator>().FirstOrDefault();
67
68      if (solutionCreator == null) {
69        solutionCreator = new PushSolutionCreator();
70        Operators.Add(solutionCreator);
71      }
72
73      solutionCreator.ErcOptions = Config.ErcOptions;
74
75      if (!Operators.OfType<PushExpressionFrequencyAnalyzer>().Any()) {
76        Operators.Add(new PushExpressionFrequencyAnalyzer());
77      }
78
79      SolutionCreator = solutionCreator;
80    }
81
82    protected override PushProgram MapIndividual(Individual individual) {
83      var program = individual.ToPushProgram(Config);
84
85      return program;
86    }
87
88    //public override double Evaluate(Individual individual, IRandom random) {
89    //  var seed = random.Next();
90
91    //  var program = individual.ToPushProgram(Config);
92
93    //  var rand = new FastRandom(seed);
94    //  var result = PushEvaluator.EvaluateTraining(Pool, program, rand);
95
96    //  individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
97    //  individual[SeedScopeParameterName] = new IntValue(seed);
98
99    //  return result.AvgQuality;
100    //}
101  }
102}
Note: See TracBrowser for help on using the repository browser.