Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/17 01:15:25 (8 years ago)
Author:
pkimmesw
Message:

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File:
1 edited

Legend:

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

    r14834 r14875  
    8383    public override bool Eval(IInternalPushInterpreter interpreter) {
    8484      // not enough arguments on stack
    85       if ((interpreter.BooleanStack.Count == 0) || (interpreter.CodeStack.Count < 2)) return false;
     85      if (interpreter.BooleanStack.Count == 0 ||
     86          interpreter.CodeStack.Count < 2)
     87        return false;
    8688
    8789      var condition = interpreter.BooleanStack.Pop();
    88       var items = interpreter.CodeStack.Pop(2);
    89 
    90       interpreter.ExecStack.Push(condition ? items[0] : items[1]);
     90      var first = interpreter.CodeStack[1];
     91      var second = interpreter.CodeStack.Top;
     92
     93      interpreter.CodeStack.Remove(2);
     94      interpreter.ExecStack.Push(condition ? first : second);
    9195
    9296      return true;
     
    104108
    105109      var first = interpreter.CodeStack.Top;
    106       var second = interpreter.CodeStack.ReverseElementAt(1);
     110      var second = interpreter.CodeStack[1];
     111
    107112      PushProgram firstProgram = null;
    108113      PushProgram secondProgram = null;
     
    130135
    131136      interpreter.CodeStack.Pop();
    132 
    133       //var first = interpreter.CodeStack.Pop();
    134       //var second = interpreter.CodeStack.Top;
    135137
    136138      PushProgram result;
     
    269271    public override bool Eval(IInternalPushInterpreter interpreter) {
    270272      if ((interpreter.CodeStack.Count < 2) ||
    271           (interpreter.CodeStack[interpreter.CodeStack.Count - 2].GetType() !=
     273          (interpreter.CodeStack[1].GetType() !=
    272274           typeof(PushProgram))) return false;
    273275
     
    308310    public override bool Eval(IInternalPushInterpreter interpreter) {
    309311      if (interpreter.CodeStack.Count < 2 ||
    310          !interpreter.CodeStack[interpreter.CodeStack.Count - 2].IsProgram)
     312         !interpreter.CodeStack[1].IsProgram)
    311313        return false;
    312314
    313       var values = interpreter.CodeStack.Pop(2);
    314       var second = (PushProgram)values[0];
    315       var contains = second.Expressions.Contains(values[1]);
    316 
     315      var second = (PushProgram)interpreter.CodeStack[1];
     316      var first = interpreter.CodeStack.Top;
     317      interpreter.CodeStack.Remove(2);
     318
     319      var contains = second.Expressions.Contains(first);
    317320      interpreter.BooleanStack.Push(contains);
    318 
    319321      return true;
    320322    }
     
    371373      if (interpreter.CodeStack.Count < 2) return false;
    372374
    373       var expressions = interpreter.CodeStack.Pop(2);
     375      var second = interpreter.CodeStack[1];
     376      var first = interpreter.CodeStack.Top;
     377      interpreter.CodeStack.Remove(2);
     378
    374379      var firstItems = new Dictionary<int, int>();
    375380      var secondItems = new Dictionary<int, int>();
    376381
    377       DetermineUniqueItems(expressions[0], secondItems);
    378       DetermineUniqueItems(expressions[1], firstItems);
     382      DetermineUniqueItems(second, secondItems);
     383      DetermineUniqueItems(first, firstItems);
    379384
    380385      var discrepancy = GetDiscrepancy(firstItems, secondItems);
    381 
    382386      interpreter.IntegerStack.Push(discrepancy);
    383387
     
    522526        return false;
    523527
    524       var source = interpreter.CodeStack[interpreter.CodeStack.Count - 2];
     528      var source = interpreter.CodeStack[1];
    525529      var target = (PushProgram)interpreter.CodeStack.Pop();
    526530      var index = (int)interpreter.IntegerStack.Pop();
     
    577581      if (interpreter.CodeStack.Count < 2 ||
    578582         (interpreter.CodeStack.Top.IsProgram && ((PushProgram)interpreter.CodeStack.Top).Depth == interpreter.Configuration.MaxDepth) ||
    579          (interpreter.CodeStack.ReverseElementAt(1).IsProgram && ((PushProgram)interpreter.CodeStack.ReverseElementAt(1)).Depth == interpreter.Configuration.MaxDepth))
     583         (interpreter.CodeStack[1].IsProgram && ((PushProgram)interpreter.CodeStack[1]).Depth == interpreter.Configuration.MaxDepth))
    580584        return false;
    581585
     
    604608      if (interpreter.CodeStack.Count < 2) return false;
    605609
    606       var expressions = interpreter.CodeStack.Pop(2);
    607 
    608       var contains = expressions[1].IsProgram
    609           ? ((PushProgram)expressions[1]).Expressions.Contains(expressions[0])
    610           : expressions[1].Equals(expressions[0]);
     610      var first = interpreter.CodeStack[1];
     611      var second = interpreter.CodeStack.Top;
     612      interpreter.CodeStack.Remove(2);
     613
     614      var contains = second.IsProgram
     615          ? ((PushProgram)second).Expressions.Contains(first)
     616          : second.Equals(first);
    611617
    612618      interpreter.BooleanStack.Push(contains);
     
    714720      if (interpreter.CodeStack.Count < 2) return false;
    715721
    716       var expressions = interpreter.CodeStack.Pop(2);
    717       var first = expressions[1];
    718       var second = expressions[0];
     722      var second = interpreter.CodeStack[1];
     723      var first = interpreter.CodeStack.Top;
     724      interpreter.CodeStack.Remove(2);
    719725
    720726      var position = -1;
     
    765771        return false;
    766772
    767       var expressions = interpreter.CodeStack.Pop(2);
    768       var third = interpreter.CodeStack.Top;
    769       var second = expressions[0];
    770       var first = expressions[1] as PushProgram;
     773      var third = interpreter.CodeStack[2];
     774      var second = interpreter.CodeStack[1];
     775      var first = interpreter.CodeStack.Top as PushProgram;
     776      interpreter.CodeStack.Remove(2);
     777
    771778      var firstExpressions = first.Expressions;
    772779      var newExpressions = interpreter.PoolContainer.ExpressionListPool.Get();
Note: See TracChangeset for help on using the changeset viewer.