Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Simplifier
- Timestamp:
- 05/10/17 11:23:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Simplifier/Simplifier.cs
r14777 r14952 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Simplifier { 2 2 using System; 3 using System.Collections.Generic; 3 4 4 5 using Expressions; 5 6 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 6 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Tree; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 7 10 8 11 public static class Simplifier { … … 10 13 new TreeNode<Expression>(ExpressionTable.GetStatelessExpression<CodeNoopExpression>()); 11 14 12 public static PushProgram Simplify(PushProgram program, Func<PushProgram, double> evaluator) {15 public static PushProgram Simplify(PushProgram program, IReadOnlyPushConfiguration config, Func<PushProgram, double> evaluator) { 13 16 var bestResult = evaluator(program); 17 //var noopFreeProgram = RemoveNoops(program, config); 14 18 var tree = program.ToTree(); 15 19 var optimizedTree = RemoveUnnecessaryExpressions(tree, tree, ref bestResult, evaluator); 16 20 17 return optimizedTree.ToPushProgram(e => !ReferenceEquals(e, NoopNode.Value)); 21 var optimizedPrgram = optimizedTree.ToPushProgram(e => !ReferenceEquals(e, NoopNode.Value)); 22 return optimizedPrgram; // RemoveNoops(optimizedPrgram, config); 23 } 24 25 // not working so far, an expression can only be a noop if it is a noop for all examples of a problem 26 private static PushProgram RemoveNoops(PushProgram pushProgram, IReadOnlyPushConfiguration config) { 27 var expressions = new List<Expression>(); 28 var interpreter = new PushInterpreter(config); 29 30 interpreter.Run(pushProgram, true); 31 32 while (interpreter.CanStep) { 33 var isNoop = interpreter.ExecStack.Top.IsNoop(interpreter); 34 if (!isNoop) 35 expressions.Add(interpreter.ExecStack.Top); 36 37 interpreter.Step(); 38 } 39 40 return new PushProgram(expressions); 18 41 } 19 42
Note: See TracChangeset
for help on using the changeset viewer.