Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/PushResultExpression.cs @ 14392

Last change on this file since 14392 was 14392, checked in by pkimmesw, 8 years ago

#2665 Full Push 3.0 instruction set and tests; Added first benchmark test (count odds) for random walk tests;

File size: 1.1 KB
Line 
1using System;
2using HeuristicLab.Algorithms.PushGP.Stack;
3
4namespace HeuristicLab.Algorithms.PushGP.Expressions
5{
6    public abstract class PushResultExpression<T> : Expression
7    {
8        public PushResultExpression(string stringRepresentation) : base(stringRepresentation)
9        { }
10
11        protected void Eval(IStack<T> stack, int count, Func<T[], T> templateFunc)
12        {
13            if (stack.Count < count)
14                return;
15
16            stack.PushResult(count, templateFunc);
17        }
18
19        protected void Eval(IStack<T> stack, int count, Func<T[], T> templateFunc, T ignoreValue)
20        {
21            if (stack.Count < count || stack.Top.Equals(ignoreValue))
22                return;
23
24            stack.PushResult(count, templateFunc);
25        }
26
27        protected void Eval<R>(IStack<T> stack, IStack<R> resultStack, int count, Func<T[], R> templateFunc)
28        {
29            if (stack.Count < count)
30                return;
31
32            var items = stack.Pop(count);
33            var result = templateFunc(items);
34
35            resultStack.Push(result);
36        }
37    }
38}
Note: See TracBrowser for help on using the repository browser.