Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushSolution.cs @ 15273

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

#2665 Started Plush Encoding, Added Zero Error Individual Count Analyzer

File size: 2.0 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
2  using Common;
3  using Configuration;
4  using Core;
5  using Expressions;
6  using Persistence.Default.CompositeSerializers.Storable;
7
8  [StorableClass]
9  public class PushSolution : NamedItem {
10    [Storable]
11    public readonly double Quality;
12    [Storable]
13    protected readonly IRandom Random;
14    [Storable]
15    public readonly IReadOnlyPushConfiguration Config;
16    [Storable]
17    public readonly IPushEvaluator Evaluator;
18    [Storable]
19    protected readonly bool simplify;
20    [Storable]
21    public PushProgram Program;
22
23
24    public PushSolution(PushProgram program, double quality, IRandom random, IReadOnlyPushConfiguration config, IPushEvaluator evaluator, bool simplify = false)
25      : base("Solution", "A push solution.") {
26      Quality = quality;
27      Random = random;
28      Config = config;
29      Evaluator = evaluator;
30      this.simplify = simplify;
31
32      Program = simplify
33        ? Simplifier.Simplifier.Simplify(program, Config, p => Evaluator.EvaluateTraining(Config, p, Random).AvgQuality)
34        : program;
35
36    }
37
38    public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) {
39      Program = cloner.Clone(origin.Program);
40      Quality = origin.Quality;
41      Random = cloner.Clone(origin.Random);
42      Config = cloner.Clone(origin.Config);
43      Evaluator = cloner.Clone(origin.Evaluator);
44      Program = origin.Program; // push programs are immutable like all expressions
45      simplify = origin.simplify;
46    }
47
48    public IRandom GetRandom() {
49      return (IRandom)Random.Clone();
50    }
51
52    public virtual PushSolution Simplify() {
53      return new PushSolution(Program, Quality, Random, Config, Evaluator, true);
54    }
55
56    [StorableConstructor]
57    protected PushSolution(bool deserializing) : base(deserializing) { }
58
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new PushSolution(this, cloner);
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.