Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Solution/PushSolution.cs @ 16724

Last change on this file since 16724 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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