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