Changeset 14914 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Timestamp:
- 05/03/17 12:48:46 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs
r14834 r14914 24 24 } 25 25 26 public static IPushStackBase GetStackBaseByType(this IPushInterpreter interpreter, StackTypes stackType) {27 return StackProperties.ContainsKey(stackType)28 ? (IPushStackBase)StackProperties[stackType].GetValue(interpreter)29 : null;30 }31 32 26 public static Type GetStackEntryType(this StackTypes stackType) { 33 27 return StackProperties.ContainsKey(stackType) … … 41 35 foreach (StackTypes type in Enum.GetValues(stackTypesType)) { 42 36 var stackName = Enum.GetName(stackTypesType, type); 43 var stack = GetStackBaseByType(interpreter, type);37 var stack = interpreter.Stacks[type]; 44 38 45 39 if (stack.IsEmpty || !stack.IsEnabled) return; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs
r14897 r14914 26 26 IPushStack<string> PrintStack { get; } 27 27 IDictionary<string, Expression> CustomExpressions { get; } 28 IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; } 28 29 IReadOnlyPushConfiguration Configuration { get; } 29 30 void Clear(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14908 r14914 5 5 using System.Threading; 6 6 using System.Threading.Tasks; 7 using Attributes;8 7 using Configuration; 9 8 using Core; 10 9 using Expressions; 10 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 12 11 13 using Parser; 12 14 using Random; … … 26 28 Configuration = config ?? new PushConfiguration(); 27 29 28 // setting the capacity of the stacks to max points ensures that there will be enough memory at runtime30 // setting the capacity of the Stacks to max points ensures that there will be enough memory at runtime 29 31 ExecStack = new PushStack<Expression>(Configuration.MaxPointsInProgram); 30 32 … … 77 79 }; 78 80 81 Stacks = new Dictionary<StackTypes, IPushStack> { 82 { StackTypes.Exec, ExecStack }, 83 { StackTypes.Code, CodeStack }, 84 { StackTypes.Integer, IntegerStack }, 85 { StackTypes.Float, FloatStack }, 86 { StackTypes.Boolean, BooleanStack }, 87 { StackTypes.Char, CharStack }, 88 { StackTypes.String, StringStack }, 89 { StackTypes.Name, NameStack }, 90 { StackTypes.IntegerVector, IntegerVectorStack }, 91 { StackTypes.FloatVector, FloatVectorStack }, 92 { StackTypes.BooleanVector, BooleanVectorStack }, 93 { StackTypes.StringVector, StringVectorStack }, 94 { StackTypes.Print, PrintStack }, 95 }; 96 79 97 CustomExpressions = new Dictionary<string, Expression>(); 80 98 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); … … 84 102 : this(config, new FastRandom(seed)) { 85 103 } 104 105 public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; } 86 106 87 107 public IRandom Random { get; set; } … … 123 143 124 144 public IReadOnlyPushConfiguration Configuration { get; protected set; } 125 126 145 [PushStack(StackTypes.Code)] 127 146 public IPushStack<Expression> CodeStack { get; private set; } 128 129 147 [PushStack(StackTypes.Exec)] 130 148 public IPushStack<Expression> ExecStack { get; private set; } 131 132 149 [PushStack(StackTypes.Name)] 133 150 public IPushStack<string> NameStack { get; private set; } 134 135 151 [PushStack(StackTypes.Boolean)] 136 152 public IPushStack<bool> BooleanStack { get; private set; } 137 138 153 [PushStack(StackTypes.Integer)] 139 154 public IPushStack<long> IntegerStack { get; private set; } 140 141 155 [PushStack(StackTypes.Float)] 142 156 public IPushStack<double> FloatStack { get; private set; } 143 144 157 [PushStack(StackTypes.Char)] 145 158 public IPushStack<char> CharStack { get; private set; } 146 147 159 [PushStack(StackTypes.String)] 148 160 public IPushStack<string> StringStack { get; private set; } 149 150 161 [PushStack(StackTypes.IntegerVector)] 151 162 public IPushStack<List<long>> IntegerVectorStack { get; private set; } 152 153 163 [PushStack(StackTypes.FloatVector)] 154 164 public IPushStack<List<double>> FloatVectorStack { get; private set; } 155 156 165 [PushStack(StackTypes.BooleanVector)] 157 166 public IPushStack<List<bool>> BooleanVectorStack { get; private set; } 158 159 167 [PushStack(StackTypes.StringVector)] 160 168 public IPushStack<List<string>> StringVectorStack { get; private set; } 161 162 169 [PushStack(StackTypes.Print)] 163 170 public IPushStack<string> PrintStack { get; private set; } … … 275 282 276 283 /// <summary> 277 /// Clears stacks and custom expressions284 /// Clears Stacks and custom expressions 278 285 /// </summary> 279 286 public void Clear() { 280 ExecStack.Clear(); 281 CodeStack.Clear(); 282 NameStack.Clear(); 283 BooleanStack.Clear(); 284 IntegerStack.Clear(); 285 FloatStack.Clear(); 287 foreach (var stack in Stacks) 288 stack.Value.Clear(); 286 289 287 290 CustomExpressions.Clear();
Note: See TracChangeset
for help on using the changeset viewer.