Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Simplifier/Simplifier.cs

    r14777 r14952  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Simplifier {
    22  using System;
     3  using System.Collections.Generic;
    34
    45  using Expressions;
    56
     7  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    68  using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Tree;
     9  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    710
    811  public static class Simplifier {
     
    1013      new TreeNode<Expression>(ExpressionTable.GetStatelessExpression<CodeNoopExpression>());
    1114
    12     public static PushProgram Simplify(PushProgram program, Func<PushProgram, double> evaluator) {
     15    public static PushProgram Simplify(PushProgram program, IReadOnlyPushConfiguration config, Func<PushProgram, double> evaluator) {
    1316      var bestResult = evaluator(program);
     17      //var noopFreeProgram = RemoveNoops(program, config);
    1418      var tree = program.ToTree();
    1519      var optimizedTree = RemoveUnnecessaryExpressions(tree, tree, ref bestResult, evaluator);
    1620
    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);
    1841    }
    1942
Note: See TracChangeset for help on using the changeset viewer.