namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; [StorableClass] public abstract class PlushPushProblem : PushProblemBase { protected PlushPushProblem(IPushEvaluator evaluator) : base(evaluator) { InitEncoding(); InitOperators(); } protected PlushPushProblem(bool deserializing) : base(deserializing) { } protected PlushPushProblem(PushProblemBase original, Cloner cloner) : base(original, cloner) { } private void InitEncoding() { Encoding.ErcOptionsParameter = Config.ErcOptionsParameter; Encoding.InstructionsParameter = Config.InstructionsParameter; Encoding.MaxLength = Config.MaxPointsInProgram; } private void InitOperators() { if (!Operators.OfType().Any()) { Operators.Add(new PushExpressionFrequencyAnalyzer()); } if (!Operators.OfType().Any()) { Operators.Add(new IndividualZeroErrorAnalyzer()); } } protected override PushProgram MapIndividual(Individual individual, IRandom random) { var plushVector = individual.PlushVector(); var program = plushVector.PushProgram; return program; } public override double Evaluate(Individual individual, IRandom random) { var program = MapIndividual(individual, random); var result = PushEvaluator.EvaluateTraining(Pool, program, random); individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); return result.AvgQuality; } } }