Changeset 15189 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
- Timestamp:
- 07/10/17 21:36:03 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r15032 r15189 2 2 using System; 3 3 using System.Collections.Generic; 4 using System.Linq; 4 5 using System.Runtime.CompilerServices; 5 6 using System.Threading; … … 35 36 BooleanVectorStack = new PushStack<IReadOnlyList<bool>>(); 36 37 StringVectorStack = new PushStack<IReadOnlyList<string>>(); 37 PrintStack = new P ushStack<string>();38 PrintStack = new PrintStack(); 38 39 39 40 Stacks = new Dictionary<StackTypes, IPushStack> { … … 53 54 }; 54 55 56 supportedStackTypes = Stacks.Keys.ToArray(); 57 55 58 CustomExpressions = new Dictionary<string, Expression>(); 56 59 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); … … 63 66 } 64 67 68 private readonly StackTypes[] supportedStackTypes; 65 69 public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; } 66 70 … … 128 132 public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; } 129 133 [PushStack(StackTypes.Print)] 130 public IP ushStack<string>PrintStack { get; private set; }134 public IPrintStack PrintStack { get; private set; } 131 135 132 136 public IDictionary<string, Expression> CustomExpressions { get; private set; } 133 137 134 138 public bool IsNameQuoteFlagSet { get; set; } 139 140 private readonly List<Expression> inputExpressions = new List<Expression>(); 141 IReadOnlyList<Expression> IInternalPushInterpreter.InputExpressions { get { return inputExpressions; } } 142 143 public void SetInput( 144 IReadOnlyList<long> integers = null, 145 IReadOnlyList<double> floats = null, 146 IReadOnlyList<bool> booleans = null, 147 IReadOnlyList<char> chars = null, 148 IReadOnlyList<string> strings = null, 149 IReadOnlyList<IReadOnlyList<long>> integerVectors = null, 150 IReadOnlyList<IReadOnlyList<double>> floatVectors = null, 151 IReadOnlyList<IReadOnlyList<string>> stringVectors = null) { 152 153 // Integer 154 if (integers != null && integers.Count > 0) { 155 var integerPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerPushExpression>(); 156 157 for (var i = 0; i < integers.Count; i++) { 158 var expression = IntegerPushExpression.Create(integerPushExpressionPool, integers[i]); 159 inputExpressions.Add(expression); 160 } 161 } 162 163 // Float 164 if (floats != null && floats.Count > 0) { 165 var floatPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatPushExpression>(); 166 167 for (var i = 0; i < floats.Count; i++) { 168 var expression = FloatPushExpression.Create(floatPushExpressionPool, floats[i]); 169 inputExpressions.Add(expression); 170 } 171 } 172 173 // Booleans 174 if (booleans != null && booleans.Count > 0) { 175 var booleanPushExpressionPool = PoolContainer.GetStatefulExpressionPool<BooleanPushExpression>(); 176 177 for (var i = 0; i < booleans.Count; i++) { 178 var expression = BooleanPushExpression.Create(booleanPushExpressionPool, booleans[i]); 179 inputExpressions.Add(expression); 180 } 181 } 182 183 // Char 184 if (chars != null && chars.Count > 0) { 185 var charPushExpressionPool = PoolContainer.GetStatefulExpressionPool<CharPushExpression>(); 186 187 for (var i = 0; i < chars.Count; i++) { 188 var expression = CharPushExpression.Create(charPushExpressionPool, chars[i]); 189 inputExpressions.Add(expression); 190 } 191 } 192 193 // String 194 if (strings != null && strings.Count > 0) { 195 var stringPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringPushExpression>(); 196 197 for (var i = 0; i < strings.Count; i++) { 198 var expression = StringPushExpression.Create(stringPushExpressionPool, strings[i]); 199 inputExpressions.Add(expression); 200 } 201 } 202 203 // IntegerVector 204 if (integerVectors != null && integerVectors.Count > 0) { 205 var integerVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerVectorPushExpression>(); 206 207 for (var i = 0; i < integerVectors.Count; i++) { 208 var expression = IntegerVectorPushExpression.Create(integerVectorPushExpressionPool, integerVectors[i]); 209 inputExpressions.Add(expression); 210 } 211 } 212 213 // FloatVector 214 if (floatVectors != null && floatVectors.Count > 0) { 215 var floatVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatVectorPushExpression>(); 216 217 for (var i = 0; i < floatVectors.Count; i++) { 218 var expression = FloatVectorPushExpression.Create(floatVectorPushExpressionPool, floatVectors[i]); 219 inputExpressions.Add(expression); 220 } 221 } 222 223 // StringVector 224 if (stringVectors != null && stringVectors.Count > 0) { 225 var stringVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringVectorPushExpression>(); 226 227 for (var i = 0; i < stringVectors.Count; i++) { 228 var expression = StringVectorPushExpression.Create(stringVectorPushExpressionPool, stringVectors[i]); 229 inputExpressions.Add(expression); 230 } 231 } 232 } 233 135 234 136 235 public Task RunAsync(string code, CancellationToken token = default(CancellationToken)) { … … 240 339 currentProgram = null; 241 340 341 inputExpressions.Clear(); 242 342 Clear(); 243 343 ConfigureStacks(); … … 245 345 246 346 private void ConfigureStacks() { 247 foreach (var pair in this.Stacks) { 248 pair.Value.IsEnabled = Configuration.IsStackEnabled(pair.Key); 347 for (var i = 0u; i < supportedStackTypes.Length; i++) { 348 var key = supportedStackTypes[i]; 349 Stacks[key].IsEnabled = Configuration.IsStackEnabled(key); 249 350 } 250 351 … … 257 358 /// </summary> 258 359 public void Clear() { 259 foreach (var stack in Stacks) 260 stack.Value.Clear(); 360 for (var i = 0u; i < supportedStackTypes.Length; i++) { 361 var key = supportedStackTypes[i]; 362 Stacks[key].Clear(); 363 } 261 364 262 365 CustomExpressions.Clear();
Note: See TracChangeset
for help on using the changeset viewer.