Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs @ 14398

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

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

File size: 1.7 KB
Line 
1using HeuristicLab.Algorithms.PushGP.Interpreter;
2using HeuristicLab.Common;
3
4namespace HeuristicLab.Algorithms.PushGP.Expressions
5{
6    public abstract class Expression : DeepCloneable
7    {
8        private string stringRepresentation;
9        private int id;
10
11        public Expression()
12        { }
13
14        /// <summary>
15        /// Clone Constructor
16        /// </summary>
17        protected Expression(Expression origin, Cloner cloner)
18        {
19            stringRepresentation = origin.stringRepresentation;
20            id = origin.id;
21        }
22
23        public abstract void Eval(IInterpreter interpreter);
24
25        protected abstract int InitId();
26
27        protected abstract string InitStringRepresentation();
28
29        public string StringRepresentation
30        {
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            }
53        }
54
55        public override bool Equals(object obj)
56        {
57            return obj != null && (GetHashCode() == obj.GetHashCode() || GetType() == obj.GetType());
58        }
59
60        public override string ToString()
61        {
62            return StringRepresentation;
63        }
64
65        public override int GetHashCode()
66        {
67            return Id;
68        }
69    }
70}
Note: See TracBrowser for help on using the repository browser.