Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File:
1 edited

Legend:

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

    r14952 r15017  
    1717    protected VectorReplaceFirstExpression(bool deserializing) : base(deserializing) { }
    1818
    19     protected bool IsNoop(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
     19    protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    2020      return vectorStack.IsEmpty || literalStack.Count < 2;
    2121    }
    2222
    23     protected void Eval(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
     23    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    2424      var vector = vectorStack.Top;
    2525      var first = literalStack.Top;
    2626      var second = literalStack[1];
    27       var index = vector.IndexOf(second);
    2827      literalStack.Remove(2);
    2928
    30       if (index >= 0)
    31         vector[index] = first;
     29      var index = -1;
     30      for (var i = 0; i < vector.Count && index < 0; i++) {
     31        if (vector[i].Equals(second)) {
     32          index = i;
     33          break;
     34        }
     35      }
     36
     37      if (index >= 0) {
     38        var result = new List<T>(vector);
     39        result[index] = first;
     40        vectorStack.Top = result;
     41      }
    3242    }
    3343  }
Note: See TracChangeset for help on using the changeset viewer.