Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/16/16 23:14:01 (8 years ago)
Author:
pkimmesw
Message:

#2665 Expressions are splitted into StatefullExpressions and StatelessExpressions, Added traits for tests

Location:
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP
Files:
5 added
2 deleted
33 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/ExpressionTable.cs

    r14392 r14398  
    88    public static class ExpressionTable
    99    {
    10         private static Dictionary<string, Expression> expressionTable;
     10        private static Dictionary<string, Expression> statelessExpressionTable;
    1111        private static Dictionary<string, Func<Expression>> statefullExpressionFactory;
    1212
     
    1515        static ExpressionTable()
    1616        {
    17             expressionTable = GetExperssionTable(e => e.ToString());
    18             statefullExpressionFactory = GetStatefullExpressionFactory(e => e.ToString());
     17            statelessExpressionTable = GetStatelessExperssionTable(e => e.StringRepresentation);
     18            statefullExpressionFactory = GetStatefullExpressionFactory(e => e.StringRepresentation);
    1919
    20             Count = expressionTable.Count + statefullExpressionFactory.Count;
     20            Count = statelessExpressionTable.Count + statefullExpressionFactory.Count;
    2121        }
    2222
    23         private static Dictionary<string, Expression> GetExperssionTable(Func<Expression, string> keyFunc)
    24         {
    25             return GetExperssionTable(e => new KeyValuePair<string, Expression>(keyFunc(e), e));
    26         }
    27 
    28         private static Dictionary<string, Expression> GetExperssionTable(Func<Expression, KeyValuePair<string, Expression>> pairFunc)
     23        private static Dictionary<string, Expression> GetStatelessExperssionTable(Func<Expression, string> keyFunc)
    2924        {
    3025            var dictionary = new Dictionary<string, Expression>();
    31             var expressionTypes = GetExpressionTypes(filterStatefull: false);
     26            var expressionTypes = GetExpressionTypes(typeof(StatelessExpression));
    3227
    3328            foreach (var type in expressionTypes)
    3429            {
    35                 var expression = (Expression)Activator.CreateInstance(type);
    36                 var pair = pairFunc(expression);
     30                var expression = Activator.CreateInstance(type) as Expression;
     31                var key = keyFunc(expression);
    3732
    38                 dictionary.Add(pair.Key, pair.Value);
     33                try
     34                {
     35                    dictionary.Add(key, expression);
     36                } catch(Exception e)
     37                {
     38                    Console.WriteLine(e);
     39                }
    3940            }
    4041
     
    4546        {
    4647            var dictionary = new Dictionary<string, Func<Expression>>();
    47             var expressionTypes = GetExpressionTypes(filterStatefull: true);
     48            var expressionTypes = GetExpressionTypes(typeof(StatefullExpression));
    4849
    4950            foreach (var type in expressionTypes)
     
    5859                var key = keyFunc(expression);
    5960
    60                 dictionary.Add(key, creator);
     61                try
     62                {
     63                    dictionary.Add(key, creator);
     64                }
     65                catch (Exception e)
     66                {
     67                    Console.WriteLine(e);
     68                }
    6169            }
    6270
     
    6472        }
    6573
    66         private static IEnumerable<Type> GetExpressionTypes(bool filterStatefull)
     74        private static IEnumerable<Type> GetExpressionTypes(Type baseType)
    6775        {
    6876            return from domainAssembly in AppDomain.CurrentDomain.GetAssemblies()
    6977                   from assemblyType in domainAssembly.GetTypes()
    70                    let type = typeof(Expression)
    7178                   where !assemblyType.IsAbstract &&
    72                          assemblyType.IsSubclassOf(type) &&
    73                          Attribute.IsDefined(assemblyType, typeof(StatefullExpressionAttribute)) == filterStatefull &&
     79                         assemblyType.IsSubclassOf(baseType) &&
    7480                         assemblyType.GetConstructor(Type.EmptyTypes) != null
    7581                   select assemblyType;
    7682        }
    7783
    78         public static int StatelessCount { get { return expressionTable.Count; } }
     84        public static int StatelessCount { get { return statelessExpressionTable.Count; } }
    7985
    8086        public static int StatefullCount { get { return statefullExpressionFactory.Count; } }
     
    8389        {
    8490            return index < StatelessCount
    85                 ? expressionTable.ElementAt(index).Value
     91                ? statelessExpressionTable.ElementAt(index).Value
    8692                : statefullExpressionFactory.ElementAt(index - StatelessCount).Value();
    8793        }
     
    102108        {
    103109            Expression expression;
    104             if (expressionTable.TryGetValue(symbol, out expression)) return expression;
     110            if (statelessExpressionTable.TryGetValue(symbol, out expression)) return expression;
    105111            else throw new NotSupportedException("Expression not supported: " + symbol);
    106112        }
     
    108114        public static bool TryGetStatelessExpression(string name, out Expression expression)
    109115        {
    110             return expressionTable.TryGetValue(name, out expression);
     116            return statelessExpressionTable.TryGetValue(name, out expression);
    111117        }
    112118
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/BooleanExpressions.cs

    r14392 r14398  
    88    public class BooleanAndExpression : PushResultExpression<bool>
    99    {
    10         public BooleanAndExpression() : base("BOOLEAN.AND") { }
     10        protected override string InitStringRepresentation()
     11        {
     12            return "BOOLEAN.AND";
     13        }
    1114
    1215        public override void Eval(IInterpreter interpreter)
    1316        {
    14             this.Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
     17            Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
    1518        }
    1619    }
     
    2124    public class BooleanOrExpression : PushResultExpression<bool>
    2225    {
    23         public BooleanOrExpression() : base("BOOLEAN.OR") { }
     26        protected override string InitStringRepresentation()
     27        {
     28            return "BOOLEAN.OR";
     29        }
    2430
    2531        public override void Eval(IInterpreter interpreter)
    2632        {
    27             this.Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
     33            Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
    2834        }
    2935    }
     
    3440    public class BooleanNotExpression : PushResultExpression<bool>
    3541    {
    36         public BooleanNotExpression() : base("BOOLEAN.NOT") { }
     42        protected override string InitStringRepresentation() { return "BOOLEAN.NOT"; }
    3743
    3844        public override void Eval(IInterpreter interpreter)
    3945        {
    40             this.Eval(interpreter.BooleanStack, 1, values => !values[0]);
     46            Eval(interpreter.BooleanStack, 1, values => !values[0]);
    4147        }
    4248    }
     
    4551    /// Pushes FALSE if the top FLOAT is 0.0, or TRUE otherwise.
    4652    /// </summary>
    47     public class BooleanFromFloatExpression : Expression
     53    public class BooleanFromFloatExpression : StatelessExpression
    4854    {
    49         public BooleanFromFloatExpression() : base("BOOLEAN.FROMFLOAT") { }
     55        protected override string InitStringRepresentation() { return "BOOLEAN.FROMFLOAT"; }
    5056
    5157        public override void Eval(IInterpreter interpreter)
     
    6369    /// Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
    6470    /// </summary>
    65     public class BooleanFromIntegerExpression : Expression
     71    public class BooleanFromIntegerExpression : StatelessExpression
    6672    {
    67         public BooleanFromIntegerExpression() : base("BOOLEAN.FROMINTEGER") { }
     73        protected override string InitStringRepresentation() { return "BOOLEAN.FROMINTEGER"; }
    6874
    6975        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/CodeExpressions.cs

    r14392 r14398  
    1717    /// manipulates the stack then this final pop may end up popping something else.
    1818    /// </summary>
    19     public class CodeDoExpression : Expression
    20     {
    21         public CodeDoExpression() : base("CODE.DO") { }
     19    public class CodeDoExpression : StatelessExpression
     20    {
     21        protected override string InitStringRepresentation()
     22        {
     23            return "CODE.DO";
     24        }
    2225
    2326        public override void Eval(IInterpreter interpreter)
     
    3538    /// Like CODE.DO but pops the stack before, rather than after, the recursive execution
    3639    /// </summary>
    37     public class CodeDoXExpression : Expression
    38     {
    39         public CodeDoXExpression() : base("CODE.DO*") { }
     40    public class CodeDoXExpression : StatelessExpression
     41    {
     42        protected override string InitStringRepresentation()
     43        {
     44            return "CODE.DO*";
     45        }
    4046
    4147        public override void Eval(IInterpreter interpreter)
     
    5359    /// Does nothing.
    5460    /// </summary>
    55     public class CodeNoopExpression : Expression
    56     {
    57         public CodeNoopExpression() : base("CODE.NOOP") { }
     61    public class CodeNoopExpression : StatelessExpression
     62    {
     63        protected override string InitStringRepresentation()
     64        {
     65            return "CODE.NOOP";
     66        }
    5867
    5968        public override void Eval(IInterpreter interpreter)
     
    6776    /// This can be implemented by moving the top item on the EXEC stack onto the CODE stack.
    6877    /// </summary>
    69     public class CodeQuoteExpression : Expression
    70     {
    71         public CodeQuoteExpression() : base("CODE.QUOTE") { }
     78    public class CodeQuoteExpression : StatelessExpression
     79    {
     80        protected override string InitStringRepresentation()
     81        {
     82            return "CODE.QUOTE";
     83        }
    7284
    7385        public override void Eval(IInterpreter interpreter)
     
    8799    /// (and the BOOLEAN value upon which the decision was made) are popped.
    88100    /// </summary>
    89     public class CodeIfExpression : Expression
    90     {
    91         public CodeIfExpression() : base("CODE.IF") { }
     101    public class CodeIfExpression : StatelessExpression
     102    {
     103        protected override string InitStringRepresentation()
     104        {
     105            return "CODE.IF";
     106        }
    92107
    93108        public override void Eval(IInterpreter interpreter)
     
    111126    /// literal (that is, something not surrounded by parentheses) then it is surrounded by parentheses first.
    112127    /// </summary>
    113     public class CodeAppendExpression : Expression
    114     {
    115         public CodeAppendExpression() : base("CODE.APPEND") { }
     128    public class CodeAppendExpression : StatelessExpression
     129    {
     130        protected override string InitStringRepresentation()
     131        {
     132            return "CODE.APPEND";
     133        }
    116134
    117135        public override void Eval(IInterpreter interpreter)
     
    130148            if (isFirstList)
    131149            {
    132                 var list1 = first as ExecExpandExpression;
     150                var expand1 = first as ExecExpandExpression;
    133151
    134152                if (isSecondList)
    135153                {
    136                     var list2 = second as ExecExpandExpression;
    137 
    138                     result = new List<Expression>(list2.Expressions.Length + list1.Expressions.Length);
    139                     result.AddRange(list2.Expressions);
    140                     result.AddRange(list1.Expressions);
     154                    var expand2 = second as ExecExpandExpression;
     155
     156                    result = new List<Expression>(expand2.Expressions.Length + expand1.Expressions.Length);
     157                    result.AddRange(expand2.Expressions);
     158                    result.AddRange(expand1.Expressions);
    141159                }
    142160                else
    143161                {
    144                     result = new List<Expression>(list1.Expressions.Length + 1);
     162                    result = new List<Expression>(expand1.Expressions.Length + 1);
    145163                    result.Add(second);
    146                     result.AddRange(list1.Expressions);
     164                    result.AddRange(expand1.Expressions);
    147165                }
    148166            }
    149167            else if (isSecondList)
    150168            {
    151                 var list2 = second as ExecExpandExpression;
    152 
    153                 result = new List<Expression>(list2.Expressions.Length + 1);
     169                var expand2 = second as ExecExpandExpression;
     170
     171                result = new List<Expression>(expand2.Expressions.Length + 1);
    154172                result.Add(first);
    155                 result.AddRange(list2.Expressions);
     173                result.AddRange(expand2.Expressions);
    156174            }
    157175            else
     
    168186    /// and FALSE otherwise (that is, if it is something surrounded by parentheses).
    169187    /// </summary>
    170     public class CodeAtomExpression : Expression
    171     {
    172         public CodeAtomExpression() : base("CODE.ATOM") { }
     188    public class CodeAtomExpression : StatelessExpression
     189    {
     190        protected override string InitStringRepresentation()
     191        {
     192            return "CODE.ATOM";
     193        }
    173194
    174195        public override void Eval(IInterpreter interpreter)
     
    189210    /// The name derives from the similar Lisp function; a more generic name would be "FIRST".
    190211    /// </summary>
    191     public class CodeCarExpression : Expression
    192     {
    193         public CodeCarExpression() : base("CODE.CAR") { }
     212    public class CodeCarExpression : StatelessExpression
     213    {
     214        protected override string InitStringRepresentation()
     215        {
     216            return "CODE.CAR";
     217        }
    194218
    195219        public override void Eval(IInterpreter interpreter)
     
    216240    /// the similar Lisp function; a more generic name would be "REST".
    217241    /// </summary>
    218     public class CodeCdrExpression : Expression
    219     {
    220         public CodeCdrExpression() : base("CODE.CDR") { }
     242    public class CodeCdrExpression : StatelessExpression
     243    {
     244        protected override string InitStringRepresentation()
     245        {
     246            return "CODE.CDR";
     247        }
    221248
    222249        public override void Eval(IInterpreter interpreter)
     
    230257            if (top.GetType() == typeof(ExecExpandExpression))
    231258            {
    232                 var expression = top as ExecExpandExpression;
    233 
    234                 if (expression.Expressions.Length == 0)
     259                var expand = top as ExecExpandExpression;
     260
     261                if (expand.IsEmpty)
    235262                {
    236263                    return;
     
    238265                else
    239266                {
    240                     var length = expression.Expressions.Length - 1;
     267                    var length = expand.Expressions.Length - 1;
    241268                    var newExpressions = new Expression[length];
    242269
    243                     Array.Copy(expression.Expressions, 0, newExpressions, 0, length);
     270                    Array.Copy(expand.Expressions, 0, newExpressions, 0, length);
    244271
    245272                    expandExpression = new ExecExpandExpression(newExpressions);
     
    260287    /// second piece of code is "X" then this pushes "( X A B )" (after popping the argument).
    261288    /// </summary>
    262     public class CodeConsExpression : Expression
    263     {
    264         public CodeConsExpression() : base("CODE.CONS") { }
     289    public class CodeConsExpression : StatelessExpression
     290    {
     291        protected override string InitStringRepresentation()
     292        {
     293            return "CODE.CONS";
     294        }
    265295
    266296        public override void Eval(IInterpreter interpreter)
     
    286316    /// and the second piece of code is "( A )" then this pushes ( C ( A ) ). Pushes an empty list if there is no such container.
    287317    /// </summary>
    288     public class CodeContainerExpression : Expression
    289     {
    290         public CodeContainerExpression() : base("CODE.CONTAINER") { }
     318    public class CodeContainerExpression : StatelessExpression
     319    {
     320        protected override string InitStringRepresentation()
     321        {
     322            return "CODE.CONTAINER";
     323        }
    291324
    292325        public override void Eval(IInterpreter interpreter)
     
    301334            var source = interpreter.CodeStack.Top;
    302335
    303             var container = this.GetContainer(null, source as ExecExpandExpression, target);
     336            var container = GetContainer(null, source as ExecExpandExpression, target);
    304337            var result = container == null
    305338                ? ExecExpandExpression.Empty
     
    330363    /// item anywhere (e.g. in a sub-list).
    331364    /// </summary>
    332     public class CodeContainsExpression : Expression
    333     {
    334         public CodeContainsExpression() : base("CODE.CONTAINS") { }
     365    public class CodeContainsExpression : StatelessExpression
     366    {
     367        protected override string InitStringRepresentation()
     368        {
     369            return "CODE.CONTAINS";
     370        }
    335371
    336372        public override void Eval(IInterpreter interpreter)
     
    352388    /// may then be executed with a call to CODE.DO or a similar instruction).
    353389    /// </summary>
    354     public class CodeDefinitionExpression : Expression
    355     {
    356         public CodeDefinitionExpression() : base("CODE.DEFINITION") { }
     390    public class CodeDefinitionExpression : StatelessExpression
     391    {
     392        protected override string InitStringRepresentation()
     393        {
     394            return "CODE.DEFINITION";
     395        }
    357396
    358397        public override void Eval(IInterpreter interpreter)
     
    385424    /// </list>
    386425    /// </summary>
    387     public class CodeDiscrepancyExpression : Expression
    388     {
    389         public CodeDiscrepancyExpression() : base("CODE.DISCREPANCY") { }
     426    public class CodeDiscrepancyExpression : StatelessExpression
     427    {
     428        protected override string InitStringRepresentation()
     429        {
     430            return "CODE.DISCREPANCY";
     431        }
    390432
    391433        public override void Eval(IInterpreter interpreter)
     
    401443            DetermineUniqueItems(expressions[1], firstItems);
    402444
    403             var discrepancy = this.GetDiscrepancy(firstItems, secondItems);
     445            var discrepancy = GetDiscrepancy(firstItems, secondItems);
    404446
    405447            interpreter.IntegerStack.Push(discrepancy);
     
    434476            if (source.GetType() == typeof(ExecExpandExpression))
    435477            {
    436                 var list = source as ExecExpandExpression;
    437 
    438                 foreach (var e in list.Expressions)
     478                var expand = source as ExecExpandExpression;
     479
     480                foreach (var e in expand.Expressions)
    439481                {
    440482                    var id = e.GetHashCode();
     
    464506    /// absolute value is taken in case it is negative) to ensure that it is within the meaningful range.
    465507    /// </summary>
    466     public class CodeExtractExpression : Expression
    467     {
    468         public CodeExtractExpression() : base("CODE.EXTRACT") { }
     508    public class CodeExtractExpression : StatelessExpression
     509    {
     510        protected override string InitStringRepresentation()
     511        {
     512            return "CODE.EXTRACT";
     513        }
    469514
    470515        public override void Eval(IInterpreter interpreter)
     
    488533    /// Pops the BOOLEAN stack and pushes the popped item (TRUE or FALSE) onto the CODE stack.
    489534    /// </summary>
    490     public class CodeFromBooleanExpression : Expression
    491     {
    492         public CodeFromBooleanExpression() : base("CODE.FROMBOOLEAN") { }
     535    public class CodeFromBooleanExpression : StatelessExpression
     536    {
     537        protected override string InitStringRepresentation()
     538        {
     539            return "CODE.FROMBOOLEAN";
     540        }
    493541
    494542        public override void Eval(IInterpreter interpreter)
     
    507555    /// Pops the FLOAT stack and pushes the popped item onto the CODE stack.
    508556    /// </summary>
    509     public class CodeFromFloatExpression : Expression
    510     {
    511         public CodeFromFloatExpression() : base("CODE.FROMFLOAT") { }
     557    public class CodeFromFloatExpression : StatelessExpression
     558    {
     559        protected override string InitStringRepresentation()
     560        {
     561            return "CODE.FROMFLOAT";
     562        }
    512563
    513564        public override void Eval(IInterpreter interpreter)
     
    526577    /// Pops the INTEGER stack and pushes the popped integer onto the CODE stack.
    527578    /// </summary>
    528     public class CodeFromIntegerExpression : Expression
    529     {
    530         public CodeFromIntegerExpression() : base("CODE.FROMINTEGER") { }
     579    public class CodeFromIntegerExpression : StatelessExpression
     580    {
     581        protected override string InitStringRepresentation()
     582        {
     583            return "CODE.FROMINTEGER";
     584        }
    531585
    532586        public override void Eval(IInterpreter interpreter)
     
    545599    /// Pops the NAME stack and pushes the popped item onto the CODE stack.
    546600    /// </summary>
    547     public class CodeFromNameExpression : Expression
    548     {
    549         public CodeFromNameExpression() : base("CODE.FROMNAME") { }
     601    public class CodeFromNameExpression : StatelessExpression
     602    {
     603        protected override string InitStringRepresentation()
     604        {
     605            return "CODE.FROMNAME";
     606        }
    550607
    551608        public override void Eval(IInterpreter interpreter)
     
    565622    /// by the top item of the INTEGER stack (and replacing whatever was there formerly).
    566623    /// </summary>
    567     public class CodeInsertExpression : Expression
    568     {
    569         public CodeInsertExpression() : base("CODE.INSERT") { }
     624    public class CodeInsertExpression : StatelessExpression
     625    {
     626        protected override string InitStringRepresentation()
     627        {
     628            return "CODE.INSERT";
     629        }
    570630
    571631        public override void Eval(IInterpreter interpreter)
     
    602662    /// matter what they contain.
    603663    /// </summary>
    604     public class CodeLengthExpression : Expression
    605     {
    606         public CodeLengthExpression() : base("CODE.LENGTH") { }
     664    public class CodeLengthExpression : StatelessExpression
     665    {
     666        protected override string InitStringRepresentation()
     667        {
     668            return "CODE.LENGTH";
     669        }
    607670
    608671        public override void Eval(IInterpreter interpreter)
     
    626689    /// Pushes a list of the top two items of the CODE stack onto the CODE stack.
    627690    /// </summary>
    628     public class CodeListExpression : Expression
    629     {
    630         public CodeListExpression() : base("CODE.LIST") { }
     691    public class CodeListExpression : StatelessExpression
     692    {
     693        protected override string InitStringRepresentation()
     694        {
     695            return "CODE.LIST";
     696        }
    631697
    632698        public override void Eval(IInterpreter interpreter)
     
    652718    /// (which is coerced to a list if necessary). Pushes FALSE onto the BOOLEAN stack otherwise.
    653719    /// </summary>
    654     public class CodeMemberExpression : Expression
    655     {
    656         public CodeMemberExpression() : base("CODE.MEMBER") { }
     720    public class CodeMemberExpression : StatelessExpression
     721    {
     722        protected override string InitStringRepresentation()
     723        {
     724            return "CODE.MEMBER";
     725        }
    657726
    658727        public override void Eval(IInterpreter interpreter)
     
    676745    /// modulo the length of the expression into which it is indexing.
    677746    /// </summary>
    678     public class CodeNthExpression : Expression
    679     {
    680         public CodeNthExpression() : base("CODE.NTH") { }
     747    public class CodeNthExpression : StatelessExpression
     748    {
     749        protected override string InitStringRepresentation()
     750        {
     751            return "CODE.NTH";
     752        }
    681753
    682754        public override void Eval(IInterpreter interpreter)
     
    693765            if (expression.GetType() == typeof(ExecExpandExpression))
    694766            {
    695                 var subExpressions = (expression as ExecExpandExpression).Expressions;
    696 
    697                 nthExpression = subExpressions.Length == 0
     767                var subExpression = expression as ExecExpandExpression;
     768
     769                nthExpression = subExpression.IsEmpty
    698770                    ? ExecExpandExpression.Empty
    699                     : subExpressions[subExpressions.Length - 1 - Math.Abs(n % subExpressions.Length)];
     771                    : subExpression.Expressions[subExpression.Expressions.Length - 1 - Math.Abs(n % subExpression.Expressions.Length)];
    700772            }
    701773            else
     
    714786    /// its first element.
    715787    /// </summary>
    716     public class CodeNthCdrExpression : Expression
    717     {
    718         public CodeNthCdrExpression() : base("CODE.NTHCDR") { }
     788    public class CodeNthCdrExpression : StatelessExpression
     789    {
     790        protected override string InitStringRepresentation()
     791        {
     792            return "CODE.NTHCDR";
     793        }
    719794
    720795        public override void Eval(IInterpreter interpreter)
     
    749824    /// Pushes TRUE onto the BOOLEAN stack if the top item of the CODE stack is an empty list, or FALSE otherwise.
    750825    /// </summary>
    751     public class CodeNullExpression : Expression
    752     {
    753         public CodeNullExpression() : base("CODE.NULL") { }
     826    public class CodeNullExpression : StatelessExpression
     827    {
     828        protected override string InitStringRepresentation()
     829        {
     830            return "CODE.NULL";
     831        }
    754832
    755833        public override void Eval(IInterpreter interpreter)
     
    768846    /// (which is coerced to a list if necessary). Pushes -1 if no match is found.
    769847    /// </summary>
    770     public class CodePositionExpression : Expression
    771     {
    772         public CodePositionExpression() : base("CODE.POSITION") { }
     848    public class CodePositionExpression : StatelessExpression
     849    {
     850        protected override string InitStringRepresentation()
     851        {
     852            return "CODE.POSITION";
     853        }
    773854
    774855        public override void Eval(IInterpreter interpreter)
     
    784865            if (first.GetType() == typeof(ExecExpandExpression))
    785866            {
    786                 var list = first as ExecExpandExpression;
    787                 position = list.Expressions.Length - 1 - Array.FindIndex(list.Expressions, e => e.Equals(second));
     867                var expand = first as ExecExpandExpression;
     868                position = expand.Expressions.Length - 1 - Array.FindIndex(expand.Expressions, e => e.Equals(second));
    788869            }
    789870            else if (first.Equals(second))
     
    800881    /// and pair of parentheses counts as a point.
    801882    /// </summary>
    802     public class CodeSizeExpression : Expression
    803     {
    804         public CodeSizeExpression() : base("CODE.SIZE") { }
     883    public class CodeSizeExpression : StatelessExpression
     884    {
     885        protected override string InitStringRepresentation()
     886        {
     887            return "CODE.SIZE";
     888        }
    805889
    806890        public override void Eval(IInterpreter interpreter)
     
    824908    /// cases with empty-list arguments. If any of these problematic possibilities occurs the stack is left unchanged.
    825909    /// </summary>
    826     public class CodeSubstitutionExpression : Expression
    827     {
    828         public CodeSubstitutionExpression() : base("CODE.SUBST") { }
     910    public class CodeSubstitutionExpression : StatelessExpression
     911    {
     912        protected override string InitStringRepresentation()
     913        {
     914            return "CODE.SUBST";
     915        }
    829916
    830917        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DefineExpressions.cs

    r14392 r14398  
    1010    /// </summary>
    1111    /// <typeparam name="T">Stacktype</typeparam>
    12     public abstract class DefineExpression<T> : Expression
     12    public abstract class DefineExpression<T> : StatelessExpression
    1313    {
    14         public DefineExpression(string stringRepresentation) : base(stringRepresentation)
    15         { }
    16 
    1714        protected void Eval(IStack<T> stack, IStack<string> nameStack, IDictionary<string, Expression> customExpressions, Func<T, Expression> creator)
    1815        {
     
    3835    public class CodeDefineExpression : DefineExpression<Expression>
    3936    {
    40         public CodeDefineExpression() : base("CODE.DEFINE")
     37        protected override string InitStringRepresentation()
    4138        {
     39            return "CODE.DEFINE";
    4240        }
    4341
     
    4846                return;
    4947
    50             this.Eval(
     48            Eval(
    5149                interpreter.CodeStack,
    5250                interpreter.NameStack,
     
    6058    public class ExecDefineExpression : DefineExpression<Expression>
    6159    {
    62         public ExecDefineExpression() : base("EXEC.DEFINE")
     60        protected override string InitStringRepresentation()
    6361        {
     62            return "EXEC.DEFINE";
    6463        }
    6564
     
    6968                return;
    7069
    71             this.Eval(
     70            Eval(
    7271                interpreter.ExecStack,
    7372                interpreter.NameStack,
     
    8180    public class FloatDefineExpression : DefineExpression<double>
    8281    {
    83         public FloatDefineExpression() : base("FLOAT.DEFINE")
     82        protected override string InitStringRepresentation()
    8483        {
     84            return "FLOAT.DEFINE";
    8585        }
    8686
    8787        public override void Eval(IInterpreter interpreter)
    8888        {
    89             this.Eval(
     89            Eval(
    9090                interpreter.FloatStack,
    9191                interpreter.NameStack,
     
    9797    public class IntegerDefineExpression : DefineExpression<long>
    9898    {
    99         public IntegerDefineExpression() : base("INTEGER.DEFINE")
     99        protected override string InitStringRepresentation()
    100100        {
     101            return "INTEGER.DEFINE";
    101102        }
    102103
    103104        public override void Eval(IInterpreter interpreter)
    104105        {
    105             this.Eval(
     106            Eval(
    106107                interpreter.IntegerStack,
    107108                interpreter.NameStack,
     
    113114    public class BooleanDefineExpression : DefineExpression<bool>
    114115    {
    115         public BooleanDefineExpression() : base("BOOLENA.DEFINE")
     116        protected override string InitStringRepresentation()
    116117        {
     118            return "BOOLEAN.DEFINE";
    117119        }
    118120
    119121        public override void Eval(IInterpreter interpreter)
    120122        {
    121             this.Eval(
     123            Eval(
    122124                interpreter.BooleanStack,
    123125                interpreter.NameStack,
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DoCountExpressions.cs

    r14392 r14398  
    11using HeuristicLab.Algorithms.PushGP.Interpreter;
    22using HeuristicLab.Algorithms.PushGP.Stack;
     3using HeuristicLab.Common;
    34
    45namespace HeuristicLab.Algorithms.PushGP.Expressions
     
    67    public abstract class DoCountExpression : LoopExpression
    78    {
    8         public DoCountExpression(string stringRepresentation) : base(stringRepresentation) { }
     9        public DoCountExpression()
     10        { }
     11
     12        public DoCountExpression(LoopExpression origin, Cloner cloner) : base(origin, cloner)
     13        { }
    914
    1015        protected override bool HasInsufficientArguments(IInterpreter interpreter, IStack<Expression> sourceStack)
     
    1722        protected override void InitState(IInterpreter interpreter, IStack<Expression> sourceStack)
    1823        {
    19             this.body = sourceStack.Pop();
    20             this.destinationIndex = interpreter.IntegerStack.Top;
    21             this.currentIndex = 1;
    22             this.incrementor = 1;
     24            body = sourceStack.Pop();
     25            destinationIndex = interpreter.IntegerStack.Top;
     26            currentIndex = 1;
     27            incrementor = 1;
    2328
    2429            interpreter.IntegerStack.SetTop(0);
     
    3439    /// ( 0 '1 - IntegerArg>' CODE.QUOTE 'CodeArg' CODE.DO*RANGE )
    3540    /// </summary>
    36     [StatefullExpression]
    3741    public class CodeDoCountExpression : DoCountExpression
    3842    {
    39         public CodeDoCountExpression() : base("CODE.DO*COUNT") { }
     43        public CodeDoCountExpression()
     44        { }
     45
     46        protected CodeDoCountExpression(CodeDoCountExpression origin, Cloner cloner) : base(origin, cloner)
     47        { }
     48
     49        public override IDeepCloneable Clone(Cloner cloner)
     50        {
     51            return new CodeDoCountExpression(this, cloner);
     52        }
     53
     54        protected override string InitStringRepresentation()
     55        {
     56            return "CODE.DO*COUNT";
     57        }
    4058
    4159        public override void Eval(IInterpreter interpreter)
    4260        {
    43             this.Eval(interpreter, interpreter.CodeStack);
     61            Eval(interpreter, interpreter.CodeStack);
    4462        }
    4563    }
     
    5472    /// ( 0 '1 - IntegerArg' EXEC.DO* RANGE'ExecArg' )
    5573    /// </summary>
    56     [StatefullExpression]
    5774    public class ExecDoCountExpression : DoCountExpression
    5875    {
    59         public ExecDoCountExpression() : base("EXEC.DO*COUNT") { }
     76        public ExecDoCountExpression()
     77        { }
     78
     79        protected ExecDoCountExpression(ExecDoCountExpression origin, Cloner cloner) : base(origin, cloner)
     80        { }
     81
     82        public override IDeepCloneable Clone(Cloner cloner)
     83        {
     84            return new ExecDoCountExpression(this, cloner);
     85        }
     86
     87        protected override string InitStringRepresentation()
     88        {
     89            return "EXEC.DO*COUNT";
     90        }
    6091
    6192        public override void Eval(IInterpreter interpreter)
    6293        {
    63             this.Eval(interpreter, interpreter.ExecStack);
     94            Eval(interpreter, interpreter.ExecStack);
    6495        }
    6596    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DoRangeExpressions.cs

    r14392 r14398  
    11using HeuristicLab.Algorithms.PushGP.Interpreter;
    22using HeuristicLab.Algorithms.PushGP.Stack;
     3using HeuristicLab.Common;
    34
    45namespace HeuristicLab.Algorithms.PushGP.Expressions
     
    67    public abstract class DoRangeExpression : LoopExpression
    78    {
    8         public DoRangeExpression(string stringRepresentation) : base(stringRepresentation) { }
     9        public DoRangeExpression()
     10        { }
     11
     12        public DoRangeExpression(LoopExpression origin, Cloner cloner) : base(origin, cloner)
     13        { }
    914
    1015        protected override bool HasInsufficientArguments(IInterpreter interpreter, IStack<Expression> sourceStack)
     
    1722        protected override void InitState(IInterpreter interpreter, IStack<Expression> sourceStack)
    1823        {
    19             this.body = sourceStack.Pop();
    20             this.destinationIndex = interpreter.IntegerStack.Pop();
    21             this.currentIndex = interpreter.IntegerStack.Top;
    22             this.incrementor = this.destinationIndex < this.currentIndex ? -1 : 1;
    23             this.currentIndex += this.incrementor;
     24            body = sourceStack.Pop();
     25            destinationIndex = interpreter.IntegerStack.Pop();
     26            currentIndex = interpreter.IntegerStack.Top;
     27            incrementor = destinationIndex < currentIndex ? -1 : 1;
     28            currentIndex += incrementor;
    2429        }
    2530    }
     
    3843    /// that is less than the specified current index.
    3944    /// </summary>
    40     [StatefullExpression]
    4145    public class CodeDoRangeExpression : DoRangeExpression
    4246    {
    43         public CodeDoRangeExpression() : base("CODE.DO*RANGE") { }
     47        public CodeDoRangeExpression()
     48        { }
     49
     50        protected CodeDoRangeExpression(CodeDoRangeExpression origin, Cloner cloner) : base(origin, cloner)
     51        { }
     52
     53        public override IDeepCloneable Clone(Cloner cloner)
     54        {
     55            return new CodeDoRangeExpression(this, cloner);
     56        }
     57
     58        protected override string InitStringRepresentation()
     59        {
     60            return "CODE.DO*RANGE";
     61        }
    4462
    4563        public override void Eval(IInterpreter interpreter)
    4664        {
    47             this.Eval(interpreter, interpreter.CodeStack);
     65            Eval(interpreter, interpreter.CodeStack);
    4866        }
    4967    }
     
    6381    /// index that is less than the specified current index.
    6482    /// </summary>
    65     [StatefullExpression]
    6683    public class ExecDoRangeExpression : DoRangeExpression
    6784    {
    68         public ExecDoRangeExpression() : base("EXEC.DO*RANGE") { }
     85        public ExecDoRangeExpression()
     86        { }
     87
     88        protected ExecDoRangeExpression(ExecDoRangeExpression origin, Cloner cloner) : base(origin, cloner)
     89        { }
     90
     91        public override IDeepCloneable Clone(Cloner cloner)
     92        {
     93            return new ExecDoRangeExpression(this, cloner);
     94        }
     95
     96        protected override string InitStringRepresentation()
     97        {
     98            return "EXEC.DO*RANGE";
     99        }
    69100
    70101        public override void Eval(IInterpreter interpreter)
    71102        {
    72             this.Eval(interpreter, interpreter.ExecStack);
     103            Eval(interpreter, interpreter.ExecStack);
    73104        }
    74105    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DoTimesExpressions.cs

    r14392 r14398  
    11using HeuristicLab.Algorithms.PushGP.Interpreter;
    22using HeuristicLab.Algorithms.PushGP.Stack;
     3using HeuristicLab.Common;
    34
    45namespace HeuristicLab.Algorithms.PushGP.Expressions
     
    67    public abstract class DoTimesExpression : LoopExpression
    78    {
    8         public DoTimesExpression(string stringRepresentation) : base(stringRepresentation) { }
     9        public DoTimesExpression()
     10        { }
     11
     12        public DoTimesExpression(LoopExpression origin, Cloner cloner) : base(origin, cloner)
     13        { }
    914
    1015        protected override bool HasInsufficientArguments(IInterpreter interpreter, IStack<Expression> sourceStack)
     
    1722        protected override void InitState(IInterpreter interpreter, IStack<Expression> sourceStack)
    1823        {
    19             this.body = sourceStack.Pop();
    20             this.destinationIndex = interpreter.IntegerStack.Pop();
    21             this.currentIndex = 1;
    22             this.incrementor = 1;
     24            body = sourceStack.Pop();
     25            destinationIndex = interpreter.IntegerStack.Pop();
     26            currentIndex = 1;
     27            incrementor = 1;
    2328        }
    2429
    2530        protected override void PushIteration(IInterpreter interpreter)
    2631        {
    27             interpreter.ExecStack.Push(this, this.body);
     32            interpreter.ExecStack.Push(this, body);
    2833        }
    2934
    3035        protected override void PushLastIteration(IInterpreter interpreter)
    3136        {
    32             interpreter.ExecStack.Push(this.body);
     37            interpreter.ExecStack.Push(body);
    3338        }
    3439    }
     
    4045    /// in the call to CODE.DO*RANGE.
    4146    /// </summary>
    42     [StatefullExpression]
     47
    4348    public class CodeDoTimesExpression : DoTimesExpression
    4449    {
    45         public CodeDoTimesExpression() : base("CODE.DO*TIMES") { }
     50        public CodeDoTimesExpression()
     51        { }
     52
     53        protected CodeDoTimesExpression(CodeDoTimesExpression origin, Cloner cloner) : base(origin, cloner)
     54        { }
     55
     56        public override IDeepCloneable Clone(Cloner cloner)
     57        {
     58            return new CodeDoTimesExpression(this, cloner);
     59        }
     60
     61        protected override string InitStringRepresentation()
     62        {
     63            return "CODE.DO*TIMES";
     64        }
    4665
    4766        public override void Eval(IInterpreter interpreter)
    4867        {
    49             this.Eval(interpreter, interpreter.CodeStack);
     68            Eval(interpreter, interpreter.CodeStack);
    5069        }
    5170    }
     
    5776    /// pushed by EXEC.DO*RANGE, prior to the execution of the loop body.
    5877    /// </summary>
    59     [StatefullExpression]
     78
    6079    public class ExecDoTimesExpression : DoTimesExpression
    6180    {
    62         public ExecDoTimesExpression() : base("EXEC.DO*TIMES") { }
     81        public ExecDoTimesExpression()
     82        { }
     83
     84        protected ExecDoTimesExpression(ExecDoTimesExpression origin, Cloner cloner) : base(origin, cloner)
     85        { }
     86
     87        public override IDeepCloneable Clone(Cloner cloner)
     88        {
     89            return new ExecDoTimesExpression(this, cloner);
     90        }
     91
     92        protected override string InitStringRepresentation()
     93        {
     94            return "EXEC.DO*TIMES";
     95        }
    6396
    6497        public override void Eval(IInterpreter interpreter)
    6598        {
    66             this.Eval(interpreter, interpreter.ExecStack);
     99            Eval(interpreter, interpreter.ExecStack);
    67100        }
    68101    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DuplicateExpressions.cs

    r14397 r14398  
    99    /// </summary>
    1010    /// <typeparam name="T">Stacktype</typeparam>
    11     public abstract class DuplicateExpression<T> : Expression
     11    public abstract class DuplicateExpression<T> : StatelessExpression
    1212    {
    13         public DuplicateExpression(string stringRepresentation) : base(stringRepresentation)
    14         { }
    15 
    1613        public void Eval(IStack<T> stack)
    1714        {
     
    2522    public class IntegerDuplicateExpression : DuplicateExpression<long>
    2623    {
    27         public IntegerDuplicateExpression() : base("INTEGER.DUP")
    28         { }
     24        protected override string InitStringRepresentation() { return "INTEGER.DUP"; }
    2925
    3026        public override void Eval(IInterpreter interpreter)
    3127        {
    32             this.Eval(interpreter.IntegerStack);
     28            Eval(interpreter.IntegerStack);
    3329        }
    3430    }
     
    3632    public class FloatDuplicateExpression : DuplicateExpression<double>
    3733    {
    38         public FloatDuplicateExpression() : base("FLOAT.DUP")
    39         { }
     34        protected override string InitStringRepresentation() { return "FLOAT.DUP"; }
    4035
    4136        public override void Eval(IInterpreter interpreter)
    4237        {
    43             this.Eval(interpreter.FloatStack);
     38            Eval(interpreter.FloatStack);
    4439        }
    4540    }
     
    4742    public class BooleanDuplicateExpression : DuplicateExpression<bool>
    4843    {
    49         public BooleanDuplicateExpression() : base("BOOLEAN.DUP")
    50         { }
     44        protected override string InitStringRepresentation() { return "BOOLEAN.DUP"; }
    5145
    5246        public override void Eval(IInterpreter interpreter)
    5347        {
    54             this.Eval(interpreter.BooleanStack);
     48            Eval(interpreter.BooleanStack);
    5549        }
    5650    }
     
    5852    public class NameDuplicateExpression : DuplicateExpression<string>
    5953    {
    60         public NameDuplicateExpression() : base("NAME.DUP")
    61         { }
     54        protected override string InitStringRepresentation() { return "NAME.DUP"; }
    6255
    6356        public override void Eval(IInterpreter interpreter)
    6457        {
    65             this.Eval(interpreter.NameStack);
     58            Eval(interpreter.NameStack);
    6659        }
    6760    }
     
    6962    public class ExecDuplicateExpression : DuplicateExpression<Expression>
    7063    {
    71         public ExecDuplicateExpression() : base("EXEC.DUP")
    72         { }
     64        protected override string InitStringRepresentation() { return "EXEC.DUP"; }
    7365
    7466        public override void Eval(IInterpreter interpreter)
    7567        {
    76             this.Eval(interpreter.ExecStack);
     68            Eval(interpreter.ExecStack);
    7769        }
    7870    }
     
    8072    public class CodeDuplicateExpression : DuplicateExpression<Expression>
    8173    {
    82         public CodeDuplicateExpression() : base("CODE.DUP")
    83         { }
     74        protected override string InitStringRepresentation() { return "CODE.DUP"; }
    8475
    8576        public override void Eval(IInterpreter interpreter)
    8677        {
    87             this.Eval(interpreter.CodeStack);
     78            Eval(interpreter.CodeStack);
    8879        }
    8980    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/ERCExpressions.cs

    r14392 r14398  
    1 using HeuristicLab.Algorithms.PushGP.Generators;
     1using System;
     2using HeuristicLab.Algorithms.PushGP.Generators;
    23using HeuristicLab.Algorithms.PushGP.Interpreter;
    34using HeuristicLab.Algorithms.PushGP.Stack;
     5using HeuristicLab.Common;
    46using HeuristicLab.Core;
    57using HeuristicLab.Random;
     
    1012    {
    1113        private readonly T value;
    12         public ERCExpression(string stringRepresentation, T value) : base(stringRepresentation)
     14
     15        public ERCExpression(T value)
    1316        {
    1417            this.value = value;
     
    1720        protected void Eval(IStack<T> stack)
    1821        {
    19             stack.Push(this.value);
     22            stack.Push(value);
     23        }
     24
     25        /// <summary>
     26        /// Does not make sense
     27        /// </summary>
     28        /// <returns></returns>
     29        protected override string InitStringRepresentation()
     30        {
     31            throw new NotImplementedException();
     32        }
     33
     34        /// <summary>
     35        /// Does not make sense
     36        /// </summary>
     37        /// <returns></returns>
     38        protected override int InitId()
     39        {
     40            throw new NotImplementedException();
     41        }
     42
     43        /// <summary>
     44        /// Does not make sense
     45        /// </summary>
     46        /// <returns></returns>
     47        public override IDeepCloneable Clone(Cloner cloner)
     48        {
     49            throw new NotImplementedException();
    2050        }
    2151    }
     
    2353    public class IntegerERCExpression : ERCExpression<long>
    2454    {
    25         public IntegerERCExpression() : base("INTEGER.ERC", IntegerGenerator.RandomInteger())
     55        public IntegerERCExpression() : base(IntegerGenerator.RandomInteger())
    2656        {
    2757        }
     
    2959        public override void Eval(IInterpreter interpreter)
    3060        {
    31             this.Eval(interpreter.IntegerStack);
     61            Eval(interpreter.IntegerStack);
    3262        }
    3363    }
     
    3767        protected bool isInitialized = false;
    3868
    39         public FloatERCExpression() : base("FLOAT.ERC", FloatGenerator.RandomFloat())
     69        public FloatERCExpression() : base(FloatGenerator.RandomFloat())
    4070        {
    4171        }
     
    4373        public override void Eval(IInterpreter interpreter)
    4474        {
    45             this.Eval(interpreter.FloatStack);
     75            Eval(interpreter.FloatStack);
    4676        }
    4777    }
     
    4979    public class BooleanERCExpression : ERCExpression<bool>
    5080    {
    51         public BooleanERCExpression() : base("BOOLEAN.ERC", BooleanGenerator.RandomBoolean())
     81        public BooleanERCExpression() : base(BooleanGenerator.RandomBoolean())
    5282        {
    5383        }
     
    5585        public override void Eval(IInterpreter interpreter)
    5686        {
    57             this.Eval(interpreter.BooleanStack);
     87            Eval(interpreter.BooleanStack);
    5888        }
    5989    }
     
    6393        private static IRandom random = new FastRandom();
    6494
    65         public NameERCExpression() : base("NAME.ERC", NameGenerator.RandomName())
     95        public NameERCExpression() : base(NameGenerator.RandomName())
    6696        {
    6797        }
     
    6999        public override void Eval(IInterpreter interpreter)
    70100        {
    71             this.Eval(interpreter.NameStack);
     101            Eval(interpreter.NameStack);
    72102        }
    73103    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/EqualsExpressions.cs

    r14392 r14398  
    88    /// </summary>
    99    /// <typeparam name="T">Stacktype</typeparam>
    10     public abstract class EqualsExpression<T> : Expression
     10    public abstract class EqualsExpression<T> : StatelessExpression
    1111    {
    12         public EqualsExpression(string stringRepresentation) : base(stringRepresentation)
    13         { }
    14 
    1512        public void Eval(IStack<T> stack, IStack<bool> booleanStack)
    1613        {
     
    2623    public class IntegerEqualsExpression : EqualsExpression<long>
    2724    {
    28         public IntegerEqualsExpression() : base("INTEGER.=")
    29         { }
     25        protected override string InitStringRepresentation() { return "INTEGER.="; }
    3026
    3127        public override void Eval(IInterpreter interpreter)
    3228        {
    33             this.Eval(interpreter.IntegerStack, interpreter.BooleanStack);
     29            Eval(interpreter.IntegerStack, interpreter.BooleanStack);
    3430        }
    3531    }
     
    3733    public class FloatEqualsExpression : EqualsExpression<double>
    3834    {
    39         public FloatEqualsExpression() : base("FLOAT.=")
    40         { }
     35        protected override string InitStringRepresentation() { return "FLOAT.="; }
    4136
    4237        public override void Eval(IInterpreter interpreter)
    4338        {
    44             this.Eval(interpreter.FloatStack, interpreter.BooleanStack);
     39            Eval(interpreter.FloatStack, interpreter.BooleanStack);
    4540        }
    4641    }
     
    4843    public class BooleanEqualsExpression : EqualsExpression<bool>
    4944    {
    50         public BooleanEqualsExpression() : base("BOOLEAN.=")
    51         { }
     45        protected override string InitStringRepresentation() { return "BOOLEAN.="; }
    5246
    5347        public override void Eval(IInterpreter interpreter)
    5448        {
    55             this.Eval(interpreter.BooleanStack, interpreter.BooleanStack);
     49            Eval(interpreter.BooleanStack, interpreter.BooleanStack);
    5650        }
    5751    }
     
    5953    public class NameEqualsExpression : EqualsExpression<string>
    6054    {
    61         public NameEqualsExpression() : base("NAME.=")
    62         { }
     55        protected override string InitStringRepresentation() { return "NAME.="; }
    6356
    6457        public override void Eval(IInterpreter interpreter)
    6558        {
    66             this.Eval(interpreter.NameStack, interpreter.BooleanStack);
     59            Eval(interpreter.NameStack, interpreter.BooleanStack);
    6760        }
    6861    }
     
    7063    public class ExecEqualsExpression : EqualsExpression<Expression>
    7164    {
    72         public ExecEqualsExpression() : base("EXEC.=")
    73         { }
     65        protected override string InitStringRepresentation() { return "EXEC.="; }
    7466
    7567        public override void Eval(IInterpreter interpreter)
    7668        {
    77             this.Eval(interpreter.ExecStack, interpreter.BooleanStack);
     69            Eval(interpreter.ExecStack, interpreter.BooleanStack);
    7870        }
    7971    }
     
    8173    public class CodeEqualsExpression : EqualsExpression<Expression>
    8274    {
    83         public CodeEqualsExpression() : base("CODE.=")
    84         { }
     75        protected override string InitStringRepresentation() { return "CODE.="; }
    8576
    8677        public override void Eval(IInterpreter interpreter)
    8778        {
    88             this.Eval(interpreter.CodeStack, interpreter.BooleanStack);
     79            Eval(interpreter.CodeStack, interpreter.BooleanStack);
    8980        }
    9081    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/ExecExpressions.cs

    r14397 r14398  
    88namespace HeuristicLab.Algorithms.PushGP.Expressions
    99{
    10     public class ExecExpandExpression : Expression
     10    public class ExecExpandExpression : StatefullExpression
    1111    {
    1212        private const string prefix = "( ";
     
    1515
    1616        public readonly Expression[] Expressions;
     17        public readonly bool IsEmpty;
     18
    1719        private List<Expression> treeIndex;
    1820
    1921        public static readonly Expression Empty = new ExecExpandExpression(new Expression[0]);
    2022
    21         public ExecExpandExpression(Expression[] expressions) : base()
    22         {
    23             this.Expressions = expressions;
     23        public ExecExpandExpression(Expression[] expressions)
     24        {
     25            Expressions = expressions;
     26            IsEmpty = expressions.Length == 0;
    2427        }
    2528
     
    2730        public ExecExpandExpression(ExecExpandExpression original, Cloner cloner) : base(original, cloner)
    2831        {
    29             this.Expressions = new Expression[original.Expressions.Length];
    30             Array.Copy(original.Expressions, this.Expressions, original.Expressions.Length);
     32            Expressions = new Expression[original.Expressions.Length];
     33            Array.Copy(original.Expressions, Expressions, original.Expressions.Length);
    3134
    3235            if (original.treeIndex != null)
    3336            {
    34                 this.treeIndex = original.treeIndex.Select(e => cloner.Clone(e)).ToList();
    35             }
     37                treeIndex = original.treeIndex.Select(e => cloner.Clone(e)).ToList();
     38            }
     39
     40            IsEmpty = original.IsEmpty;
    3641        }
    3742
     
    5459        }
    5560
    56         private string GetStringRepresentation()
    57         {
    58             if (this.StringRepresentation == null)
    59             {
    60                 var sb = new StringBuilder();
    61 
    62                 sb.Append(prefix);
    63 
    64                 for (var i = this.Expressions.Length - 1; i >= 0; i--)
     61        protected override string InitStringRepresentation()
     62        {
     63            var sb = new StringBuilder();
     64
     65            sb.Append(prefix);
     66
     67            for (var i = Expressions.Length - 1; i >= 0; i--)
     68            {
     69                sb.Append(Expressions[i].ToString() + delimiter);
     70            }
     71
     72            sb.Append(postfix);
     73
     74            return sb.ToString();
     75        }
     76
     77        protected override int InitId()
     78        {
     79            unchecked
     80            {
     81                var hash = 19;
     82                foreach (var e in Expressions)
    6583                {
    66                     sb.Append(this.Expressions[i].ToString() + delimiter);
     84                    hash *= 31 + e.GetHashCode();
    6785                }
    6886
    69                 sb.Append(postfix);
    70 
    71                 this.StringRepresentation = sb.ToString();
    72             }
    73 
    74             return this.StringRepresentation;
    75         }
    76 
    77         private int GetId()
    78         {
    79             if (this.Id == default(int))
    80             {
    81                 unchecked
    82                 {
    83                     this.Id = 19;
    84                     foreach (var e in Expressions)
    85                     {
    86                         this.Id *= 31 + e.GetHashCode();
    87                     }
    88                 }
    89             }
    90 
    91             return this.Id;
     87                return hash;
     88            }
    9289        }
    9390
     
    9794        }
    9895
     96        public override int GetHashCode()
     97        {
     98            return base.GetHashCode();
     99        }
     100
    99101        public override bool Equals(object obj)
    100102        {
     
    111113            var other = obj as ExecExpandExpression;
    112114
    113             return this.Expressions.SequenceEqual(other.Expressions);
    114         }
    115 
    116         public override int GetHashCode()
    117         {
    118             return this.GetId();
    119         }
    120 
    121         public override string ToString()
    122         {
    123             return this.GetStringRepresentation();
    124         }
    125 
    126         public override void Eval(IInterpreter interpreter)
    127         {
    128             interpreter.ExecStack.Push(this.Expressions);
     115            return Expressions.SequenceEqual(other.Expressions);
     116        }
     117
     118        public override void Eval(IInterpreter interpreter)
     119        {
     120            interpreter.ExecStack.Push(Expressions);
    129121        }
    130122
     
    137129            get
    138130            {
    139                 this.BuildIndexIfNecessary();
    140 
    141                 return this.treeIndex.Count;
     131                BuildIndexIfNecessary();
     132
     133                return treeIndex.Count;
    142134            }
    143135        }
     
    150142        public Expression GetFromTree(int index)
    151143        {
    152             this.BuildIndexIfNecessary();
    153 
    154             return this.treeIndex[index];
     144            BuildIndexIfNecessary();
     145
     146            return treeIndex[index];
    155147        }
    156148
    157149        private void BuildIndexIfNecessary()
    158150        {
    159             if (this.treeIndex != null)
    160                 return;
    161 
    162             this.treeIndex = new List<Expression>(this.Expressions.Length) { this };
    163 
    164             for (var i = this.Expressions.Length - 1; i >= 0; i--)
    165             {
    166                 var subExpression = this.Expressions[i];
     151            if (treeIndex != null)
     152                return;
     153
     154            treeIndex = new List<Expression>(Expressions.Length) { this };
     155
     156            for (var i = Expressions.Length - 1; i >= 0; i--)
     157            {
     158                var subExpression = Expressions[i];
    167159
    168160                if (subExpression.GetType() == typeof(ExecExpandExpression))
    169161                {
    170                     var list = subExpression as ExecExpandExpression;
    171 
    172                     list.BuildIndexIfNecessary();
    173                     this.treeIndex.AddRange(list.treeIndex);
     162                    var expand = subExpression as ExecExpandExpression;
     163
     164                    expand.BuildIndexIfNecessary();
     165                    treeIndex.AddRange(expand.treeIndex);
    174166                }
    175167                else
    176168                {
    177                     this.treeIndex.Add(subExpression);
     169                    treeIndex.Add(subExpression);
    178170                }
    179171
     
    188180    /// the BOOLEAN stack.
    189181    /// </summary>
    190     public class ExecIfExpression : Expression
    191     {
    192         public ExecIfExpression() : base("EXEC.IF") { }
     182    public class ExecIfExpression : StatelessExpression
     183    {
     184        protected override string InitStringRepresentation() { return "EXEC.IF"; }
    193185
    194186        public override void Eval(IInterpreter interpreter)
     
    212204    /// "( EXEC.Y <TopItem> )".
    213205    /// </summary>
    214     public class ExecYExpression : Expression
    215     {
    216         public ExecYExpression() : base("EXEC.Y")
    217         {
    218         }
     206    public class ExecYExpression : StatelessExpression
     207    {
     208        protected override string InitStringRepresentation() { return "EXEC.Y"; }
    219209
    220210        public override void Eval(IInterpreter interpreter)
     
    237227    /// The Push implementation of the "K combinator". Removes the second item on the EXEC stack.
    238228    /// </summary>
    239     public class ExecKExpression : Expression
    240     {
    241         public ExecKExpression() : base("EXEC.K") { }
     229    public class ExecKExpression : StatelessExpression
     230    {
     231        protected override string InitStringRepresentation() { return "EXEC.K"; }
    242232
    243233        public override void Eval(IInterpreter interpreter)
     
    256246    /// another instance of C, followed by another instance of A.
    257247    /// </summary>
    258     public class ExecSExpression : Expression
    259     {
    260         public ExecSExpression() : base("EXEC.S") { }
     248    public class ExecSExpression : StatelessExpression
     249    {
     250        protected override string InitStringRepresentation() { return "EXEC.S"; }
    261251
    262252        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs

    r14392 r14398  
    66    public abstract class Expression : DeepCloneable
    77    {
    8         public Expression() { }
     8        private string stringRepresentation;
     9        private int id;
    910
    10         public Expression(string stringRepresenation) : this(stringRepresenation, stringRepresenation.GetHashCode())
     11        public Expression()
    1112        { }
    1213
    13         public Expression(string stringRepresenation, int id)
     14        /// <summary>
     15        /// Clone Constructor
     16        /// </summary>
     17        protected Expression(Expression origin, Cloner cloner)
    1418        {
    15             this.StringRepresentation = stringRepresenation;
    16             this.Id = id;
     19            stringRepresentation = origin.stringRepresentation;
     20            id = origin.id;
    1721        }
    18 
    19         // copy constructor
    20         public Expression(Expression original, Cloner cloner) : base(original, cloner)
    21         {
    22             this.StringRepresentation = original.StringRepresentation;
    23             this.Id = original.Id;
    24         }
    25 
    26         protected int Id { get; set; }
    27         protected string StringRepresentation { get; set; }
    2822
    2923        public abstract void Eval(IInterpreter interpreter);
    3024
    31         public override string ToString()
     25        protected abstract int InitId();
     26
     27        protected abstract string InitStringRepresentation();
     28
     29        public string StringRepresentation
    3230        {
    33             return this.StringRepresentation;
     31            get
     32            {
     33                if (stringRepresentation == null)
     34                {
     35                    stringRepresentation = InitStringRepresentation();
     36                }
     37
     38                return stringRepresentation;
     39            }
     40        }
     41
     42        public int Id
     43        {
     44            get
     45            {
     46                if (id == default(int))
     47                {
     48                    id = InitId();
     49                }
     50
     51                return id;
     52            }
    3453        }
    3554
    3655        public override bool Equals(object obj)
    3756        {
    38             return obj != null && this.GetType() == obj.GetType();
     57            return obj != null && (GetHashCode() == obj.GetHashCode() || GetType() == obj.GetType());
     58        }
     59
     60        public override string ToString()
     61        {
     62            return StringRepresentation;
    3963        }
    4064
    4165        public override int GetHashCode()
    4266        {
    43             return this.Id;
    44         }
    45 
    46         public override IDeepCloneable Clone(Cloner cloner)
    47         {
    48             return this;
     67            return Id;
    4968        }
    5069    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/FloatExpressions.cs

    r14392 r14398  
    99    public class FloatAddExpression : PushResultExpression<double>
    1010    {
    11         public FloatAddExpression() : base("FLOAT.+")
    12         { }
    13 
    14         public override void Eval(IInterpreter interpreter)
    15         {
    16             this.Eval(interpreter.FloatStack, 2, values => values[0] + values[1]);
     11        protected override string InitStringRepresentation() { return "FLOAT.+"; }
     12
     13        public override void Eval(IInterpreter interpreter)
     14        {
     15            Eval(interpreter.FloatStack, 2, values => values[0] + values[1]);
    1716        }
    1817    }
     
    2322    public class FloatSubtractExpression : PushResultExpression<double>
    2423    {
    25         public FloatSubtractExpression() : base("FLOAT.-")
    26         { }
    27 
    28         public override void Eval(IInterpreter interpreter)
    29         {
    30             this.Eval(interpreter.FloatStack, 2, values => values[0] - values[1]);
     24        protected override string InitStringRepresentation() { return "FLOAT.-"; }
     25
     26        public override void Eval(IInterpreter interpreter)
     27        {
     28            Eval(interpreter.FloatStack, 2, values => values[0] - values[1]);
    3129        }
    3230    }
     
    3735    public class FloatMultiplyExpression : PushResultExpression<double>
    3836    {
    39         public FloatMultiplyExpression() : base("FLOAT.*")
    40         { }
    41 
    42         public override void Eval(IInterpreter interpreter)
    43         {
    44             this.Eval(interpreter.FloatStack, 2, values => values[0] * values[1]);
     37        protected override string InitStringRepresentation() { return "FLOAT.*"; }
     38
     39        public override void Eval(IInterpreter interpreter)
     40        {
     41            Eval(interpreter.FloatStack, 2, values => values[0] * values[1]);
    4542        }
    4643    }
     
    5249    public class FloatDivideExpression : PushResultExpression<double>
    5350    {
    54         public FloatDivideExpression() : base("FLOAT./")
    55         { }
    56 
    57         public override void Eval(IInterpreter interpreter)
    58         {
    59             this.Eval(interpreter.FloatStack, 2, values => values[0] / values[1], 0);
     51        protected override string InitStringRepresentation() { return "FLOAT./"; }
     52
     53        public override void Eval(IInterpreter interpreter)
     54        {
     55            Eval(interpreter.FloatStack, 2, values => values[0] / values[1], 0);
    6056        }
    6157    }
     
    6965    public class FloatModuloExpression : PushResultExpression<double>
    7066    {
    71         public FloatModuloExpression() : base("FLOAT.%")
    72         { }
    73 
    74         public override void Eval(IInterpreter interpreter)
    75         {
    76             this.Eval(interpreter.FloatStack, 2, values => values[0] % values[1], 0);
     67        protected override string InitStringRepresentation() { return "FLOAT.%"; }
     68
     69        public override void Eval(IInterpreter interpreter)
     70        {
     71            Eval(interpreter.FloatStack, 2, values => values[0] % values[1], 0);
    7772        }
    7873    }
     
    8378    public class FloatMinExpression : PushResultExpression<double>
    8479    {
    85         public FloatMinExpression() : base("FLOAT.MIN")
    86         { }
    87 
    88         public override void Eval(IInterpreter interpreter)
    89         {
    90             this.Eval(interpreter.FloatStack, 2, values => Math.Min(values[0], values[1]));
     80        protected override string InitStringRepresentation() { return "FLOAT.MIN"; }
     81
     82        public override void Eval(IInterpreter interpreter)
     83        {
     84            Eval(interpreter.FloatStack, 2, values => Math.Min(values[0], values[1]));
    9185        }
    9286    }
     
    9791    public class FloatMaxExpression : PushResultExpression<double>
    9892    {
    99         public FloatMaxExpression() : base("FLOAT.MAX")
    100         { }
    101 
    102         public override void Eval(IInterpreter interpreter)
    103         {
    104             this.Eval(interpreter.FloatStack, 2, values => Math.Max(values[0], values[1]));
     93        protected override string InitStringRepresentation() { return "FLOAT.MAX"; }
     94
     95        public override void Eval(IInterpreter interpreter)
     96        {
     97            Eval(interpreter.FloatStack, 2, values => Math.Max(values[0], values[1]));
    10598        }
    10699    }
     
    111104    public class FloatSmallerThanExpression : PushResultExpression<double>
    112105    {
    113         public FloatSmallerThanExpression() : base("FLOAT.<")
    114         { }
    115 
    116         public override void Eval(IInterpreter interpreter)
    117         {
    118             this.Eval(
     106        protected override string InitStringRepresentation() { return "FLOAT.<"; }
     107
     108        public override void Eval(IInterpreter interpreter)
     109        {
     110            Eval(
    119111                interpreter.FloatStack,
    120112                interpreter.BooleanStack,
     
    129121    public class FloatGreaterThanExpression : PushResultExpression<double>
    130122    {
    131         public FloatGreaterThanExpression() : base("FLOAT.>")
    132         { }
    133 
    134         public override void Eval(IInterpreter interpreter)
    135         {
    136             this.Eval(
     123        protected override string InitStringRepresentation() { return "FLOAT.>"; }
     124
     125        public override void Eval(IInterpreter interpreter)
     126        {
     127            Eval(
    137128                interpreter.FloatStack,
    138129                interpreter.BooleanStack,
     
    147138    public class FloatSineExpression : PushResultExpression<double>
    148139    {
    149         public FloatSineExpression() : base("FLOAT.SIN")
    150         { }
    151 
    152         public override void Eval(IInterpreter interpreter)
    153         {
    154             this.Eval(
     140        protected override string InitStringRepresentation() { return "FLOAT.SIN"; }
     141
     142        public override void Eval(IInterpreter interpreter)
     143        {
     144            Eval(
    155145                interpreter.FloatStack,
    156146                1,
     
    164154    public class FloatCosineExpression : PushResultExpression<double>
    165155    {
    166         public FloatCosineExpression() : base("FLOAT.COS") { }
    167 
    168         public override void Eval(IInterpreter interpreter)
    169         {
    170             this.Eval(
     156        protected override string InitStringRepresentation() { return "FLOAT.COS"; }
     157
     158        public override void Eval(IInterpreter interpreter)
     159        {
     160            Eval(
    171161                interpreter.FloatStack,
    172162                1,
     
    178168    /// Pushes 1 if the top BOOLEAN is TRUE, or 0 if the top BOOLEAN is FALSE.
    179169    /// </summary>
    180     public class FloatFromBooleanExpression : Expression
    181     {
    182         public FloatFromBooleanExpression() : base("FLOAT.FROMBOOLEAN") { }
     170    public class FloatFromBooleanExpression : StatelessExpression
     171    {
     172        protected override string InitStringRepresentation() { return "FLOAT.FROMBOOLEAN"; }
    183173
    184174        public override void Eval(IInterpreter interpreter)
     
    197187    /// Pushes a floating point version of the top INTEGER.
    198188    /// </summary>
    199     public class FloatFromIntegerExpression : Expression
    200     {
    201         public FloatFromIntegerExpression() : base("FLOAT.FROMINTEGER")
    202         {
    203         }
     189    public class FloatFromIntegerExpression : StatelessExpression
     190    {
     191        protected override string InitStringRepresentation() { return "FLOAT.FROMINTEGER"; }
    204192
    205193        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/FlushExpressions.cs

    r14392 r14398  
    88    /// </summary>
    99    /// <typeparam name="T">Stacktype</typeparam>
    10     public abstract class FlushExpression<T> : Expression
     10    public abstract class FlushExpression<T> : StatelessExpression
    1111    {
    12         public FlushExpression(string stringRepresentation) : base(stringRepresentation)
    13         { }
    14 
    1512        public void Eval(IStack<T> stack)
    1613        {
     
    2118    public class IntegerFlushExpression : FlushExpression<long>
    2219    {
    23         public IntegerFlushExpression() : base("INTEGER.FLUSH")
    24         { }
     20        protected override string InitStringRepresentation() { return "INTEGER.FLUSH"; }
    2521
    2622        public override void Eval(IInterpreter interpreter)
    2723        {
    28             this.Eval(interpreter.IntegerStack);
     24            Eval(interpreter.IntegerStack);
    2925        }
    3026    }
     
    3228    public class FloatFlushExpression : FlushExpression<double>
    3329    {
    34         public FloatFlushExpression() : base("FLOAT.FLUSH")
    35         { }
     30        protected override string InitStringRepresentation() { return "FLOAT.FLUSH"; }
    3631
    3732        public override void Eval(IInterpreter interpreter)
    3833        {
    39             this.Eval(interpreter.FloatStack);
     34            Eval(interpreter.FloatStack);
    4035        }
    4136    }
     
    4338    public class BooleanFlushExpression : FlushExpression<bool>
    4439    {
    45         public BooleanFlushExpression() : base("BOOLEAN.FLUSH")
    46         { }
     40        protected override string InitStringRepresentation() { return "BOOLEAN.FLUSH"; }
    4741
    4842        public override void Eval(IInterpreter interpreter)
    4943        {
    50             this.Eval(interpreter.BooleanStack);
     44            Eval(interpreter.BooleanStack);
    5145        }
    5246    }
     
    5448    public class NameFlushExpression : FlushExpression<string>
    5549    {
    56         public NameFlushExpression() : base("NAME.FLUSH")
    57         { }
     50        protected override string InitStringRepresentation() { return "NAME.FLUSH"; }
    5851
    5952        public override void Eval(IInterpreter interpreter)
    6053        {
    61             this.Eval(interpreter.NameStack);
     54            Eval(interpreter.NameStack);
    6255        }
    6356    }
     
    6558    public class ExecFlushExpression : FlushExpression<Expression>
    6659    {
    67         public ExecFlushExpression() : base("EXEC.FLUSH")
    68         { }
     60        protected override string InitStringRepresentation() { return "EXEC.FLUSH"; }
    6961
    7062        public override void Eval(IInterpreter interpreter)
    7163        {
    72             this.Eval(interpreter.ExecStack);
     64            Eval(interpreter.ExecStack);
    7365        }
    7466    }
     
    7668    public class CodeFlushExpression : FlushExpression<Expression>
    7769    {
    78         public CodeFlushExpression() : base("CODE.FLUSH")
    79         { }
     70        protected override string InitStringRepresentation() { return "CODE.FLUSH"; }
    8071
    8172        public override void Eval(IInterpreter interpreter)
    8273        {
    83             this.Eval(interpreter.CodeStack);
     74            Eval(interpreter.CodeStack);
    8475        }
    8576    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/IntegerExpressions.cs

    r14392 r14398  
    99    public class IntegerAddExpression : PushResultExpression<long>
    1010    {
    11         public IntegerAddExpression() : base("INTEGER.+") { }
     11        protected override string InitStringRepresentation() { return "INTEGER.+"; }
    1212
    1313        public override void Eval(IInterpreter interpreter)
    1414        {
    15             this.Eval(interpreter.IntegerStack, 2, values => values[0] + values[1]);
     15            Eval(interpreter.IntegerStack, 2, values => values[0] + values[1]);
    1616        }
    1717    }
     
    2222    public class IntegerSubtractExpression : PushResultExpression<long>
    2323    {
    24         public IntegerSubtractExpression() : base("INTEGER.-") { }
     24        protected override string InitStringRepresentation() { return "INTEGER.-"; }
    2525
    2626        public override void Eval(IInterpreter interpreter)
    2727        {
    28             this.Eval(interpreter.IntegerStack, 2, values => values[0] - values[1]);
     28            Eval(interpreter.IntegerStack, 2, values => values[0] - values[1]);
    2929        }
    3030    }
     
    3535    public class IntegerMultiplyExpression : PushResultExpression<long>
    3636    {
    37         public IntegerMultiplyExpression() : base("INTEGER.*") { }
     37        protected override string InitStringRepresentation() { return "INTEGER.*"; }
    3838
    3939        public override void Eval(IInterpreter interpreter)
    4040        {
    41             this.Eval(interpreter.IntegerStack, 2, values => values[0] * values[1]);
     41            Eval(interpreter.IntegerStack, 2, values => values[0] * values[1]);
    4242        }
    4343    }
     
    4949    public class IntegerDivideExpression : PushResultExpression<long>
    5050    {
    51         public IntegerDivideExpression() : base("INTEGER./") { }
     51        protected override string InitStringRepresentation() { return "INTEGER./"; }
    5252
    5353        public override void Eval(IInterpreter interpreter)
    5454        {
    55             this.Eval(interpreter.IntegerStack, 2, values => values[0] / values[1], 0);
     55            Eval(interpreter.IntegerStack, 2, values => values[0] / values[1], 0);
    5656        }
    5757    }
     
    6565    public class IntegerModuloExpression : PushResultExpression<long>
    6666    {
    67         public IntegerModuloExpression() : base("INTEGER.%") { }
     67        protected override string InitStringRepresentation() { return "INTEGER.%"; }
    6868
    6969        public override void Eval(IInterpreter interpreter)
    7070        {
    71             this.Eval(interpreter.IntegerStack, 2, values => values[0] % values[1], 0);
     71            Eval(interpreter.IntegerStack, 2, values => values[0] % values[1], 0);
    7272        }
    7373    }
     
    7878    public class IntegerMinExpression : PushResultExpression<long>
    7979    {
    80         public IntegerMinExpression() : base("INTEGER.MIN") { }
     80        protected override string InitStringRepresentation() { return "INTEGER.MIN"; }
    8181
    8282        public override void Eval(IInterpreter interpreter)
    8383        {
    84             this.Eval(interpreter.IntegerStack, 2, values => Math.Min(values[0], values[1]));
     84            Eval(interpreter.IntegerStack, 2, values => Math.Min(values[0], values[1]));
    8585        }
    8686    }
     
    9191    public class IntegerMaxExpression : PushResultExpression<long>
    9292    {
    93         public IntegerMaxExpression() : base("INTEGER.MAX") { }
     93        protected override string InitStringRepresentation() { return "INTEGER.MAX"; }
    9494
    9595        public override void Eval(IInterpreter interpreter)
    9696        {
    97             this.Eval(interpreter.IntegerStack, 2, values => Math.Max(values[0], values[1]));
     97            Eval(interpreter.IntegerStack, 2, values => Math.Max(values[0], values[1]));
    9898        }
    9999    }
     
    104104    public class IntegerSmallerThanExpression : PushResultExpression<long>
    105105    {
    106         public IntegerSmallerThanExpression() : base("INTEGER.<") { }
     106        protected override string InitStringRepresentation() { return "INTEGER.<"; }
    107107
    108108        public override void Eval(IInterpreter interpreter)
    109109        {
    110             this.Eval(
     110            Eval(
    111111                interpreter.IntegerStack,
    112112                interpreter.BooleanStack,
     
    121121    public class IntegerGreaterThanExpression : PushResultExpression<long>
    122122    {
    123         public IntegerGreaterThanExpression() : base("INTEGER.>") { }
     123        protected override string InitStringRepresentation() { return "INTEGER.>"; }
    124124
    125125        public override void Eval(IInterpreter interpreter)
    126126        {
    127             this.Eval(
     127            Eval(
    128128                interpreter.IntegerStack,
    129129                interpreter.BooleanStack,
     
    136136    /// Pushes 1 if the top BOOLEAN is TRUE, or 0 if the top BOOLEAN is FALSE.
    137137    /// </summary>
    138     public class IntegerFromBooleanExpression : Expression
     138    public class IntegerFromBooleanExpression : StatelessExpression
    139139    {
    140         public IntegerFromBooleanExpression() : base("INTEGER.FROMBOOLEAN") { }
     140        protected override string InitStringRepresentation() { return "INTEGER.FROMBOOLEAN"; }
    141141
    142142        public override void Eval(IInterpreter interpreter)
     
    155155    /// Pushes the result of truncating the top FLOAT.
    156156    /// </summary>
    157     public class IntegerFromFloatExpression : Expression
     157    public class IntegerFromFloatExpression : StatelessExpression
    158158    {
    159         public IntegerFromFloatExpression() : base("INTEGER.FROMFLOAT") { }
     159        protected override string InitStringRepresentation() { return "INTEGER.FROMFLOAT"; }
    160160
    161161        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/LoopExpression.cs

    r14392 r14398  
    11using HeuristicLab.Algorithms.PushGP.Interpreter;
    22using HeuristicLab.Algorithms.PushGP.Stack;
     3using HeuristicLab.Common;
    34
    45namespace HeuristicLab.Algorithms.PushGP.Expressions
    56{
    6     public abstract class LoopExpression : Expression
     7    public abstract class LoopExpression : StatefullExpression
    78    {
    8         public long destinationIndex;
    9         public long currentIndex;
    10         public long incrementor;
    11         public bool pushCurrentIndex = false;
    12         public Expression body;
     9        protected long destinationIndex;
     10        protected long currentIndex;
     11        protected long incrementor;
     12        protected Expression body;
    1313
    14         public LoopExpression(string stringRepresentation) : base(stringRepresentation) { }
     14        public LoopExpression()
     15        { }
    1516
    16         protected void Eval(IInterpreter interpreter, IStack<Expression> sourceStack)
     17        /// <summary>
     18        /// Clone constructor
     19        /// </summary>
     20        protected LoopExpression(LoopExpression origin, Cloner cloner) : base(origin, cloner)
     21        {
     22            destinationIndex = origin.destinationIndex;
     23            currentIndex = origin.currentIndex;
     24            incrementor = origin.incrementor;
     25            body = origin.body;
     26        }
     27
     28        protected void Eval(IInterpreter interpreter, IStack<Expression> sourceStack, bool pushCurrentIndex = false)
    1729        {
    1830            // if not initialized
    1931            if (body == null)
    2032            {
    21                 if (this.HasInsufficientArguments(interpreter, sourceStack))
     33                if (HasInsufficientArguments(interpreter, sourceStack))
    2234                {
    2335                    return;
    2436                }
    2537
    26                 this.InitState(interpreter, sourceStack);
     38                InitState(interpreter, sourceStack);
    2739
    28                 interpreter.ExecStack.Push(this, this.body);
     40                interpreter.ExecStack.Push(this, body);
    2941
    3042                return;
     
    3446            if (destinationIndex == currentIndex)
    3547            {
    36                 this.PushLastIteration(interpreter);
    37                 this.Clear();
     48                PushLastIteration(interpreter);
     49                Clear();
    3850
    3951                return;
    4052            }
    4153
    42             this.PushIteration(interpreter);
    43             this.currentIndex += this.incrementor;
     54            PushIteration(interpreter);
     55            currentIndex += incrementor;
    4456        }
    4557
    4658        protected virtual void Clear()
    4759        {
    48             this.body = null;
     60            body = null;
    4961        }
    5062
    5163        protected virtual void PushIteration(IInterpreter interpreter)
    5264        {
    53             interpreter.IntegerStack.Push(this.currentIndex);
    54             interpreter.ExecStack.Push(this, this.body);
     65            interpreter.IntegerStack.Push(currentIndex);
     66            interpreter.ExecStack.Push(this, body);
    5567        }
    5668
    5769        protected virtual void PushLastIteration(IInterpreter interpreter)
    5870        {
    59             interpreter.IntegerStack.Push(this.currentIndex);
    60             interpreter.ExecStack.Push(this.body);
     71            interpreter.IntegerStack.Push(currentIndex);
     72            interpreter.ExecStack.Push(body);
    6173        }
    6274
     
    7183
    7284            var isBodyEqual =
    73                 (this.body == null && other.body == null) ||
    74                 (this.body != null && other.body != null && this.body.Equals(other.body));
     85                (body == null && other.body == null) ||
     86                (body != null && other.body != null && body.Equals(other.body));
    7587
    7688            return isBodyEqual &&
    77                 this.currentIndex == other.currentIndex &&
    78                 this.destinationIndex == other.destinationIndex &&
    79                 this.incrementor == other.incrementor;
     89                currentIndex == other.currentIndex &&
     90                destinationIndex == other.destinationIndex &&
     91                incrementor == other.incrementor;
     92        }
     93
     94        public override int GetHashCode()
     95        {
     96            return base.GetHashCode();
     97        }
     98
     99        protected override int InitId()
     100        {
     101            unchecked
     102            {
     103                var hash = 19;
     104
     105                if (body != null)
     106                {
     107                    hash *= 31 + body.GetHashCode();
     108                }
     109
     110                hash *= 31 + currentIndex.GetHashCode();
     111                hash *= 31 + destinationIndex.GetHashCode();
     112                hash *= 31 + incrementor.GetHashCode();
     113
     114                return hash;
     115            }
    80116        }
    81117
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/NameExpressions.cs

    r14392 r14398  
    1 using System.Linq;
     1using System;
     2using System.Linq;
    23using HeuristicLab.Algorithms.PushGP.Interpreter;
     4using HeuristicLab.Common;
    35using HeuristicLab.Core;
    46using HeuristicLab.Random;
     
    68namespace HeuristicLab.Algorithms.PushGP.Expressions
    79{
    8     public class NameDefineXExecExpression : Expression
     10    public class NameDefineXExecExpression : StatefullExpression
    911    {
    10         public NameDefineXExecExpression(string name) : base(name) { }
     12        private readonly string name;
     13        public NameDefineXExecExpression(string name)
     14        {
     15            this.name = name;
     16        }
     17
     18        public NameDefineXExecExpression(NameDefineXExecExpression origin, Cloner cloner) : base(origin, cloner)
     19        {
     20            name = origin.name;
     21        }
    1122
    1223        public override void Eval(IInterpreter interpreter)
     
    1425            Expression expression;
    1526            if (!interpreter.IsNameQuoteFlagSet &&
    16                 interpreter.CustomExpressions.TryGetValue(this.StringRepresentation, out expression))
     27                interpreter.CustomExpressions.TryGetValue(name, out expression))
    1728            {
    1829                interpreter.ExecStack.Push(expression);
     
    2031            else
    2132            {
    22                 interpreter.NameStack.Push(this.StringRepresentation);
     33                interpreter.NameStack.Push(name);
    2334                interpreter.IsNameQuoteFlagSet = false;
    2435            }
     
    3243            }
    3344
    34             return this.StringRepresentation.Equals(obj.ToString());
     45            var other = obj as NameDefineXExecExpression;
     46
     47            return name.Equals(other.name);
     48        }
     49
     50        public override int GetHashCode()
     51        {
     52            return base.GetHashCode();
     53        }
     54
     55        protected override string InitStringRepresentation()
     56        {
     57            return name;
     58        }
     59
     60        protected override int InitId()
     61        {
     62            return name.GetHashCode();
     63        }
     64
     65        public override IDeepCloneable Clone(Cloner cloner)
     66        {
     67            throw new NotImplementedException();
    3568        }
    3669    }
     
    4174    /// onto the NAME stack the flag will be cleared (whether or not the pushed name had a definition).
    4275    /// </summary>
    43     public class NameQuoteExpression : Expression
     76    public class NameQuoteExpression : StatelessExpression
    4477    {
    45         public NameQuoteExpression() : base("NAME.QUOTE") { }
     78        protected override string InitStringRepresentation()
     79        {
     80            return "NAME.QUOTE";
     81        }
    4682
    4783        public override void Eval(IInterpreter interpreter)
     
    5490    /// Pushes a randomly selected NAME that already has a definition.
    5591    /// </summary>
    56     public class NameRandBoundNameExpression : Expression
     92    public class NameRandBoundNameExpression : StatelessExpression
    5793    {
    5894        private static IRandom rand = new FastRandom();
    5995
    60         public NameRandBoundNameExpression() : base("NAME.RANDBOUNDNAME") { }
     96        protected override string InitStringRepresentation()
     97        {
     98            return "NAME.RANDBOUNDNAME";
     99        }
    61100
    62101        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/PopExpressions.cs

    r14392 r14398  
    44namespace HeuristicLab.Algorithms.PushGP.Expressions
    55{
    6     public abstract class PopExpression<T> : Expression
     6    public abstract class PopExpression<T> : StatelessExpression
    77    {
    8         public PopExpression(string stringRepresentation) : base(stringRepresentation)
    9         {
    10         }
    11 
    128        public void Eval(IStack<T> stack)
    139        {
     
    2117    public class IntegerPopExpression : PopExpression<long>
    2218    {
    23         public IntegerPopExpression() : base("INTEGER.POP")
    24         {
    25         }
     19        protected override string InitStringRepresentation() { return "INTEGER.POP"; }
    2620
    2721        public override void Eval(IInterpreter interpreter)
    2822        {
    29             this.Eval(interpreter.IntegerStack);
     23            Eval(interpreter.IntegerStack);
    3024        }
    3125    }
     
    3327    public class FloatPopExpression : PopExpression<double>
    3428    {
    35         public FloatPopExpression() : base("FLOAT.POP")
    36         {
    37         }
     29        protected override string InitStringRepresentation() { return "FLOAT.POP"; }
    3830
    3931        public override void Eval(IInterpreter interpreter)
    4032        {
    41             this.Eval(interpreter.FloatStack);
     33            Eval(interpreter.FloatStack);
    4234        }
    4335    }
     
    4537    public class BooleanPopExpression : PopExpression<bool>
    4638    {
    47         public BooleanPopExpression() : base("BOOLEAN.POP")
    48         {
    49         }
     39        protected override string InitStringRepresentation() { return "BOOLEAN.POP"; }
    5040
    5141        public override void Eval(IInterpreter interpreter)
    5242        {
    53             this.Eval(interpreter.BooleanStack);
     43            Eval(interpreter.BooleanStack);
    5444        }
    5545    }
     
    5747    public class NamePopExpression : PopExpression<string>
    5848    {
    59         public NamePopExpression() : base("NAME.POP")
    60         {
    61         }
     49        protected override string InitStringRepresentation() { return "NAME.POP"; }
    6250
    6351        public override void Eval(IInterpreter interpreter)
    6452        {
    65             this.Eval(interpreter.NameStack);
     53            Eval(interpreter.NameStack);
    6654        }
    6755    }
     
    6957    public class ExecPopExpression : PopExpression<Expression>
    7058    {
    71         public ExecPopExpression() : base("EXEC.POP")
    72         {
    73         }
     59        protected override string InitStringRepresentation() { return "EXEC.POP"; }
    7460
    7561        public override void Eval(IInterpreter interpreter)
    7662        {
    77             this.Eval(interpreter.ExecStack);
     63            Eval(interpreter.ExecStack);
    7864        }
    7965    }
     
    8167    public class CodePopExpression : PopExpression<Expression>
    8268    {
    83         public CodePopExpression() : base("CODE.POP")
    84         {
    85         }
     69        protected override string InitStringRepresentation() { return "CODE.POP"; }
    8670
    8771        public override void Eval(IInterpreter interpreter)
    8872        {
    89             this.Eval(interpreter.CodeStack);
     73            Eval(interpreter.CodeStack);
    9074        }
    9175    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/PushExpressions.cs

    r14392 r14398  
    55namespace HeuristicLab.Algorithms.PushGP.Expressions
    66{
    7     public abstract class PushExpression<T> : Expression
     7    public abstract class PushExpression<T> : StatefullExpression
    88    {
    99        protected readonly T value;
    1010
    11         public PushExpression(T value) : base(value.ToString(), value.GetHashCode())
     11        public PushExpression(T value)
    1212        {
    1313            this.value = value;
     
    1717        public PushExpression(PushExpression<T> expression, Cloner cloner) : base(expression, cloner)
    1818        {
    19             this.value = expression.value;
     19            value = expression.value;
     20        }
     21
     22        protected override int InitId()
     23        {
     24            return this.value.GetHashCode();
     25        }
     26
     27        protected override string InitStringRepresentation()
     28        {
     29            return this.value.ToString();
    2030        }
    2131
    2232        protected void Eval(IStack<T> stack)
    2333        {
    24             stack.Push(this.value);
     34            stack.Push(value);
    2535        }
    2636
     
    3444            var other = obj as PushExpression<T>;
    3545
    36             return this.value.Equals(value);
     46            return value.Equals(value);
     47        }
     48
     49        public override int GetHashCode()
     50        {
     51            return base.GetHashCode();
    3752        }
    3853    }
     
    4964        public override void Eval(IInterpreter interpreter)
    5065        {
    51             this.Eval(interpreter.IntegerStack);
     66            Eval(interpreter.IntegerStack);
    5267        }
    5368
     
    6984        public override void Eval(IInterpreter interpreter)
    7085        {
    71             this.Eval(interpreter.FloatStack);
     86            Eval(interpreter.FloatStack);
    7287        }
    7388
     
    89104        public override void Eval(IInterpreter interpreter)
    90105        {
    91             this.Eval(interpreter.BooleanStack);
     106            Eval(interpreter.BooleanStack);
    92107        }
    93108
     
    109124        public override void Eval(IInterpreter interpreter)
    110125        {
    111             this.Eval(interpreter.NameStack);
     126            Eval(interpreter.NameStack);
    112127        }
    113128
     
    129144        public override void Eval(IInterpreter interpreter)
    130145        {
    131             this.Eval(interpreter.ExecStack);
     146            Eval(interpreter.ExecStack);
    132147        }
    133148
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/PushResultExpression.cs

    r14392 r14398  
    44namespace HeuristicLab.Algorithms.PushGP.Expressions
    55{
    6     public abstract class PushResultExpression<T> : Expression
     6    public abstract class PushResultExpression<T> : StatelessExpression
    77    {
    8         public PushResultExpression(string stringRepresentation) : base(stringRepresentation)
    9         { }
    10 
    118        protected void Eval(IStack<T> stack, int count, Func<T[], T> templateFunc)
    129        {
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/RandExpressions.cs

    r14392 r14398  
    77    /// Pushes a random NAME.
    88    /// </summary>
    9     public class NameRandExpression : Expression
     9    public class NameRandExpression : StatelessExpression
    1010    {
    11         public NameRandExpression() : base("NAME.RAND")
    12         {
    13         }
     11        protected override string InitStringRepresentation() { return "NAME.RAND"; }
    1412
    1513        public override void Eval(IInterpreter interpreter)
     
    2422    /// Pushes a random integer.
    2523    /// </summary>
    26     public class IntegerRandExpression : Expression
     24    public class IntegerRandExpression : StatelessExpression
    2725    {
    28         public IntegerRandExpression() : base("INTEGER.RAND")
    29         {
    30         }
     26        protected override string InitStringRepresentation() { return "INTEGER.RAND"; }
    3127
    3228        public override void Eval(IInterpreter interpreter)
     
    4339    /// Pushes a random float.
    4440    /// </summary>
    45     public class FloatRandExpression : Expression
     41    public class FloatRandExpression : StatelessExpression
    4642    {
    47         public FloatRandExpression() : base("FLOAT.RAND")
    48         {
    49         }
     43        protected override string InitStringRepresentation() { return "FLOAT.RAND"; }
    5044
    5145        public override void Eval(IInterpreter interpreter)
     
    6256    /// Pushes a random boolean.
    6357    /// </summary>
    64     public class BooleanRandExpression : Expression
     58    public class BooleanRandExpression : StatelessExpression
    6559    {
    66         public BooleanRandExpression() : base("BOOLEAN.RAND")
    67         {
    68         }
     60        protected override string InitStringRepresentation() { return "BOOLEAN.RAND"; }
    6961
    7062        public override void Eval(IInterpreter interpreter)
     
    7971    /// Pushes random expressions onto the code stack.
    8072    /// </summary>
    81     public class CodeRandExpression : Expression
     73    public class CodeRandExpression : StatelessExpression
    8274    {
    83         public CodeRandExpression() : base("CODE.RAND")
    84         {
    85         }
     75        protected override string InitStringRepresentation() { return "CODE.RAND"; }
    8676
    8777        public override void Eval(IInterpreter interpreter)
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/RotateExpressions.cs

    r14392 r14398  
    44namespace HeuristicLab.Algorithms.PushGP.Expressions
    55{
    6     public abstract class RotateExpression<T> : Expression
     6    public abstract class RotateExpression<T> : StatelessExpression
    77    {
    8         public RotateExpression(string stringRepresentation) : base(stringRepresentation)
    9         { }
    10 
    118        public void Eval(IStack<T> stack)
    129        {
     
    2017    public class IntegerRotateExpression : RotateExpression<long>
    2118    {
    22         public IntegerRotateExpression() : base("INTEGER.ROT")
    23         { }
     19        protected override string InitStringRepresentation() { return "INTEGER.ROT"; }
    2420
    2521        public override void Eval(IInterpreter interpreter)
    2622        {
    27             this.Eval(interpreter.IntegerStack);
     23            Eval(interpreter.IntegerStack);
    2824        }
    2925    }
     
    3127    public class FloatRotateExpression : RotateExpression<double>
    3228    {
    33         public FloatRotateExpression() : base("FLOAT.ROT")
    34         { }
     29        protected override string InitStringRepresentation() { return "FLOAT.ROT"; }
    3530
    3631        public override void Eval(IInterpreter interpreter)
    3732        {
    38             this.Eval(interpreter.FloatStack);
     33            Eval(interpreter.FloatStack);
    3934        }
    4035    }
     
    4237    public class BooleanRotateExpression : RotateExpression<bool>
    4338    {
    44         public BooleanRotateExpression() : base("BOOLEAN.ROT")
    45         { }
     39        protected override string InitStringRepresentation() { return "BOOLEAN.ROT"; }
    4640
    4741        public override void Eval(IInterpreter interpreter)
    4842        {
    49             this.Eval(interpreter.BooleanStack);
     43            Eval(interpreter.BooleanStack);
    5044        }
    5145    }
     
    5347    public class NameRotateExpression : RotateExpression<string>
    5448    {
    55         public NameRotateExpression() : base("NAME.ROT")
    56         { }
     49        protected override string InitStringRepresentation() { return "NAME.ROT"; }
    5750
    5851        public override void Eval(IInterpreter interpreter)
    5952        {
    60             this.Eval(interpreter.NameStack);
     53            Eval(interpreter.NameStack);
    6154        }
    6255    }
     
    6457    public class ExecRotateExpression : RotateExpression<Expression>
    6558    {
    66         public ExecRotateExpression() : base("EXEC.ROT")
    67         { }
     59        protected override string InitStringRepresentation() { return "EXEC.ROT"; }
    6860
    6961        public override void Eval(IInterpreter interpreter)
    7062        {
    71             this.Eval(interpreter.ExecStack);
     63            Eval(interpreter.ExecStack);
    7264        }
    7365    }
     
    7567    public class CodeRotateExpression : RotateExpression<Expression>
    7668    {
    77         public CodeRotateExpression() : base("CODE.ROT")
    78         { }
     69        protected override string InitStringRepresentation() { return "CODE.ROT"; }
    7970
    8071        public override void Eval(IInterpreter interpreter)
    8172        {
    82             this.Eval(interpreter.CodeStack);
     73            Eval(interpreter.CodeStack);
    8374        }
    8475    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/ShoveExpressions.cs

    r14392 r14398  
    44namespace HeuristicLab.Algorithms.PushGP.Expressions
    55{
    6     public abstract class ShoveExpression<T> : Expression
     6    public abstract class ShoveExpression<T> : StatelessExpression
    77    {
    8         public ShoveExpression(string stringRepresentation) : base(stringRepresentation)
    9         { }
    10 
    118        public void Eval(IStack<T> stack, IStack<long> integerStack, int count = 1)
    129        {
     
    2926    public class IntegerShoveExpression : ShoveExpression<long>
    3027    {
    31         public IntegerShoveExpression() : base("INTEGER.SHOVE")
    32         { }
     28        protected override string InitStringRepresentation() { return "INTEGER.SHOVE"; }
    3329
    3430        public override void Eval(IInterpreter interpreter)
    3531        {
    36             this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
     32            Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
    3733        }
    3834    }
     
    4036    public class FloatShoveExpression : ShoveExpression<double>
    4137    {
    42         public FloatShoveExpression() : base("FLOAT.SHOVE")
    43         { }
     38        protected override string InitStringRepresentation() { return "FLOAT.SHOVE"; }
    4439
    4540        public override void Eval(IInterpreter interpreter)
    4641        {
    47             this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
     42            Eval(interpreter.FloatStack, interpreter.IntegerStack);
    4843        }
    4944    }
     
    5146    public class BooleanShoveExpression : ShoveExpression<bool>
    5247    {
    53         public BooleanShoveExpression() : base("BOOLEAN.SHOVE")
    54         { }
     48        protected override string InitStringRepresentation() { return "BOOLEAN.SHOVE"; }
    5549
    5650        public override void Eval(IInterpreter interpreter)
    5751        {
    58             this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
     52            Eval(interpreter.BooleanStack, interpreter.IntegerStack);
    5953        }
    6054    }
     
    6256    public class NameShoveExpression : ShoveExpression<string>
    6357    {
    64         public NameShoveExpression() : base("NAME.SHOVE")
    65         { }
     58        protected override string InitStringRepresentation() { return "NAME.SHOVE"; }
    6659
    6760        public override void Eval(IInterpreter interpreter)
    6861        {
    69             this.Eval(interpreter.NameStack, interpreter.IntegerStack);
     62            Eval(interpreter.NameStack, interpreter.IntegerStack);
    7063        }
    7164    }
     
    7366    public class ExecShoveExpression : ShoveExpression<Expression>
    7467    {
    75         public ExecShoveExpression() : base("EXEC.SHOVE")
    76         { }
     68        protected override string InitStringRepresentation() { return "EXEC.SHOVE"; }
    7769
    7870        public override void Eval(IInterpreter interpreter)
    7971        {
    80             this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
     72            Eval(interpreter.ExecStack, interpreter.IntegerStack);
    8173        }
    8274    }
     
    8476    public class CodeShoveExpression : ShoveExpression<Expression>
    8577    {
    86         public CodeShoveExpression() : base("CODE.SHOVE")
    87         { }
     78        protected override string InitStringRepresentation() { return "CODE.SHOVE"; }
    8879
    8980        public override void Eval(IInterpreter interpreter)
    9081        {
    91             this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
     82            Eval(interpreter.CodeStack, interpreter.IntegerStack);
    9283        }
    9384    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/StackdepthExpressions.cs

    r14392 r14398  
    88    /// </summary>
    99    /// <typeparam name="T">Stacktype</typeparam>
    10     public abstract class StackdepthExpression<T> : Expression
     10    public abstract class StackdepthExpression<T> : StatelessExpression
    1111    {
    12         public StackdepthExpression(string stringRepresentation) : base(stringRepresentation)
    13         { }
    14 
    1512        public void Eval(IStack<T> stack, IStack<long> integerStack, bool incremental = false)
    1613        {
     
    2825    public class IntegerStackdepthExpression : StackdepthExpression<long>
    2926    {
    30         public IntegerStackdepthExpression() : base("INTEGER.STACKDEPTH")
    31         { }
     27        protected override string InitStringRepresentation() { return "INTEGER.STACKDEPTH"; }
    3228
    3329        public override void Eval(IInterpreter interpreter)
    3430        {
    35             this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
     31            Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
    3632        }
    3733    }
     
    3935    public class FloatStackdepthExpression : StackdepthExpression<double>
    4036    {
    41         public FloatStackdepthExpression() : base("FLOAT.STACKDEPTH")
    42         { }
     37        protected override string InitStringRepresentation() { return "FLOAT.STACKDEPTH"; }
    4338
    4439        public override void Eval(IInterpreter interpreter)
    4540        {
    46             this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
     41            Eval(interpreter.FloatStack, interpreter.IntegerStack);
    4742        }
    4843    }
     
    5045    public class BooleanStackdepthExpression : StackdepthExpression<bool>
    5146    {
    52         public BooleanStackdepthExpression() : base("BOOLEAN.STACKDEPTH")
    53         { }
     47        protected override string InitStringRepresentation() { return "BOOLEAN.STACKDEPTH"; }
    5448
    5549        public override void Eval(IInterpreter interpreter)
    5650        {
    57             this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
     51            Eval(interpreter.BooleanStack, interpreter.IntegerStack);
    5852        }
    5953    }
     
    6155    public class NameStackdepthExpression : StackdepthExpression<string>
    6256    {
    63         public NameStackdepthExpression() : base("NAME.STACKDEPTH")
    64         { }
     57        protected override string InitStringRepresentation() { return "NAME.STACKDEPTH"; }
    6558
    6659        public override void Eval(IInterpreter interpreter)
    6760        {
    68             this.Eval(interpreter.NameStack, interpreter.IntegerStack);
     61            Eval(interpreter.NameStack, interpreter.IntegerStack);
    6962        }
    7063    }
     
    7265    public class ExecStackdepthExpression : StackdepthExpression<Expression>
    7366    {
    74         public ExecStackdepthExpression() : base("EXEC.STACKDEPTH")
    75         { }
     67        protected override string InitStringRepresentation() { return "EXEC.STACKDEPTH"; }
    7668
    7769        public override void Eval(IInterpreter interpreter)
    7870        {
    79             this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
     71            Eval(interpreter.ExecStack, interpreter.IntegerStack);
    8072        }
    8173    }
     
    8375    public class CodeStackdepthExpression : StackdepthExpression<Expression>
    8476    {
    85         public CodeStackdepthExpression() : base("CODE.STACKDEPTH")
    86         { }
     77        protected override string InitStringRepresentation() { return "CODE.STACKDEPTH"; }
    8778
    8879        public override void Eval(IInterpreter interpreter)
    8980        {
    90             this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
     81            Eval(interpreter.CodeStack, interpreter.IntegerStack);
    9182        }
    9283    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/SwapExpressions.cs

    r14392 r14398  
    88    /// </summary>
    99    /// <typeparam name="T">Stacktype</typeparam>
    10     public abstract class SwapExpression<T> : Expression
     10    public abstract class SwapExpression<T> : StatelessExpression
    1111    {
    12         public SwapExpression(string stringRepresentation) : base(stringRepresentation)
    13         { }
    14 
    1512        public void Eval(IStack<T> stack)
    1613        {
     
    2421    public class IntegerSwapExpression : SwapExpression<long>
    2522    {
    26         public IntegerSwapExpression() : base("INTEGER.SWAP")
    27         { }
     23        protected override string InitStringRepresentation() { return "INTEGER.SWAP"; }
    2824
    2925        public override void Eval(IInterpreter interpreter)
    3026        {
    31             this.Eval(interpreter.IntegerStack);
     27            Eval(interpreter.IntegerStack);
    3228        }
    3329    }
     
    3531    public class FloatSwapExpression : SwapExpression<double>
    3632    {
    37         public FloatSwapExpression() : base("FLOAT.SWAP")
    38         { }
     33        protected override string InitStringRepresentation() { return "FLOAT.SWAP"; }
    3934
    4035        public override void Eval(IInterpreter interpreter)
    4136        {
    42             this.Eval(interpreter.FloatStack);
     37            Eval(interpreter.FloatStack);
    4338        }
    4439    }
     
    4641    public class BooleanSwapExpression : SwapExpression<bool>
    4742    {
    48         public BooleanSwapExpression() : base("BOOLEAN.SWAP")
    49         { }
     43        protected override string InitStringRepresentation() { return "BOOLEAN.SWAP"; }
    5044
    5145        public override void Eval(IInterpreter interpreter)
    5246        {
    53             this.Eval(interpreter.BooleanStack);
     47            Eval(interpreter.BooleanStack);
    5448        }
    5549    }
     
    5751    public class NameSwapExpression : SwapExpression<string>
    5852    {
    59         public NameSwapExpression() : base("NAME.SWAP")
    60         { }
     53        protected override string InitStringRepresentation() { return "NAME.SWAP"; }
    6154
    6255        public override void Eval(IInterpreter interpreter)
    6356        {
    64             this.Eval(interpreter.NameStack);
     57            Eval(interpreter.NameStack);
    6558        }
    6659    }
     
    6861    public class ExecSwapExpression : SwapExpression<Expression>
    6962    {
    70         public ExecSwapExpression() : base("EXEC.SWAP")
    71         { }
     63        protected override string InitStringRepresentation() { return "EXEC.SWAP"; }
    7264
    7365        public override void Eval(IInterpreter interpreter)
    7466        {
    75             this.Eval(interpreter.ExecStack);
     67            Eval(interpreter.ExecStack);
    7668        }
    7769    }
     
    7971    public class CodeSwapExpression : SwapExpression<Expression>
    8072    {
    81         public CodeSwapExpression() : base("CODE.SWAP")
    82         { }
     73        protected override string InitStringRepresentation() { return "CODE.SWAP"; }
    8374
    8475        public override void Eval(IInterpreter interpreter)
    8576        {
    86             this.Eval(interpreter.CodeStack);
     77            Eval(interpreter.CodeStack);
    8778        }
    8879    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/YankDuplicateExpressions.cs

    r14392 r14398  
    99    /// </summary>
    1010    /// <typeparam name="T">Stacktype</typeparam>
    11     public abstract class YankDuplicateExpression<T> : Expression
     11    public abstract class YankDuplicateExpression<T> : StatelessExpression
    1212    {
    13         public YankDuplicateExpression(string stringRepresentation) : base(stringRepresentation)
    14         { }
    15 
    1613        public void Eval(IStack<T> stack, IStack<long> integerStack, int count = 1)
    1714        {
     
    3532    public class IntegerYankDuplicateExpression : YankDuplicateExpression<long>
    3633    {
    37         public IntegerYankDuplicateExpression() : base("INTEGER.YANKDUP")
    38         { }
     34        protected override string InitStringRepresentation() { return "INTEGER.YANKDUP"; }
    3935
    4036        public override void Eval(IInterpreter interpreter)
    4137        {
    42             this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
     38            Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
    4339        }
    4440    }
     
    4642    public class FloatYankDuplicateExpression : YankDuplicateExpression<double>
    4743    {
    48         public FloatYankDuplicateExpression() : base("FLOAT.YANKDUP")
    49         { }
     44        protected override string InitStringRepresentation() { return "FLOAT.YANKDUP"; }
    5045
    5146        public override void Eval(IInterpreter interpreter)
    5247        {
    53             this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
     48            Eval(interpreter.FloatStack, interpreter.IntegerStack);
    5449        }
    5550    }
     
    5752    public class BooleanYankDuplicateExpression : YankDuplicateExpression<bool>
    5853    {
    59         public BooleanYankDuplicateExpression() : base("BOOLEAN.YANKDUP")
    60         { }
     54        protected override string InitStringRepresentation() { return "BOOLEAN.YANKDUP"; }
    6155
    6256        public override void Eval(IInterpreter interpreter)
    6357        {
    64             this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
     58            Eval(interpreter.BooleanStack, interpreter.IntegerStack);
    6559        }
    6660    }
     
    6862    public class NameYankDuplicateExpression : YankDuplicateExpression<string>
    6963    {
    70         public NameYankDuplicateExpression() : base("NAME.YANKDUP")
    71         { }
     64        protected override string InitStringRepresentation() { return "NAME.YANKDUP"; }
    7265
    7366        public override void Eval(IInterpreter interpreter)
    7467        {
    75             this.Eval(interpreter.NameStack, interpreter.IntegerStack);
     68            Eval(interpreter.NameStack, interpreter.IntegerStack);
    7669        }
    7770    }
     
    7972    public class ExecYankDuplicateExpression : YankDuplicateExpression<Expression>
    8073    {
    81         public ExecYankDuplicateExpression() : base("EXEC.YANKDUP")
    82         { }
     74        protected override string InitStringRepresentation() { return "EXEC.YANKDUP"; }
    8375
    8476        public override void Eval(IInterpreter interpreter)
    8577        {
    86             this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
     78            Eval(interpreter.ExecStack, interpreter.IntegerStack);
    8779        }
    8880    }
     
    9082    public class CodeYankDuplicateExpression : YankDuplicateExpression<Expression>
    9183    {
    92         public CodeYankDuplicateExpression() : base("CODE.YANKDUP")
    93         { }
     84        protected override string InitStringRepresentation() { return "CODE.YANKDUP"; }
    9485
    9586        public override void Eval(IInterpreter interpreter)
    9687        {
    97             this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
     88            Eval(interpreter.CodeStack, interpreter.IntegerStack);
    9889        }
    9990    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/YankExpressions.cs

    r14392 r14398  
    99    /// </summary>
    1010    /// <typeparam name="T">Stacktype</typeparam>
    11     public abstract class YankExpression<T> : Expression
     11    public abstract class YankExpression<T> : StatelessExpression
    1212    {
    13         public YankExpression(string stringRepresentation) : base(stringRepresentation)
    14         { }
    15 
    1613        public void Eval(IStack<T> stack, IStack<long> integerStack, int count = 1)
    1714        {
     
    3330    public class IntegerYankExpression : YankExpression<long>
    3431    {
    35         public IntegerYankExpression() : base("INTEGER.YANK")
    36         { }
     32        protected override string InitStringRepresentation() { return "INTEGER.YANK"; }
    3733
    3834        public override void Eval(IInterpreter interpreter)
    3935        {
    40             this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
     36            Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
    4137        }
    4238    }
     
    4440    public class FloatYankExpression : YankExpression<double>
    4541    {
    46         public FloatYankExpression() : base("FLOAT.YANK")
    47         { }
     42        protected override string InitStringRepresentation() { return "FLOAT.YANK"; }
    4843
    4944        public override void Eval(IInterpreter interpreter)
    5045        {
    51             this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
     46            Eval(interpreter.FloatStack, interpreter.IntegerStack);
    5247        }
    5348    }
     
    5550    public class BooleanYankExpression : YankExpression<bool>
    5651    {
    57         public BooleanYankExpression() : base("BOOLEAN.YANK")
    58         { }
     52        protected override string InitStringRepresentation() { return "BOOLEAN.YANK"; }
    5953
    6054        public override void Eval(IInterpreter interpreter)
    6155        {
    62             this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
     56            Eval(interpreter.BooleanStack, interpreter.IntegerStack);
    6357        }
    6458    }
     
    6660    public class NameYankExpression : YankExpression<string>
    6761    {
    68         public NameYankExpression() : base("NAME.YANK")
    69         { }
     62        protected override string InitStringRepresentation() { return "NAME.YANK"; }
    7063
    7164        public override void Eval(IInterpreter interpreter)
    7265        {
    73             this.Eval(interpreter.NameStack, interpreter.IntegerStack);
     66            Eval(interpreter.NameStack, interpreter.IntegerStack);
    7467        }
    7568    }
     
    7770    public class ExecYankExpression : YankExpression<Expression>
    7871    {
    79         public ExecYankExpression() : base("EXEC.YANK")
    80         { }
     72        protected override string InitStringRepresentation() { return "EXEC.YANK"; }
    8173
    8274        public override void Eval(IInterpreter interpreter)
    8375        {
    84             this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
     76            Eval(interpreter.ExecStack, interpreter.IntegerStack);
    8577        }
    8678    }
     
    8880    public class CodeYankExpression : YankExpression<Expression>
    8981    {
    90         public CodeYankExpression() : base("CODE.YANK")
    91         { }
     82        protected override string InitStringRepresentation() { return "CODE.YANK"; }
    9283
    9384        public override void Eval(IInterpreter interpreter)
    9485        {
    95             this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
     86            Eval(interpreter.CodeStack, interpreter.IntegerStack);
    9687        }
    9788    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/CodeGenerator.cs

    r14392 r14398  
    4646            if (points == 1)
    4747            {
    48                 var index = random.Next(0, ExpressionTable.Count + this.interpreter.CustomExpressions.Count - 2);
    49                 return new[] { this.CreateExpression(index) };
     48                var index = random.Next(0, ExpressionTable.Count + interpreter.CustomExpressions.Count - 2);
     49                return new[] { CreateExpression(index) };
    5050            }
    5151            else
     
    7373            return (index >= 0 && index < ExpressionTable.Count)
    7474                ? ExpressionTable.GetExpression(index)
    75                 : new NameDefineXExecExpression(this.interpreter.CustomExpressions.ElementAt(index - (ExpressionTable.Count - 1)).Key);
     75                : new NameDefineXExecExpression(interpreter.CustomExpressions.ElementAt(index - (ExpressionTable.Count - 1)).Key);
    7676        }
    7777    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj

    r14397 r14398  
    5252  </ItemGroup>
    5353  <ItemGroup>
     54    <Compile Include="Data\ExpressionNode.cs" />
     55    <Compile Include="Data\ExpressionTree.cs" />
    5456    <Compile Include="Exporter\Exporter.cs" />
    5557    <Compile Include="Expressions\BooleanExpressions.cs" />
     
    6365    <Compile Include="Expressions\EqualsExpressions.cs" />
    6466    <Compile Include="Expressions\RandExpressions.cs" />
    65     <Compile Include="Expressions\SetExpressions.cs" />
     67    <Compile Include="Expressions\StatefullExpression.cs" />
     68    <Compile Include="Expressions\StatelessExpression.cs" />
    6669    <Compile Include="Expressions\YankDuplicateExpressions.cs" />
    6770    <Compile Include="Expressions\YankExpressions.cs" />
     
    8285    <Compile Include="Simplifier\ISimplifier.cs" />
    8386    <Compile Include="Simplifier\RandomSimplifier.cs" />
    84     <Compile Include="StateFullExpressionAttribute.cs" />
    8587    <Compile Include="Generators\BooleanGenerator.cs" />
    8688    <Compile Include="Generators\FloatGenerator.cs" />
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Interpreter/Configuration.cs

    r14397 r14398  
    88        public Configuration()
    99        {
    10             this.IsBooleanStackEnabled = true;
    11             this.IsIntegerStackEnabled = true;
    12             this.IsFloatStackEnabled = true;
    13             this.IsCodeStackEnabled = true;
    14             this.IsNameStackEnabled = true;
     10            IsBooleanStackEnabled = true;
     11            IsIntegerStackEnabled = true;
     12            IsFloatStackEnabled = true;
     13            IsCodeStackEnabled = true;
     14            IsNameStackEnabled = true;
    1515
    16             this.EvalPushLimit = 4096;
    17             this.MaxPointsInProgram = 128;
    18             this.MaxPointsInRandomExpression = 1024;
     16            EvalPushLimit = 4096;
     17            MaxPointsInProgram = 128;
     18            MaxPointsInRandomExpression = 1024;
    1919
    20             this.TopLevelPushCode = true;
    21             this.TopLevelPopCode = false;
     20            TopLevelPushCode = true;
     21            TopLevelPopCode = false;
    2222
    23             this.RandomSeedMax = 30081;
    24             this.RandomSeedMin = 0;
    25             this.RandomSeed = null;
     23            RandomSeedMax = 30081;
     24            RandomSeedMin = 0;
     25            RandomSeed = null;
    2626
    27             this.MinRandomInteger = -128;
    28             this.MaxRandomInteger = 128;
    29             this.MinRandomFloat = -128D;
    30             this.MaxRandomFloat = 128D;
    31             this.NewErcNameProbability = 0.5;
     27            MinRandomInteger = -128;
     28            MaxRandomInteger = 128;
     29            MinRandomFloat = -128D;
     30            MaxRandomFloat = 128D;
     31            NewErcNameProbability = 0.5;
    3232        }
    3333
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Interpreter/PushGPInterpreter.cs

    r14392 r14398  
    1616        public PushGPInterpreter(Configuration config = null)
    1717        {
    18             this.Configuration = config ?? new Configuration();
    19 
    20             this.CodeStack = new PushGPStack<Expression>(128);
    21             this.ExecStack = new PushGPStack<Expression>(128);
    22             this.NameStack = new PushGPStack<string>(16);
    23             this.BooleanStack = new PushGPStack<bool>(16);
    24             this.IntegerStack = new PushGPStack<long>(16);
    25             this.FloatStack = new PushGPStack<double>(16);
    26 
    27             this.CustomExpressions = new Dictionary<string, Expression>();
    28 
    29             this.CodeGenerator = new CodeGenerator(this);
     18            Configuration = config ?? new Configuration();
     19
     20            CodeStack = new PushGPStack<Expression>(128);
     21            ExecStack = new PushGPStack<Expression>(128);
     22            NameStack = new PushGPStack<string>(16);
     23            BooleanStack = new PushGPStack<bool>(16);
     24            IntegerStack = new PushGPStack<long>(16);
     25            FloatStack = new PushGPStack<double>(16);
     26
     27            CustomExpressions = new Dictionary<string, Expression>();
     28
     29            CodeGenerator = new CodeGenerator(this);
    3030        }
    3131
     
    3535        public bool IsPaused { get; private set; }
    3636        public bool IsAborted { get; private set; }
    37         public bool IsRunning { get { return this.ExecStack.Count > 0 && !IsPaused && !IsAborted && ExecCounter < Configuration.EvalPushLimit; } }
    38         public bool IsCompleted { get { return this.ExecStack.Count == 0; } }
     37        public bool IsRunning { get { return ExecStack.Count > 0 && !IsPaused && !IsAborted && ExecCounter < Configuration.EvalPushLimit; } }
     38        public bool IsCompleted { get { return ExecStack.Count == 0; } }
    3939        public bool CanStep { get { return !IsCompleted && !IsAborted && IsPaused; } }
    4040
     
    5454        public void Reset()
    5555        {
    56             this.IsAborted = false;
    57             this.IsPaused = false;
    58             this.currentTask = null;
    59 
    60             this.Clear();
     56            IsAborted = false;
     57            IsPaused = false;
     58            currentTask = null;
     59
     60            Clear();
    6161        }
    6262
    6363        public void Clear()
    6464        {
    65             this.ExecCounter = 0;
    66 
    67             this.ExecStack.Clear();
    68             this.CodeStack.Clear();
    69             this.NameStack.Clear();
    70             this.BooleanStack.Clear();
    71             this.IntegerStack.Clear();
    72             this.FloatStack.Clear();
    73 
    74             this.CustomExpressions.Clear();
     65            ExecCounter = 0;
     66
     67            ExecStack.Clear();
     68            CodeStack.Clear();
     69            NameStack.Clear();
     70            BooleanStack.Clear();
     71            IntegerStack.Clear();
     72            FloatStack.Clear();
     73
     74            CustomExpressions.Clear();
    7575        }
    7676
     
    7878        {
    7979            var program = Encode(code);
    80             this.Interpret(program);
     80            Interpret(program);
    8181        }
    8282
     
    8585            var program = Encode(code);
    8686
    87             this.currentTask = this.InterpretAsync(program, paused, token);
     87            currentTask = InterpretAsync(program, paused, token);
    8888
    8989            return currentTask;
     
    9292        public Task InterpretAsync(Expression program, bool paused = false, CancellationToken token = default(CancellationToken))
    9393        {
    94             this.IsPaused = paused;
    95             this.currentTask = Task.Run(() => this.Interpret(program), token);
     94            IsPaused = paused;
     95            currentTask = Task.Run(() => Interpret(program), token);
    9696
    9797            return currentTask;
     
    103103             * If the top expression is a single statement then the loop has nothing to do
    104104             * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */
    105             this.ExecStack.Push(program);
    106 
    107             if (this.Configuration.TopLevelPushCode)
    108             {
    109                 this.CodeStack.Insert(0, program);
     105            ExecStack.Push(program);
     106
     107            if (Configuration.TopLevelPushCode)
     108            {
     109                CodeStack.Insert(0, program);
    110110            }
    111111
    112112            // run top expression
    113             this.ExecStack.Pop().Eval(this);
    114 
    115             this.Interpret();
     113            ExecStack.Pop().Eval(this);
     114
     115            Interpret();
    116116        }
    117117
    118118        private void Interpret()
    119119        {
    120             while (this.IsRunning)
    121             {
    122                 this.DoStep();
    123                 this.ExecCounter++;
    124             }
    125 
    126             this.Finally();
     120            while (IsRunning)
     121            {
     122                DoStep();
     123                ExecCounter++;
     124            }
     125
     126            Finally();
    127127        }
    128128
    129129        private void Finally()
    130130        {
    131             if (this.IsCompleted && this.Configuration.TopLevelPopCode && this.CodeStack.Count > 0)
    132             {
    133                 this.CodeStack.Pop();
     131            if (IsCompleted && Configuration.TopLevelPopCode && CodeStack.Count > 0)
     132            {
     133                CodeStack.Pop();
    134134            }
    135135        }
     
    137137        private void DoStep()
    138138        {
    139             this.ExecStack.Pop().Eval(this);
     139            ExecStack.Pop().Eval(this);
    140140        }
    141141
    142142        private Task InterpreteAsync()
    143143        {
    144             this.currentTask = Task.Run(() => this.Interpret());
    145 
    146             return this.currentTask;
     144            currentTask = Task.Run(() => Interpret());
     145
     146            return currentTask;
    147147        }
    148148
    149149        public async Task AbortAsync()
    150150        {
    151             if (this.IsAborted || this.IsCompleted)
     151            if (IsAborted || IsCompleted)
    152152                return;
    153153
    154             this.IsAborted = true;
    155 
    156             if (this.currentTask != null)
    157             {
    158                 await this.currentTask;
     154            IsAborted = true;
     155
     156            if (currentTask != null)
     157            {
     158                await currentTask;
    159159            }
    160160        }
     
    162162        public async Task AbortAndResetAsync()
    163163        {
    164             await this.AbortAsync();
    165             this.Reset();
     164            await AbortAsync();
     165            Reset();
    166166        }
    167167
    168168        public async Task PauseAsync()
    169169        {
    170             if (this.IsPaused || this.IsCompleted)
     170            if (IsPaused || IsCompleted)
    171171                return;
    172172
    173             this.IsPaused = true;
    174 
    175             if (this.currentTask != null)
    176             {
    177                 await this.currentTask;
     173            IsPaused = true;
     174
     175            if (currentTask != null)
     176            {
     177                await currentTask;
    178178            }
    179179        }
     
    181181        public Task ResumeAsync()
    182182        {
    183             if (this.IsPaused || !this.IsAborted)
    184             {
    185                 this.IsPaused = false;
    186                 return this.InterpreteAsync();
    187             }
    188 
    189             return this.currentTask;
     183            if (IsPaused || !IsAborted)
     184            {
     185                IsPaused = false;
     186                return InterpreteAsync();
     187            }
     188
     189            return currentTask;
    190190        }
    191191
    192192        public void Step()
    193193        {
    194             if (this.CanStep)
    195             {
    196                 this.DoStep();
    197                 this.Finally();
     194            if (CanStep)
     195            {
     196                DoStep();
     197                Finally();
    198198            }
    199199        }
     
    203203            for (var i = 0; i < count; i++)
    204204            {
    205                 this.Step();
     205                Step();
    206206            }
    207207        }
     
    229229        public void PrintStacks()
    230230        {
    231             this.PrintStack("EXEC", this.ExecStack);
    232             this.PrintStack("CODE", this.CodeStack);
    233             this.PrintStack("NAME", this.NameStack);
    234             this.PrintStack("BOOLEAN", this.BooleanStack);
    235             this.PrintStack("FLOAT", this.FloatStack);
    236             this.PrintStack("INTEGER", this.IntegerStack);
     231            PrintStack("EXEC", ExecStack);
     232            PrintStack("CODE", CodeStack);
     233            PrintStack("NAME", NameStack);
     234            PrintStack("BOOLEAN", BooleanStack);
     235            PrintStack("FLOAT", FloatStack);
     236            PrintStack("INTEGER", IntegerStack);
    237237        }
    238238
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Simplifier/RandomSimplifier.cs

    r14397 r14398  
    1717            var clone = program.Clone() as ExecExpandExpression;
    1818
    19             for (var i = 0; i < this.Trys; i++)
     19            for (var i = 0; i < Trys; i++)
    2020            {
    2121                var index = rand.Next(0, clone.TotalCount - 1);
     22
    2223            }
    2324
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/PushGPStack.cs

    r14392 r14398  
    2020        public PushGPStack(int capacity = 0)
    2121        {
    22             this.data = new List<T>();
    23         }
    24 
    25         public T Top { get { return this.data[Count - 1]; } }
    26         public T TopOrDefault { get { return Count > 0 ? this.data[Count - 1] : default(T); } }
    27         public T Bottom { get { return this.data[0]; } }
    28         public T BottomOrDefault { get { return Count > 0 ? this.data[0] : default(T); } }
    29         public int Count { get { return this.data.Count; } }
    30         public int Capacity { get { return this.data.Capacity; } }
    31         public bool IsEmpty { get { return this.Count == 0; } }
     22            data = new List<T>();
     23        }
     24
     25        public T Top { get { return data[Count - 1]; } }
     26        public T TopOrDefault { get { return Count > 0 ? data[Count - 1] : default(T); } }
     27        public T Bottom { get { return data[0]; } }
     28        public T BottomOrDefault { get { return Count > 0 ? data[0] : default(T); } }
     29        public int Count { get { return data.Count; } }
     30        public int Capacity { get { return data.Capacity; } }
     31        public bool IsEmpty { get { return Count == 0; } }
    3232
    3333        public bool IsReadOnly { get { return false; } }
     
    3535        public void Add(T item)
    3636        {
    37             this.Push(item);
     37            Push(item);
    3838        }
    3939
    4040        public void Clear()
    4141        {
    42             this.data.Clear();
     42            data.Clear();
    4343        }
    4444
    4545        public bool Contains(T item)
    4646        {
    47             return this.data.Contains(item);
     47            return data.Contains(item);
    4848        }
    4949
    5050        public void CopyTo(T[] array, int arrayIndex)
    5151        {
    52             this.data.CopyTo(array, arrayIndex);
     52            data.CopyTo(array, arrayIndex);
    5353        }
    5454
    5555        public IEnumerator<T> GetEnumerator()
    5656        {
    57             return this.data.GetEnumerator();
     57            return data.GetEnumerator();
    5858        }
    5959
    6060        public T ElementAt(int index)
    6161        {
    62             return this.data[index];
     62            return data[index];
    6363        }
    6464
     
    6666        public T ReverseElementAt(int offset)
    6767        {
    68             return this.data[this.Count - 1 - offset];
     68            return data[Count - 1 - offset];
    6969        }
    7070
    7171        public void SetTop(T value)
    7272        {
    73             this.data[Count - 1] = value;
     73            data[Count - 1] = value;
    7474        }
    7575
    7676        public T this[int key]
    7777        {
    78             get { return this.data[key]; }
    79             set { this.data[key] = value; }
     78            get { return data[key]; }
     79            set { data[key] = value; }
    8080        }
    8181
    8282        public void Swap(int count)
    8383        {
    84             var top = this.Top;
    85             var bottomIndex = this.Count - count;
    86 
    87             for (var i = this.Count - 1; i > bottomIndex; i--)
    88             {
    89                 this.data[i] = this.data[i - 1];
    90             }
    91 
    92             this.data[bottomIndex] = top;
     84            var top = Top;
     85            var bottomIndex = Count - count;
     86
     87            for (var i = Count - 1; i > bottomIndex; i--)
     88            {
     89                data[i] = data[i - 1];
     90            }
     91
     92            data[bottomIndex] = top;
    9393        }
    9494
    9595        public void Yank(int index)
    9696        {
    97             var item = this.ElementAt(index);
    98             this.data.RemoveAt(index);
    99             this.data.Add(item);
     97            var item = ElementAt(index);
     98            data.RemoveAt(index);
     99            data.Add(item);
    100100        }
    101101
    102102        public T Pop()
    103103        {
    104             var value = this.data[Count - 1];
    105             this.data.RemoveAt(Count - 1);
     104            var value = data[Count - 1];
     105            data.RemoveAt(Count - 1);
    106106
    107107            return value;
     
    113113
    114114            var items = new T[count];
    115             this.data.CopyTo(startIndex, items, 0, count);
    116             this.Remove(count);
     115            data.CopyTo(startIndex, items, 0, count);
     116            Remove(count);
    117117
    118118            return items;
     
    121121        public void Push(T item)
    122122        {
    123             this.data.Add(item);
     123            data.Add(item);
    124124        }
    125125
     
    128128            for (var i = 0; i < items.Length; i++)
    129129            {
    130                 this.data.Add((T)items[i]);
     130                data.Add((T)items[i]);
    131131            }
    132132        }
     
    137137            var items = new T[count];
    138138
    139             this.data.CopyTo(startIndex, items, 0, count);
    140             this.Remove(count - 1);
    141 
    142             this.data[Count - 1] = templateFunc(items);
     139            data.CopyTo(startIndex, items, 0, count);
     140            Remove(count - 1);
     141
     142            data[Count - 1] = templateFunc(items);
    143143        }
    144144
     
    147147            for (var i = 0; i < items.Length; i++)
    148148            {
    149                 this.data.Add(items[i]);
     149                data.Add(items[i]);
    150150            }
    151151        }
     
    153153        public void Push(IEnumerable<T> items)
    154154        {
    155             this.data.AddRange(items);
     155            data.AddRange(items);
    156156        }
    157157
    158158        public void Insert(int index, T item)
    159159        {
    160             this.data.Insert(index, item);
     160            data.Insert(index, item);
    161161        }
    162162
    163163        public void Insert(int index, params T[] items)
    164164        {
    165             this.data.InsertRange(index, items);
     165            data.InsertRange(index, items);
    166166        }
    167167
    168168        public void Insert(int index, IEnumerable<T> items)
    169169        {
    170             this.data.InsertRange(index, items);
     170            data.InsertRange(index, items);
    171171        }
    172172
     
    174174        {
    175175            var index = Count - 1;
    176             if (this.Count > 0 && this.data[index].Equals(item))
    177             {
    178                 this.data.RemoveAt(index);
     176            if (Count > 0 && data[index].Equals(item))
     177            {
     178                data.RemoveAt(index);
    179179                return true;
    180180            }
     
    187187        public void RemoveTop()
    188188        {
    189             this.data.RemoveAt(this.Count - 1);
     189            data.RemoveAt(Count - 1);
    190190        }
    191191
     
    194194            for (var i = 0; i < count; i++)
    195195            {
    196                 this.data.RemoveAt(Count - 1);
     196                data.RemoveAt(Count - 1);
    197197            }
    198198        }
     
    200200        public void RemoveAt(int index)
    201201        {
    202             this.data.RemoveAt(index);
     202            data.RemoveAt(index);
    203203        }
    204204
    205205        public void RemoveAt(int index, int count)
    206206        {
    207             this.data.RemoveRange(index, count);
     207            data.RemoveRange(index, count);
    208208        }
    209209
    210210        public bool TryPop(out T item)
    211211        {
    212             if (this.Count > 0)
    213             {
    214                 item = this.Pop();
     212            if (Count > 0)
     213            {
     214                item = Pop();
    215215                return true;
    216216            }
     
    224224        IEnumerator IEnumerable.GetEnumerator()
    225225        {
    226             return (this.data as IEnumerable).GetEnumerator();
     226            return (data as IEnumerable).GetEnumerator();
    227227        }
    228228
    229229        public override string ToString()
    230230        {
    231             return string.Join(Delimiter, this.data);
     231            return string.Join(Delimiter, data);
    232232        }
    233233    }
Note: See TracChangeset for help on using the changeset viewer.