using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.ProgramSynthesis { [StorableClass] public class PushSolution : NamedItem, IPushSolution { [Storable] public readonly double Quality; [Storable] protected readonly IRandom Random; [Storable] public readonly IReadOnlyPushConfiguration Config; [Storable] public readonly IPushEvaluator Evaluator; [Storable] protected readonly bool simplify; [Storable] public PushProgram Program; public PushSolution(PushProgram program, double quality, IRandom random, IReadOnlyPushConfiguration config, IPushEvaluator evaluator, bool simplify = false) : base("Solution", "A push solution.") { Quality = quality; Random = random; Config = config; Evaluator = evaluator; this.simplify = simplify; Program = simplify ? Simplifier.Simplify(program, Config, p => Evaluator.EvaluateTraining(Config, p, Random).AvgQuality) : program; } public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) { Program = cloner.Clone(origin.Program); Quality = origin.Quality; Random = cloner.Clone(origin.Random); Config = cloner.Clone(origin.Config); Evaluator = cloner.Clone(origin.Evaluator); Program = origin.Program; // push programs are immutable like all expressions simplify = origin.simplify; } public IRandom GetRandom() { return (IRandom)Random.Clone(); } public virtual PushSolution Simplify() { return new PushSolution(Program, Quality, Random, Config, Evaluator, true); } [StorableConstructor] protected PushSolution(bool deserializing) : base(deserializing) { } public override IDeepCloneable Clone(Cloner cloner) { return new PushSolution(this, cloner); } } }