Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File size: 1.9 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    public 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 virtual PushSolution Simplify() {
49      return new PushSolution(Program, Quality, Random, Config, Evaluator, true);
50    }
51
52    [StorableConstructor]
53    protected PushSolution(bool deserializing) : base(deserializing) { }
54
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new PushSolution(this, cloner);
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.