Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs @ 15275

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

#2665 Added PlushEncoding, ZeroErrorDistributionAnalzer

File size: 2.0 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
2  using System.Linq;
3
4  using HeuristicLab.Common;
5  using HeuristicLab.Core;
6  using HeuristicLab.Data;
7  using HeuristicLab.Optimization;
8  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
10  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
11  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
12
13  [StorableClass]
14  public abstract class PlushPushProblem : PushProblemBase<PlushEncoding> {
15    protected PlushPushProblem(IPushEvaluator evaluator)
16      : base(evaluator) {
17      InitEncoding();
18      InitOperators();
19    }
20
21    protected PlushPushProblem(bool deserializing)
22      : base(deserializing) {
23    }
24
25    protected PlushPushProblem(PushProblemBase<PlushEncoding> original, Cloner cloner)
26      : base(original, cloner) {
27    }
28
29    private void InitEncoding() {
30      Encoding.ErcOptionsParameter = Config.ErcOptionsParameter;
31      Encoding.InstructionsParameter = Config.InstructionsParameter;
32      Encoding.MaxLength = Config.MaxPointsInProgram;
33    }
34
35    private void InitOperators() {
36      if (!Operators.OfType<PushExpressionFrequencyAnalyzer>().Any()) {
37        Operators.Add(new PushExpressionFrequencyAnalyzer());
38      }
39
40      if (!Operators.OfType<IndividualZeroErrorAnalyzer>().Any()) {
41        Operators.Add(new IndividualZeroErrorAnalyzer());
42      }
43    }
44
45    protected override PushProgram MapIndividual(Individual individual, IRandom random) {
46      var plushVector = individual.PlushVector();
47      var program = plushVector.PushProgram;
48
49      return program;
50    }
51
52    public override double Evaluate(Individual individual, IRandom random) {
53      var program = MapIndividual(individual, random);
54      var result = PushEvaluator.EvaluateTraining(Pool, program, random);
55
56      individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
57
58      return result.AvgQuality;
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.