Changeset 14875 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CodeExpressions.cs
- Timestamp:
- 04/18/17 01:15:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CodeExpressions.cs
r14834 r14875 83 83 public override bool Eval(IInternalPushInterpreter interpreter) { 84 84 // 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; 86 88 87 89 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); 91 95 92 96 return true; … … 104 108 105 109 var first = interpreter.CodeStack.Top; 106 var second = interpreter.CodeStack.ReverseElementAt(1); 110 var second = interpreter.CodeStack[1]; 111 107 112 PushProgram firstProgram = null; 108 113 PushProgram secondProgram = null; … … 130 135 131 136 interpreter.CodeStack.Pop(); 132 133 //var first = interpreter.CodeStack.Pop();134 //var second = interpreter.CodeStack.Top;135 137 136 138 PushProgram result; … … 269 271 public override bool Eval(IInternalPushInterpreter interpreter) { 270 272 if ((interpreter.CodeStack.Count < 2) || 271 (interpreter.CodeStack[ interpreter.CodeStack.Count - 2].GetType() !=273 (interpreter.CodeStack[1].GetType() != 272 274 typeof(PushProgram))) return false; 273 275 … … 308 310 public override bool Eval(IInternalPushInterpreter interpreter) { 309 311 if (interpreter.CodeStack.Count < 2 || 310 !interpreter.CodeStack[ interpreter.CodeStack.Count - 2].IsProgram)312 !interpreter.CodeStack[1].IsProgram) 311 313 return false; 312 314 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); 317 320 interpreter.BooleanStack.Push(contains); 318 319 321 return true; 320 322 } … … 371 373 if (interpreter.CodeStack.Count < 2) return false; 372 374 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 374 379 var firstItems = new Dictionary<int, int>(); 375 380 var secondItems = new Dictionary<int, int>(); 376 381 377 DetermineUniqueItems( expressions[0], secondItems);378 DetermineUniqueItems( expressions[1], firstItems);382 DetermineUniqueItems(second, secondItems); 383 DetermineUniqueItems(first, firstItems); 379 384 380 385 var discrepancy = GetDiscrepancy(firstItems, secondItems); 381 382 386 interpreter.IntegerStack.Push(discrepancy); 383 387 … … 522 526 return false; 523 527 524 var source = interpreter.CodeStack[ interpreter.CodeStack.Count - 2];528 var source = interpreter.CodeStack[1]; 525 529 var target = (PushProgram)interpreter.CodeStack.Pop(); 526 530 var index = (int)interpreter.IntegerStack.Pop(); … … 577 581 if (interpreter.CodeStack.Count < 2 || 578 582 (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)) 580 584 return false; 581 585 … … 604 608 if (interpreter.CodeStack.Count < 2) return false; 605 609 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); 611 617 612 618 interpreter.BooleanStack.Push(contains); … … 714 720 if (interpreter.CodeStack.Count < 2) return false; 715 721 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); 719 725 720 726 var position = -1; … … 765 771 return false; 766 772 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 771 778 var firstExpressions = first.Expressions; 772 779 var newExpressions = interpreter.PoolContainer.ExpressionListPool.Get();
Note: See TracChangeset
for help on using the changeset viewer.