- Timestamp:
- 04/28/17 22:52:08 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push
- Files:
-
- 14 added
- 6 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs
r14875 r14897 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration { 2 2 using System.Collections.Generic; 3 4 using HeuristicLab.Common; 5 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 3 using Base.Erc; 4 using Common; 5 using Stack; 7 6 8 7 public interface IReadOnlyPushConfiguration : IDeepCloneable { … … 12 11 int MaxStringLength { get; } 13 12 int MaxVectorLength { get; } 13 int MinPointsInProgram { get; } 14 14 int MaxPointsInProgram { get; } 15 15 int MaxPointsInRandomExpression { get; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r14875 r14897 5 5 using Attributes; 6 6 using Base.Erc; 7 using Base.Erc.Interfaces;8 7 using Common; 9 8 using Core; … … 14 13 [StorableClass] 15 14 public class PushConfiguration : ParameterizedNamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration { 16 17 18 19 15 public PushConfiguration() { 20 16 Name = "Push Configuration"; … … 25 21 ErcOptions = new ErcOptions(); 26 22 EvalPushLimit = 1024; 27 MaxPointsInProgram = 128; 23 MinPointsInProgram = 25; 24 MaxPointsInProgram = 200; 28 25 TopLevelPushCode = true; 29 26 TopLevelPopCode = false; 30 27 MaxPointsInRandomExpression = 64; 31 MaxStringLength = 32;28 MaxStringLength = 128; 32 29 MaxVectorLength = 64; 33 30 MaxDepth = 32; … … 38 35 private void InitEnabledStacks(bool state = true) { 39 36 foreach (StackTypes type in Enum.GetValues(typeof(StackTypes))) { 40 if (!enabledStacks.ContainsKey(type) )37 if (!enabledStacks.ContainsKey(type) && type != StackTypes.None) 41 38 enabledStacks.Add(type, state); 42 39 } … … 54 51 ErcOptions = cloner.Clone(origin.ErcOptions); 55 52 EvalPushLimit = origin.EvalPushLimit; 53 MinPointsInProgram = origin.MinPointsInProgram; 56 54 MaxPointsInProgram = origin.MaxPointsInProgram; 57 55 MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression; … … 72 70 73 71 [Storable] 74 private Dictionary<StackTypes, bool> enabledStacks;72 private readonly Dictionary<StackTypes, bool> enabledStacks; 75 73 76 74 public IReadOnlyDictionary<StackTypes, bool> EnabledStacks { get { return enabledStacks; } } … … 122 120 123 121 /// <summary> 122 /// This is the minimum size of an item on the CODE stack, expressed as a number of points. 123 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be 124 /// exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 125 /// instruction. 126 /// </summary> 127 [Storable] 128 public int MinPointsInProgram { get; set; } 129 130 /// <summary> 124 131 /// This is the maximum size of an item on the CODE stack, expressed as a number of points. 125 132 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be 126 /// exceeded 127 /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 133 /// exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 128 134 /// instruction. 129 135 /// </summary> … … 155 161 [Storable] 156 162 public int MaxVectorLength { get; set; } 163 164 165 public void SetEnabledStacks(StackTypes types) { 166 // Disable all 167 EnabledExpressions.Clear(); 168 169 // Enable those are required 170 foreach (StackTypes type in Enum.GetValues(types.GetType())) { 171 if (type == StackTypes.None) continue; 172 173 enabledStacks[type] = false; 174 175 if (types.HasFlag(type)) 176 EnableStack(type, true); 177 } 178 } 157 179 158 180 public void EnableExpressionOfStack(StackTypes types) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EqualsExpressions.cs
r14875 r14897 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using System.Collections.Generic; 3 4 using HeuristicLab.Common; 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 3 using Attributes; 4 using Common; 5 using Interpreter; 6 using Stack; 8 7 9 8 /// <summary> -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RandExpressions.cs
r14834 r14897 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators;4 3 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 5 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 6 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 7 using HeuristicLab.Random;8 6 9 7 /// <summary> … … 16 14 return false; 17 15 18 var name = interpreter.CustomExpressions.Count == 0 || interpreter.Random.NextDouble() < interpreter.Configuration.ErcOptions.NameErcOptions.NewNameProbability 19 ? ErcUtils.GetName(interpreter.Configuration.ErcOptions.NameErcOptions, interpreter.Random) 20 : interpreter.CustomExpressions.Keys.SampleRandom(interpreter.Random); 21 16 var name = interpreter.Configuration.ErcOptions.NameErcOptions.GetErcValue(interpreter.Random); 22 17 interpreter.NameStack.Push(name); 23 18 return true; … … 34 29 return false; 35 30 36 var value = ErcUtils.GetInteger(interpreter.Configuration.ErcOptions.IntegerErcOptions,interpreter.Random);31 var value = interpreter.Configuration.ErcOptions.IntegerErcOptions.GetErcValue(interpreter.Random); 37 32 interpreter.IntegerStack.Push(value); 38 33 return true; … … 49 44 return false; 50 45 51 var value = ErcUtils.GetDouble(interpreter.Configuration.ErcOptions.FloatErcOptions,interpreter.Random);46 var value = interpreter.Configuration.ErcOptions.FloatErcOptions.GetErcValue(interpreter.Random); 52 47 interpreter.FloatStack.Push(value); 53 48 return true; … … 64 59 return false; 65 60 66 var value = ErcUtils.GetBoolean(interpreter.Configuration.ErcOptions.BooleanErcOptions,interpreter.Random);61 var value = interpreter.Configuration.ErcOptions.BooleanErcOptions.GetErcValue(interpreter.Random); 67 62 interpreter.BooleanStack.Push(value); 68 63 return true; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs
r14875 r14897 3 3 4 4 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator { 5 using Core; 6 using Expressions; 5 7 6 using HeuristicLab.Core; 7 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces; 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 8 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 9 10 using Stack; 10 11 11 12 internal static class CodeGeneratorUtils { … … 19 20 20 21 return index >= enabledExpressions.Count 21 ? customExpressions. ElementAt(index - (enabledExpressions.Count - 1)).Value22 ? customExpressions.Values.ElementAt(index - enabledExpressions.Count) 22 23 : CreateExpressionOrErc(index, random, enabledExpressions, ercOptions); 23 24 } … … 55 56 } 56 57 58 private static readonly Expression Noop = ExpressionTable.GetStatelessExpression<ExecNoopExpression>(); 57 59 /// <summary> 58 60 /// Create a ErcExpression whereby the type of the expression conforms to the passed stack type. … … 65 67 switch (type) { 66 68 case StackTypes.Integer: 67 if (ercOptions.IntegerErcOptions == null || !ercOptions.IntegerErcOptions.IsEnabled) 68 return ExpressionTable.GetStatelessExpression<ExecNoopExpression>(); 69 70 var intValue = ErcUtils.GetInteger(ercOptions.IntegerErcOptions, random); 71 72 return new IntegerPushExpression(intValue); 69 return ercOptions.IntegerErcOptions == null || !ercOptions.IntegerErcOptions.IsEnabled 70 ? Noop 71 : new IntegerPushExpression(ercOptions.IntegerErcOptions.GetErcValue(random)); 73 72 74 73 case StackTypes.Float: 75 if (ercOptions.FloatErcOptions == null || !ercOptions.FloatErcOptions.IsEnabled) 76 return ExpressionTable.GetStatelessExpression<ExecNoopExpression>(); 77 78 var doubleValue = ErcUtils.GetDouble(ercOptions.FloatErcOptions, random); 79 80 return new FloatPushExpression(doubleValue); 74 return ercOptions.FloatErcOptions == null || !ercOptions.FloatErcOptions.IsEnabled 75 ? Noop 76 : new FloatPushExpression(ercOptions.FloatErcOptions.GetErcValue(random)); 81 77 82 78 case StackTypes.Boolean: 83 79 return ercOptions.BooleanErcOptions == null || !ercOptions.BooleanErcOptions.IsEnabled 84 ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()85 : new BooleanPushExpression( ErcUtils.GetBoolean(ercOptions.BooleanErcOptions,random));80 ? Noop 81 : new BooleanPushExpression(ercOptions.BooleanErcOptions.GetErcValue(random)); 86 82 87 83 case StackTypes.Name: 88 84 return ercOptions.NameErcOptions == null || !ercOptions.NameErcOptions.IsEnabled 89 ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()90 : new NamePushExpression( ErcUtils.GetName(ercOptions.NameErcOptions,random));85 ? Noop 86 : new NamePushExpression(ercOptions.NameErcOptions.GetErcValue(random)); 91 87 92 88 case StackTypes.String: 93 89 return ercOptions.StringErcOptions == null || !ercOptions.StringErcOptions.IsEnabled 94 ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()95 : new StringPushExpression( ErcUtils.GetString(ercOptions.StringErcOptions,random));90 ? Noop 91 : new StringPushExpression(ercOptions.StringErcOptions.GetErcValue(random)); 96 92 97 93 case StackTypes.Char: 98 94 return ercOptions.CharErcOptions == null || !ercOptions.CharErcOptions.IsEnabled 99 ? ExpressionTable.GetStatelessExpression<ExecNoopExpression>()100 : new CharPushExpression( ErcUtils.GetChar(ercOptions.CharErcOptions,random));95 ? Noop 96 : new CharPushExpression(ercOptions.CharErcOptions.GetErcValue(random)); 101 97 102 98 default: 103 return ExpressionTable.GetStatelessExpression<ExecNoopExpression>();99 return Noop; 104 100 } 105 101 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs
r14834 r14897 24 24 IPushStack<List<bool>> BooleanVectorStack { get; } 25 25 IPushStack<List<string>> StringVectorStack { get; } 26 IPushStack<string> PrintStack { get; } 26 27 IDictionary<string, Expression> CustomExpressions { get; } 27 28 IReadOnlyPushConfiguration Configuration { get; } 28 29 void Clear(); 30 void Reset(); 29 31 void Run(string code, bool stepwise = false); 30 32 void Run(Expression expression, bool stepwise = false); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14875 r14897 73 73 }; 74 74 75 PrintStack = new PushStack<string> { 76 IsEnabled = Configuration.EnabledStacks[StackTypes.Print] 77 }; 78 75 79 CustomExpressions = new Dictionary<string, Expression>(); 76 80 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); … … 155 159 [PushStack(StackTypes.StringVector)] 156 160 public IPushStack<List<string>> StringVectorStack { get; private set; } 161 162 [PushStack(StackTypes.Print)] 163 public IPushStack<string> PrintStack { get; private set; } 157 164 158 165 public IDictionary<string, Expression> CustomExpressions { get; private set; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/EvaluationResult.cs
r14834 r14897 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem 8 { 9 public class EvaluationResult 10 { 11 public EvaluationResult(int exampleCount) 12 { 13 ExampleQualities = new double[exampleCount]; 14 } 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { 2 public class EvaluationResult { 3 public EvaluationResult(int exampleCount) { 4 ExampleQualities = new double[exampleCount]; 5 } 15 6 16 7 17 18 19 8 public double TotalQuality { get; set; } 9 public double[] ExampleQualities { get; set; } 10 } 20 11 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IndividualMapper.cs
r14875 r14897 43 43 44 44 private static PushProgram ToPushProgram(this IntegerVector vector, IReadOnlyPushConfiguration config, IRandom random) { 45 var expressions = new Expression[vector.Length];46 45 var enabledExpressions = config.EnabledExpressions; 47 46 var ercOptions = config.ErcOptions; 47 //var programLength = random.Next(config.MinPointsInProgram, config.MaxPointsInProgram + 1); 48 var expressions = new Expression[vector.Length]; 48 49 49 50 for (var i = 0; i < vector.Length; i++) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r14875 r14897 2 2 3 3 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { 4 using System.Collections.Generic;5 4 using System.Linq; 6 using BenchmarkSuite.Problems; 5 7 6 using Common; 8 7 using Configuration; … … 10 9 using Data.Pool; 11 10 using Encodings.IntegerVectorEncoding; 12 using Expressions;13 11 using HeuristicLab.Data; 14 12 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 15 16 using Instances; 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite; 14 17 15 using Interpreter; 18 16 using Optimization; … … 20 18 using Persistence.Default.CompositeSerializers.Storable; 21 19 using Random; 22 using Stack;23 20 24 21 [StorableClass] 25 [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 180)] 26 [Item("Push Problem", "")] 27 public class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding>, IProblemInstanceConsumer<ProblemData> { 22 public abstract class PushProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding> { 28 23 [Storable] 29 private readonly PushConfiguration config; 30 private PushInterpreterPool pool; 31 private readonly ObjectPool<IRandom> randomPool = new ObjectPool<IRandom>(() => new MersenneTwister()); 24 protected readonly PushConfiguration config; 25 protected PushInterpreterPool pool; 26 protected readonly ObjectPool<IRandom> randomPool = new ObjectPool<IRandom>(() => new MersenneTwister()); 27 28 [Storable] 29 protected readonly IPushEvaluator PushEvaluator; 32 30 33 31 public const string CaseQualitiesScopeParameterName = "CaseQualities"; … … 35 33 private const string TestQualityResultName = "Test Quality"; 36 34 37 p ublic PushProblem() {35 protected PushProblem(PushBenchmarkSuiteEvaluator evaluator) { 38 36 config = new PushConfiguration(); 37 PushEvaluator = evaluator; 39 38 40 39 InitData(); … … 44 43 45 44 [StorableConstructor] 46 p ublicPushProblem(bool deserializing)45 protected PushProblem(bool deserializing) 47 46 : base(deserializing) { 48 47 } 49 48 50 p ublicPushProblem(PushProblem original, Cloner cloner)49 protected PushProblem(PushProblem original, Cloner cloner) 51 50 : base(original, cloner) { 52 51 config = cloner.Clone(original.config); 52 PushEvaluator = cloner.Clone(original.PushEvaluator); 53 53 54 54 InitData(); … … 78 78 #region Parameters 79 79 80 private const string DataBoundsParameterName = "DataBounds";81 private const string DataParameterName = "Data";82 private const string DataParameterDescription = "Program Synthesis";83 80 private const string InstructionsParameterName = "Instructions"; 84 81 private const string InstructionsParameterDescription = "Enables/Disables Instructions"; 85 82 private const string EvalPushLimitParameterName = "EvalPushLimit"; 86 83 private const string EvalPushLimitParameterDescription = "This is the maximum allowed number of \"executions\" in a single top-level call to the interpreter. The execution of a single Push instruction counts as one execution, as does the processing of a single literal, as does the descent into one layer of parentheses (that is, the processing of the \"(\" counts as one execution)."; 84 private const string MinPointsInProgramParameterName = "MinProgramLength"; 85 private const string MinProgramLengthParameterDescription = "This is the minimum size of an item on the CODE/EXEC stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses."; 87 86 private const string MaxPointsInProgramParameterName = "MaxProgramLength"; 88 private const string MaxProgramLengthParameterDescription = "This is the maximum size of an item on the CODE stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses.";87 private const string MaxProgramLengthParameterDescription = "This is the maximum size of an item on the CODE/EXEC stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses."; 89 88 private const string TopLevelPushCodeParameterName = "TopLevelPushCode"; 90 89 private const string TopLevelPushCodeParameterDescription = "When TRUE (which is the default), code passed to the top level of the interpreter will be pushed onto the CODE stack prior to execution."; … … 98 97 99 98 private void InitParameters() { 100 Parameters.Add(new FixedValueParameter<DataBounds>(DataBoundsParameterName));101 102 99 Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>( 103 100 InstructionsParameterName, … … 105 102 config)); 106 103 107 Parameters.Add(new ValueParameter<ProblemData>(108 DataParameterName,109 DataParameterDescription));110 111 104 Parameters.Add(new ValueParameter<ErcOptions>(ErcOptionsParameterName, config.ErcOptions)); 112 105 … … 117 110 118 111 Parameters.Add(new FixedValueParameter<IntValue>( 112 MinPointsInProgramParameterName, 113 MinProgramLengthParameterDescription, 114 new IntValue(config.MinPointsInProgram)) { Hidden = true }); 115 116 Parameters.Add(new FixedValueParameter<IntValue>( 119 117 MaxPointsInProgramParameterName, 120 118 MaxProgramLengthParameterDescription, 121 119 new IntValue(config.MaxPointsInProgram))); 122 Encoding.LengthParameter = Parameters[MaxPointsInProgramParameterName]as IFixedValueParameter<IntValue>;120 Encoding.LengthParameter = MaxPointsInProgramParameter as IFixedValueParameter<IntValue>; 123 121 124 122 Parameters.Add(new FixedValueParameter<BoolValue>( … … 153 151 } 154 152 155 public IValueParameter<DataBounds> DataBoundsParameter156 {157 get { return (IValueParameter<DataBounds>)Parameters[DataBoundsParameterName]; }158 }159 160 public DataBounds DataBounds161 {162 get { return DataBoundsParameter.Value; }163 set { DataBoundsParameter.Value = value; }164 }165 166 167 153 public IValueParameter<IEnabledExpressionsConfiguration> InstructionsParameter 168 154 { … … 174 160 get { return InstructionsParameter.Value; } 175 161 set { InstructionsParameter.Value = value; } 176 }177 178 public IValueParameter<ProblemData> DataParameter179 {180 get { return (IValueParameter<ProblemData>)Parameters[DataParameterName]; }181 }182 183 public ProblemData Data184 {185 get { return DataParameter.Value; }186 set { DataParameter.Value = value; }187 162 } 188 163 … … 267 242 268 243 /// <summary> 244 /// This is the minimum size of an item on the CODE stack, expressed as a number of points. 245 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be 246 /// exceeded 247 /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 248 /// instruction. 249 /// </summary> 250 public IValueParameter<IntValue> MinPointsInProgramParameter 251 { 252 get { return (IValueParameter<IntValue>)this.Parameters[MinPointsInProgramParameterName]; } 253 } 254 255 public int MinPointsInProgram 256 { 257 get { return config.MaxPointsInProgram; } 258 set 259 { 260 MinPointsInProgramParameter.Value.Value = value; 261 config.MinPointsInProgram = value; 262 } 263 } 264 265 /// <summary> 269 266 /// The maximum number of points in an expression produced by the CODE.RAND instruction. 270 267 /// </summary> … … 338 335 339 336 public override bool Maximization { get { return false; } } 340 341 public override IDeepCloneable Clone(Cloner cloner) {342 return new PushProblem(this, cloner);343 }344 337 345 338 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { … … 357 350 private void AnalyzeBestTestSolution(IntegerVector bestIndividual, ResultCollection results, IRandom random) { 358 351 var program = bestIndividual.ToPushProgram(config, randomPool); 359 var t rainingResult = PushEvaluator.Evaluate(program, pool, random, Data, DataBounds.TestRange.Start, DataBounds.TestRange.End);352 var testResult = PushEvaluator.EvaluateTest(pool, program, random); 360 353 361 354 if (!results.ContainsKey(TestQualityResultName)) { 362 results.Add(new Result(TestQualityResultName, new DoubleValue(t rainingResult.TotalQuality)));355 results.Add(new Result(TestQualityResultName, new DoubleValue(testResult.TotalQuality))); 363 356 } else { 364 ((DoubleValue)results[TestQualityResultName].Value).Value = t rainingResult.TotalQuality;357 ((DoubleValue)results[TestQualityResultName].Value).Value = testResult.TotalQuality; 365 358 } 366 359 } 367 360 368 361 private bool AnalyzeBestTrainingSolution(IntegerVector bestIndividual, double bestQuality, ResultCollection results, IRandom random) { 369 var solution = new PushSolution(bestIndividual, bestQuality, Data, random, config, DataBounds.TrainingRange.Start, DataBounds.TrainingRange.End); 362 var solution = CreatePushSolution( 363 bestIndividual, 364 bestQuality, 365 random, 366 config, 367 PushEvaluator); 370 368 371 369 if (!results.ContainsKey(BestTrainingSolutionResultName)) { … … 385 383 } 386 384 385 protected abstract PushSolution CreatePushSolution( 386 IntegerVector vector, 387 double bestQuality, 388 IRandom random, 389 IReadOnlyPushConfiguration config, 390 IPushEvaluator evaluator); 391 387 392 public override double Evaluate(Individual individual, IRandom random) { 388 393 var program = individual.ToPushProgram(config, randomPool); 389 var result = PushEvaluator.Evaluate( 390 program, 391 pool, 392 random, 393 Data, 394 DataBounds.TrainingRange.Start, 395 DataBounds.TrainingRange.End); 396 397 individual.SetScopeValue(CaseQualitiesScopeParameterName, new DoubleArray(result.ExampleQualities)); 394 var result = PushEvaluator.EvaluateTraining(pool, program, random); 395 396 individual[CaseQualitiesScopeParameterName] = new DoubleArray(result.ExampleQualities); 398 397 399 398 return result.TotalQuality; 400 }401 402 public void Load(ProblemData data) {403 Data = data;404 BestKnownQuality = data.BestResult;405 MaxPointsInProgram = data.MaxSize;406 EvalPushLimit = data.EvalLimit;407 ErcOptions = data.ErcOptions;408 409 config.EnabledExpressions = (IList<string>)ExpressionTable.GetExpressionsByStackTypes((StackTypes)data.EnabledDataTypes);410 411 // update enabled stack types412 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) {413 var enable = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]).Any();414 config.SetStack(stackType, enable);415 }416 417 Encoding.Bounds[0, 0] = 0;418 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count;419 Encoding.Length = config.MaxPointsInProgram;420 421 DataBounds.TrainingRange.Start = 0;422 DataBounds.TrainingRange.End = Data.TrainingCount;423 DataBounds.TestRange.Start = Data.TrainingCount;424 DataBounds.TestRange.End = Data.TrainingCount + Data.TestCount;425 399 } 426 400 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushSolution.cs
r14875 r14897 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { 2 using HeuristicLab.BenchmarkSuite.Problems;3 using HeuristicLab.Common;4 using HeuristicLab.Core;5 using HeuristicLab.Encodings.IntegerVectorEncoding;6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;7 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;2 using Common; 3 using Configuration; 4 using Core; 5 using Encodings.IntegerVectorEncoding; 6 using Expressions; 7 using Persistence.Default.CompositeSerializers.Storable; 8 8 9 9 [StorableClass] … … 14 14 public readonly IntegerVector IntegerVector; 15 15 [Storable] 16 public readonly ProblemData Data;17 [Storable]18 16 public readonly IRandom Random; 19 17 [Storable] 20 18 public readonly IReadOnlyPushConfiguration Config; 19 21 20 [Storable] 22 public readonly int DataStart; 23 [Storable] 24 public readonly int DataEnd; 25 [Storable] 26 public readonly bool Simplify; 21 public readonly IPushEvaluator Evaluator; 27 22 28 public PushSolution(IntegerVector integerVector, double quality, ProblemData data, IRandom random, IReadOnlyPushConfiguration config, int dataStart, int dataEnd, bool simplify = false) 23 public readonly PushProgram Program; 24 25 public PushSolution(IntegerVector integerVector, double quality, IRandom random, IReadOnlyPushConfiguration config, IPushEvaluator evaluator, bool simplify = false) 29 26 : base("Solution", "A push solution.") { 30 27 IntegerVector = integerVector; 31 28 Quality = quality; 32 Data = data;33 29 Random = random; 34 30 Config = config; 35 DataStart = dataStart; 36 DataEnd = dataEnd; 37 Simplify = simplify; 31 Evaluator = evaluator; 32 33 Program = IntegerVector.ToPushProgram(config); 34 35 if (simplify) 36 Program = Simplifier.Simplifier.Simplify(Program, p => Evaluator.EvaluateTraining(config, p, random).TotalQuality); 38 37 } 39 38 40 39 public PushSolution(PushSolution origin, Cloner cloner) : base(origin, cloner) { 40 Quality = origin.Quality; 41 41 IntegerVector = cloner.Clone(origin.IntegerVector); 42 Quality = origin.Quality;43 Data = cloner.Clone(origin.Data);44 42 Random = cloner.Clone(origin.Random); 45 43 Config = cloner.Clone(origin.Config); 46 DataStart = origin.DataStart; 47 DataEnd = origin.DataEnd; 48 Simplify = origin.Simplify; 44 } 45 46 public virtual PushSolution Simplify() { 47 return new PushSolution(IntegerVector, Quality, Random, Config, Evaluator, true); 49 48 } 50 49 51 50 [StorableConstructor] 52 pr ivatePushSolution(bool deserializing) : base(deserializing) { }51 protected PushSolution(bool deserializing) : base(deserializing) { } 53 52 54 53 public override IDeepCloneable Clone(Cloner cloner) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs
r14875 r14897 5 5 [Flags] 6 6 public enum StackTypes : ushort { 7 None = 0x0 0, // Required to specify expression dependencies7 None = 0x01, // Required to specify expression dependencies 8 8 Integer = 0x02, 9 9 Float = 0x04, … … 14 14 Code = 0x80, 15 15 Exec = 0x100, 16 Return= 0x200,16 Print = 0x200, 17 17 IntegerVector = 0x400, 18 18 FloatVector = 0x800, 19 19 StringVector = 0x1000, 20 BooleanVector = 0x2000 20 BooleanVector = 0x2000, 21 21 } 22 22 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.resx
r14777 r14897 67 67 <xsd:element name="metadata"> 68 68 <xsd:complexType> 69 <xsd: sequence>69 <xsd:items> 70 70 <xsd:element name="value" types="xsd:string" minOccurs="0" /> 71 </xsd: sequence>71 </xsd:items> 72 72 <xsd:attribute name="name" use="required" types="xsd:string" /> 73 73 <xsd:attribute name="types" types="xsd:string" /> … … 84 84 <xsd:element name="data"> 85 85 <xsd:complexType> 86 <xsd: sequence>86 <xsd:items> 87 87 <xsd:element name="value" types="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 88 88 <xsd:element name="comment" types="xsd:string" minOccurs="0" msdata:Ordinal="2" /> 89 </xsd: sequence>89 </xsd:items> 90 90 <xsd:attribute name="name" types="xsd:string" use="required" msdata:Ordinal="1" /> 91 91 <xsd:attribute name="types" types="xsd:string" msdata:Ordinal="3" /> … … 96 96 <xsd:element name="resheader"> 97 97 <xsd:complexType> 98 <xsd: sequence>98 <xsd:items> 99 99 <xsd:element name="value" types="xsd:string" minOccurs="0" msdata:Ordinal="1" /> 100 </xsd: sequence>100 </xsd:items> 101 101 <xsd:attribute name="name" types="xsd:string" use="required" /> 102 102 </xsd:complexType>
Note: See TracChangeset
for help on using the changeset viewer.