namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { using System.Linq; using Common; using Configuration; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; using HeuristicLab.Problems.ProgramSynthesis.Push.Evaluator; using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator; using Optimization; using Persistence.Default.CompositeSerializers.Storable; [StorableClass] public abstract class IntegerVectorPushProblem : PushProblemBase { protected IntegerVectorPushProblem(IPushEvaluator evaluator) : base(evaluator) { InitEvents(); InitEncoding(); InitOperators(); } [StorableConstructor] protected IntegerVectorPushProblem(bool deserializing) : base(deserializing) { } protected IntegerVectorPushProblem(IntegerVectorPushProblem original, Cloner cloner) : base(original, cloner) { InitEvents(); } [StorableHook(HookType.AfterDeserialization)] // ReSharper disable once UnusedMember.Local private void AfterDeserialization() { InitEvents(); } private void InitEvents() { Config.EnabledExpressionsChanged += EnabledExpressionsChanged; } private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) { Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count; Encoding.BoundsParameter.Value[0, 1] = Config.EnabledExpressions.Count; } //protected override void OnReset() { // base.OnReset(); // // clear pools and free reserved memory // Pool.Clear(); // IndividualMapper.Clear(); // RandomPool.Clear(); //} private void InitEncoding() { Encoding.Bounds[0, 0] = 0; Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count; Encoding.Length = Config.MaxPointsInProgram; } private void InitOperators() { var solutionCreator = Operators.OfType().FirstOrDefault(); if (solutionCreator == null) { solutionCreator = new PushSolutionCreator(); Operators.Add(solutionCreator); } solutionCreator.ErcOptions = Config.ErcOptions; if (!Operators.OfType().Any()) { Operators.Add(new PushExpressionFrequencyAnalyzer()); } SolutionCreator = solutionCreator; } protected override PushProgram MapIndividual(Individual individual) { var program = individual.ToPushProgram(Config); return program; } //public override double Evaluate(Individual individual, IRandom random) { // var seed = random.Next(); // var program = individual.ToPushProgram(Config); // var rand = new FastRandom(seed); // var result = PushEvaluator.EvaluateTraining(Pool, program, rand); // individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); // individual[SeedScopeParameterName] = new IntValue(seed); // return result.AvgQuality; //} } }