[15275] | 1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
|
---|
| 2 | using System.Linq;
|
---|
| 3 |
|
---|
| 4 | using HeuristicLab.Common;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
| 7 | using HeuristicLab.Optimization;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 | using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
|
---|
| 10 | using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
|
---|
| 11 | using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
|
---|
| 12 |
|
---|
| 13 | [StorableClass]
|
---|
| 14 | public abstract class PlushPushProblem : PushProblemBase<PlushEncoding> {
|
---|
| 15 | protected PlushPushProblem(IPushEvaluator evaluator)
|
---|
| 16 | : base(evaluator) {
|
---|
| 17 | InitEncoding();
|
---|
| 18 | InitOperators();
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | protected PlushPushProblem(bool deserializing)
|
---|
| 22 | : base(deserializing) {
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | protected PlushPushProblem(PushProblemBase<PlushEncoding> original, Cloner cloner)
|
---|
| 26 | : base(original, cloner) {
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | private void InitEncoding() {
|
---|
| 30 | Encoding.ErcOptionsParameter = Config.ErcOptionsParameter;
|
---|
| 31 | Encoding.InstructionsParameter = Config.InstructionsParameter;
|
---|
| 32 | Encoding.MaxLength = Config.MaxPointsInProgram;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | private void InitOperators() {
|
---|
| 36 | if (!Operators.OfType<PushExpressionFrequencyAnalyzer>().Any()) {
|
---|
| 37 | Operators.Add(new PushExpressionFrequencyAnalyzer());
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | if (!Operators.OfType<IndividualZeroErrorAnalyzer>().Any()) {
|
---|
| 41 | Operators.Add(new IndividualZeroErrorAnalyzer());
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | protected override PushProgram MapIndividual(Individual individual, IRandom random) {
|
---|
| 46 | var plushVector = individual.PlushVector();
|
---|
| 47 | var program = plushVector.PushProgram;
|
---|
| 48 |
|
---|
| 49 | return program;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public override double Evaluate(Individual individual, IRandom random) {
|
---|
| 53 | var program = MapIndividual(individual, random);
|
---|
| 54 | var result = PushEvaluator.EvaluateTraining(Pool, program, random);
|
---|
| 55 |
|
---|
| 56 | individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities);
|
---|
| 57 |
|
---|
| 58 | return result.AvgQuality;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|