Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs @ 17603

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

#2665 Testet Problems, Improved Performance

File size: 3.4 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    }
62
63    private void InitOperators() {
64
65      var solutionCreator = Operators.OfType<PushSolutionCreator>().FirstOrDefault();
66
67      if (solutionCreator == null) {
68        solutionCreator = new PushSolutionCreator();
69        Operators.Add(solutionCreator);
70      }
71
72      solutionCreator.ErcOptions = Config.ErcOptions;
73      solutionCreator.MinLength = Config.MinProgramLength;
74
75      if (!Operators.OfType<PushExpressionFrequencyAnalyzer>().Any()) {
76        Operators.Add(new PushExpressionFrequencyAnalyzer());
77      }
78
79      if (!Operators.OfType<IndividualZeroErrorAnalyzer>().Any()) {
80        Operators.Add(new IndividualZeroErrorAnalyzer());
81      }
82
83      SolutionCreator = solutionCreator;
84    }
85
86    protected override PushProgram MapIndividual(Individual individual) {
87      var program = individual.ToPushProgram(Config);
88
89      return program;
90    }
91
92    //public override double Evaluate(Individual individual, IRandom random) {
93    //  var seed = random.Next();
94
95    //  var program = individual.ToPushProgram(Config);
96
97    //  var rand = new FastRandom(seed);
98    //  var result = PushEvaluator.EvaluateTraining(Pool, program, rand);
99
100    //  individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
101    //  individual[SeedScopeParameterName] = new IntValue(seed);
102
103    //  return result.AvgQuality;
104    //}
105  }
106}
Note: See TracBrowser for help on using the repository browser.