- Timestamp:
- 05/03/17 12:48:46 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push
- Files:
-
- 7 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(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs
r14909 r14914 3 3 using System.Collections.Generic; 4 4 5 public interface IPushStack<T> : ICollection<T>, IPushStack Base{5 public interface IPushStack<T> : ICollection<T>, IPushStack { 6 6 T Top { get; } 7 7 T TopOrDefault { get; } … … 9 9 T BottomOrDefault { get; } 10 10 T this[int key] { get; set; } 11 new int Count { get; } 11 12 void Push(T item); 12 13 void Push(T item1, T item2); 13 14 void Push(T item1, T item2, T item3); 14 15 void Push(T item1, T item2, T item3, T item4); 15 void Push(IReadOnlyList<T> items, int startIndex = 0);16 void Push(IReadOnlyList<T> items, int startIndex); 16 17 void Push(IReadOnlyList<T> items); 17 18 void Push(IEnumerable<T> items); 19 new void Clear(); 18 20 T Peek(); 19 21 T[] Peek(int count); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStackBase.cs
r14834 r14914 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack { 2 2 using System.Collections; 3 using System.Collections.Generic; 3 4 4 public interface IPushStack Base: IEnumerable {5 public interface IPushStack : IEnumerable { 5 6 bool IsEmpty { get; } 7 bool IsEnabled { get; } 8 int Count { get; } 6 9 7 bool IsEnabled { get; } 8 10 void Clear(); 9 11 void Swap(int count); 10 11 12 void Yank(int index); 12 13 void RemoveTop(); 13 14 14 void Remove(int count); 15 16 15 void RemoveAt(int index); 17 18 16 void RemoveAt(int index, int count); 17 IEnumerable<string> AsStrings(); 18 IEnumerable<object> AsObjects(); 19 19 } 20 20 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs
r14909 r14914 6 6 7 7 /// <summary> 8 /// While Push's stacks are generally treated as genuine stacks---that is, inclassions take their arguments from the8 /// While Push's Stacks are generally treated as genuine Stacks---that is, inclassions take their arguments from the 9 9 /// tops of 10 /// the stacks and push their results onto the tops of the stacks---a few inclassions (like YANK and SHOVE) do allow10 /// the Stacks and push their results onto the tops of the Stacks---a few inclassions (like YANK and SHOVE) do allow 11 11 /// direct access 12 /// to "deep" stack elements by means of integer indices. To this extent the stacks can be used as general, random12 /// to "deep" stack elements by means of integer indices. To this extent the Stacks can be used as general, random 13 13 /// access memory 14 14 /// classures. This is one of the features that ensures the Turing-completeness of Push (another being the arbitrary … … 279 279 return string.Join(Delimiter, data.Reverse()); 280 280 } 281 282 IEnumerable<string> IPushStack.AsStrings() { 283 return data.Select(x => x.ToString()); 284 } 285 286 IEnumerable<object> IPushStack.AsObjects() { 287 return data.OfType<object>(); 288 } 281 289 } 282 290 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs
r14897 r14914 228 228 }; 229 229 230 // align numbers right 230 231 var stackEntryType = type.GetStackEntryType(); 231 232 if (stackEntryType == typeof(double) || … … 270 271 271 272 foreach (var pair in debugControlDict) { 272 var stack = interpreter. GetStackEntriesByType<object>(pair.Key);273 var stack = interpreter.Stacks[pair.Key]; 273 274 var name = Enum.GetName(typeof(StackTypes), pair.Key); 274 275 275 pair.Value.Items.AddRange(stack. Reverse().ToArray());276 pair.Value.Items.AddRange(stack.AsObjects().Reverse().ToArray()); 276 277 ((GroupBox)pair.Value.Parent).Text = string.Format(GroupBoxTextStringFormat, name, pair.Value.Items.Count); 277 278 }
Note: See TracChangeset
for help on using the changeset viewer.