Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

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