Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/21/17 11:33:53 (7 years ago)
Author:
pkimmesw
Message:

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

Location:
branches/PushGP/HeuristicLab.PushGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore
      •  

        old new  
        11*.user
         2packages
         3TestResults
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs

    r15189 r15334  
    122122    public override bool IsNoop(IInternalPushInterpreter interpreter) {
    123123      return interpreter.StringStack.Count < 2 ||
    124              interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length >= interpreter.Configuration.MaxStringLength;
     124             interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length > interpreter.Configuration.MaxStringLength;
    125125    }
    126126
     
    148148      return interpreter.StringStack.IsEmpty ||
    149149             interpreter.CharStack.IsEmpty ||
    150              interpreter.StringStack.Top.Length + 1 >= interpreter.Configuration.MaxStringLength;
     150             interpreter.StringStack.Top.Length + 1 > interpreter.Configuration.MaxStringLength;
    151151    }
    152152
     
    618618
    619619    public override void Eval(IInternalPushInterpreter interpreter) {
     620      var result = GetResultString(interpreter);
     621
     622      // Should be checked in isNoop but would require to calculate result twice which is an expensive operation
     623      if (result.Length > interpreter.Configuration.MaxStringLength)
     624        return;
     625
     626      interpreter.StringStack.Remove(2);
     627      interpreter.StringStack.Top = result;
     628    }
     629
     630    private static string GetResultString(IInternalPushInterpreter interpreter) {
    620631      var third = interpreter.StringStack[2];
    621632      var second = interpreter.StringStack[1];
    622633      var first = interpreter.StringStack[0];
    623       interpreter.StringStack.Remove(2);
    624 
    625       interpreter.StringStack.Top = third.Length == 0 || second.Length == 0
     634
     635      var result = third.Length == 0 || second.Length == 0
    626636        ? third
    627637        : third.Replace(second, first);
     638
     639      return result;
    628640    }
    629641  }
     
    647659
    648660    public override void Eval(IInternalPushInterpreter interpreter) {
     661      var result = GetResultString(interpreter);
     662
     663      // Should be checked in isNoop but would require to calculate result twice which is an expensive operation
     664      if (result.Length > interpreter.Configuration.MaxStringLength)
     665        return;
     666
     667      interpreter.StringStack.Remove(2);
     668      interpreter.StringStack.Top = result;
     669    }
     670
     671    private static string GetResultString(IInternalPushInterpreter interpreter) {
    649672      var third = interpreter.StringStack[2];
    650673      var second = interpreter.StringStack[1];
    651674      var first = interpreter.StringStack[0];
    652       interpreter.StringStack.Remove(2);
    653 
    654       interpreter.StringStack.Top = third.Length == 0 || second.Length == 0
     675
     676      var result = third.Length == 0 || second.Length == 0
    655677        ? third
    656678        : ReplaceFirst(third, second, first);
     679      return result;
    657680    }
    658681
     
    802825    "STRING.ITERATE",
    803826    "Iterates over the top STRING using the CODE on the EXEC stack.",
    804     StackTypes.Exec | StackTypes.Char, execIn: 1)]
     827    StackTypes.Exec | StackTypes.Char, requiredBlockCount: 1)]
    805828  public class StringIterateExpression : StatelessExpression {
    806829    public StringIterateExpression() { }
Note: See TracChangeset for help on using the changeset viewer.