Changeset 14746 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
- Timestamp:
- 03/11/17 20:07:13 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r14745 r14746 12 12 using HeuristicLab.BenchmarkSuite; 13 13 using HeuristicLab.Data; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; 15 14 16 using Instances; 15 17 using Interpreter; … … 26 28 private readonly PushConfiguration config; 27 29 private PushInterpreterPool pool; 30 private ManagedPoolProvider<PushProgram> pushProgramPoolProvider; 28 31 29 32 public PushProblem() { 30 33 config = new PushConfiguration(); 31 34 pool = new PushInterpreterPool(config); 35 36 pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(1024); 37 pushProgramPoolProvider.InitDummyPartition(() => new PushProgram()); 32 38 33 39 InitEvents(); … … 56 62 pool = new PushInterpreterPool(config); 57 63 Instructions = config; 64 65 pushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(1024); 66 pushProgramPoolProvider.InitDummyPartition(() => new PushProgram()); 58 67 59 68 InitEvents(); … … 404 413 405 414 public override double Evaluate(Individual individual, IRandom random) { 415 if (DataBounds[0, 1] <= 0) return default(double); 406 416 407 417 var program = individual.PushProgram(config.EnabledExpressions as IReadOnlyList<string>); 408 var expandExpression = new PushProgram(program); 409 var results = new List<double>(); 418 var result = 0d; 410 419 411 420 using (var interpreter = pool.GetInstance(random)) { 412 421 for (var i = DataBounds[0, 0]; i < DataBounds[0, 1]; i++) { 413 var example = this.DataDescriptor.Examples[i];422 var example = DataDescriptor.Examples[i]; 414 423 415 424 interpreter.BooleanStack.Push(example.InputBoolean); … … 417 426 interpreter.FloatStack.Push(example.InputFloat); 418 427 419 interpreter.Run(expandExpression); 420 421 var diff = GetDiff(example.OutputInt, interpreter.IntegerStack, this.DataDescriptor.WorstResult, LongDiffer) + 422 GetDiff(example.OutputFloat, interpreter.FloatStack, this.DataDescriptor.WorstResult, DoubleDiffer) + 423 GetDiff(example.OutputBoolean, interpreter.BooleanStack, this.DataDescriptor.WorstResult, BooleanDiffer); 424 425 results.Add(diff); 428 using (interpreter.PushProgramPool = pushProgramPoolProvider.CreatePool()) { 429 interpreter.Run(program); 430 } 431 432 result += GetDiff(example.OutputInt, interpreter.IntegerStack, DataDescriptor.WorstResult, LongDiffer) 433 + GetDiff(example.OutputFloat, interpreter.FloatStack, DataDescriptor.WorstResult, DoubleDiffer) 434 + GetDiff(example.OutputBoolean, interpreter.BooleanStack, DataDescriptor.WorstResult, BooleanDiffer); 435 426 436 interpreter.Clear(); 427 437 } 428 438 } 429 439 430 return result s.Count == 0 ? 0d : results.Average();440 return result / DataBounds[0, 1]; 431 441 } 432 442
Note: See TracChangeset
for help on using the changeset viewer.