Changeset 15189 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions
- Timestamp:
- 07/10/17 21:36:03 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs
r15032 r15189 151 151 152 152 public override void Eval(IInternalPushInterpreter interpreter) { 153 var chars = interpreter.StringStack.Pop().Reverse().To Array();153 var chars = interpreter.StringStack.Pop().Reverse().ToList(); 154 154 interpreter.CharStack.Push(chars); 155 155 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs
r15017 r15189 43 43 44 44 public object Clone() { 45 return Clone(new Cloner()); 46 } 47 48 public virtual IDeepCloneable Clone(Cloner cloner) { 45 49 return this; 46 50 } 47 51 48 public IDeepCloneable Clone(Cloner cloner) { 49 return this; 50 } 52 void IPooledObject.Init() { } 51 53 52 54 void IPooledObject.Reset() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r15032 r15189 25 25 26 26 static ExpressionTable() { 27 StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).To Array();28 StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).To Array();27 StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToList(); 28 StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToList(); 29 29 30 30 StatelessExpressionTable = GetStatelessExpressionTable(); … … 35 35 .Where(t => typeToNameTable.ContainsKey(t)) 36 36 .Select(type => typeToNameTable[type]) 37 .To Array();37 .ToList(); 38 38 39 39 ExpressionCount = StatelessExpressionTable.Count + StatefulExpressionFactory.Count; … … 57 57 dictionary.Add(type, expression); 58 58 59 // do not index hidden expressions like push expression in tables60 if (attribute.IsHidden) continue;59 //// do not index hidden expressions like push expression in tables 60 //if (attribute.IsHidden) continue; 61 61 62 62 indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.Name); … … 156 156 .Where(entry => (entry.Key & ~allowedTypes) == 0x0) 157 157 .SelectMany(entry => entry.Value) 158 .To Array();158 .ToList(); 159 159 } 160 160 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs
r15032 r15189 2 2 using System.Collections.Generic; 3 3 using System.Globalization; 4 using System.Text;5 4 using Attributes; 6 5 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Constants; 7 8 8 using Interpreter; 9 9 using Stack; … … 21 21 22 22 public override void Eval(IInternalPushInterpreter interpreter) { 23 interpreter.PrintStack. Push(string.Empty);23 interpreter.PrintStack.NewLine(); 24 24 } 25 25 } … … 28 28 public abstract class PrintExpression<T> : StatelessExpression { 29 29 protected PrintExpression() { } 30 30 31 [StorableConstructor] 31 32 protected PrintExpression(bool deserializing) : base(deserializing) { } 32 33 33 34 protected void Eval(IInternalPushInterpreter interpreter, IPushStack<T> stack) { 34 var value = stack.Pop().ToString(); 35 36 if (interpreter.PrintStack.IsEmpty) 37 interpreter.PrintStack.Push(value); 38 else 39 interpreter.PrintStack.Top += value; 35 var value = stack.Pop(); 36 37 interpreter.PrintStack.Push(value); 40 38 } 41 39 42 40 protected void EvalVector(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) { 43 var sb = new StringBuilder();44 41 var vector = vectorStack.Pop(); 45 42 46 sb.Append(PushEnvironment.VectorStartSymbol);43 interpreter.PrintStack.Push(PushEnvironment.VectorStartSymbol); 47 44 48 45 if (vector.Count > 0) { 49 sb.Append(vector[0]);46 interpreter.PrintStack.Push(vector[0]); 50 47 51 48 for (var i = 1; i < vector.Count; i++) { 52 sb.Append(PushEnvironment.VectorSeparatorSymbol);53 sb.Append(vector[i]);49 interpreter.PrintStack.Push(PushEnvironment.VectorSeparatorSymbol); 50 interpreter.PrintStack.Push(vector[i]); 54 51 } 55 52 } 56 53 57 sb.Append(PushEnvironment.VectorEndSymbol); 58 59 var value = sb.ToString(); 60 interpreter.PrintStack.Push(value); 54 interpreter.PrintStack.Push(PushEnvironment.VectorEndSymbol); 61 55 } 62 56 } … … 165 159 166 160 public override void Eval(IInternalPushInterpreter interpreter) { 167 Eval(interpreter, interpreter.IntegerStack); 161 var value = interpreter.IntegerStack.Pop(); 162 interpreter.PrintStack.Push(value); 168 163 } 169 164 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs
r15017 r15189 8 8 using Data.Pool; 9 9 using Extensions; 10 11 using HeuristicLab.Common; 12 10 13 using Interpreter; 11 14 using Persistence.Default.CompositeSerializers.Storable; … … 41 44 } 42 45 46 public PushProgram(PushProgram origin, Cloner cloner) { 47 stringRepresentation = origin.stringRepresentation; 48 hashCode = origin.hashCode; 49 depth = origin.depth; 50 treeIndex = origin.treeIndex; 51 expressions = new List<Expression>(origin.expressions); 52 } 53 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new PushProgram(this, cloner); 56 } 57 43 58 public bool IsEmpty { get { return Count == 0; } } 44 59 public int Count { get { return expressions.Count; } } … … 51 66 return program; 52 67 } 68 69 void IPooledObject.Init() { } 53 70 54 71 void IPooledObject.Reset() { … … 263 280 yield return sub; 264 281 else yield return expr; 282 } 283 } 284 285 public IReadOnlyList<Expression> Flatten() { 286 var result = new List<Expression>(); 287 Flatten(result); 288 return result; 289 } 290 291 private void Flatten(List<Expression> result) { 292 result.AddRange(expressions); 293 294 for (var i = 0; i < expressions.Count; i++) { 295 var expr = expressions[i]; 296 if (expr.IsProgram) { 297 ((PushProgram)expr).Flatten(result); 298 } 265 299 } 266 300 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs
r15017 r15189 69 69 } 70 70 71 void IPooledObject.Init() { } 72 71 73 public void Reset() { 72 74 State = default(T); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
r15032 r15189 453 453 .Where(x => !string.IsNullOrWhiteSpace(x)) 454 454 .Reverse() 455 .To Array();456 457 if (words. Length== 0) {455 .ToList(); 456 457 if (words.Count == 0) { 458 458 interpreter.StringStack.Pop(); 459 459 } else { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorButLastExpressions.cs
r15032 r15189 25 25 vectorStack.Top = vectorStack.Top 26 26 .Take(vectorStack.Top.Count - 1) 27 .To Array();27 .ToList(); 28 28 } 29 29 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIterateExpressions.cs
r15032 r15189 56 56 } 57 57 58 vectorStack.Top = vector.Take(last).To Array();58 vectorStack.Top = vector.Take(last).ToList(); 59 59 } 60 60 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs
r15032 r15189 23 23 24 24 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) { 25 var vector = vectorStack.Pop().Reverse().To Array();25 var vector = vectorStack.Pop().Reverse().ToList(); 26 26 literalStack.Push(vector); 27 27 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRemoveExpressions.cs
r15032 r15189 25 25 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) { 26 26 var literal = literalStack.Pop(); 27 vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).To Array();27 vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToList(); 28 28 } 29 29 } … … 92 92 [PushExpression( 93 93 StackTypes.StringVector, 94 "STRING[].REMOVE", 94 95 "Removes all occurrences of the top STRING in the top STRING[].", 95 "STRING[].REMOVE",96 96 StackTypes.String)] 97 97 public class StringVectorRemoveExpression : VectorRemoveExpression<string> { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRestExpressions.cs
r15032 r15189 42 42 } 43 43 44 vectorStack.Top = vector.Skip(1).To Array();44 vectorStack.Top = vector.Skip(1).ToList(); 45 45 } 46 46 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorReverseExpressions.cs
r15032 r15189 25 25 26 26 protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack) { 27 vectorStack.Top = vectorStack.Top.Reverse().To Array();27 vectorStack.Top = vectorStack.Top.Reverse().ToList(); 28 28 } 29 29 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSubExpressions.cs
r15032 r15189 51 51 } 52 52 53 vectorStack.Top = vector.Skip(first).Take(lenght).To Array();53 vectorStack.Top = vector.Skip(first).Take(lenght).ToList(); 54 54 } 55 55 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs
r15032 r15189 53 53 } 54 54 55 vectorStack.Top = vector.Take(count).To Array();55 vectorStack.Top = vector.Take(count).ToList(); 56 56 } 57 57 }
Note: See TracChangeset
for help on using the changeset viewer.