Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 21:36:03 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

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  
    151151
    152152    public override void Eval(IInternalPushInterpreter interpreter) {
    153       var chars = interpreter.StringStack.Pop().Reverse().ToArray();
     153      var chars = interpreter.StringStack.Pop().Reverse().ToList();
    154154      interpreter.CharStack.Push(chars);
    155155    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs

    r15017 r15189  
    4343
    4444    public object Clone() {
     45      return Clone(new Cloner());
     46    }
     47
     48    public virtual IDeepCloneable Clone(Cloner cloner) {
    4549      return this;
    4650    }
    4751
    48     public IDeepCloneable Clone(Cloner cloner) {
    49       return this;
    50     }
     52    void IPooledObject.Init() { }
    5153
    5254    void IPooledObject.Reset() { }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs

    r15032 r15189  
    2525
    2626    static ExpressionTable() {
    27       StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToArray();
    28       StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToArray();
     27      StatelessExpressionTypes = GetExpressionTypes(typeof(StatelessExpression)).ToList();
     28      StatefulExpressionTypes = GetExpressionTypes(typeof(StatefulExpression<>)).ToList();
    2929
    3030      StatelessExpressionTable = GetStatelessExpressionTable();
     
    3535        .Where(t => typeToNameTable.ContainsKey(t))
    3636        .Select(type => typeToNameTable[type])
    37         .ToArray();
     37        .ToList();
    3838
    3939      ExpressionCount = StatelessExpressionTable.Count + StatefulExpressionFactory.Count;
     
    5757        dictionary.Add(type, expression);
    5858
    59         // do not index hidden expressions like push expression in tables
    60         if (attribute.IsHidden) continue;
     59        //// do not index hidden expressions like push expression in tables
     60        //if (attribute.IsHidden) continue;
    6161
    6262        indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.Name);
     
    156156          .Where(entry => (entry.Key & ~allowedTypes) == 0x0)
    157157          .SelectMany(entry => entry.Value)
    158           .ToArray();
     158          .ToList();
    159159    }
    160160
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs

    r15032 r15189  
    22  using System.Collections.Generic;
    33  using System.Globalization;
    4   using System.Text;
    54  using Attributes;
    65  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    76  using HeuristicLab.Problems.ProgramSynthesis.Push.Constants;
     7
    88  using Interpreter;
    99  using Stack;
     
    2121
    2222    public override void Eval(IInternalPushInterpreter interpreter) {
    23       interpreter.PrintStack.Push(string.Empty);
     23      interpreter.PrintStack.NewLine();
    2424    }
    2525  }
     
    2828  public abstract class PrintExpression<T> : StatelessExpression {
    2929    protected PrintExpression() { }
     30
    3031    [StorableConstructor]
    3132    protected PrintExpression(bool deserializing) : base(deserializing) { }
    3233
    3334    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);
    4038    }
    4139
    4240    protected void EvalVector(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
    43       var sb = new StringBuilder();
    4441      var vector = vectorStack.Pop();
    4542
    46       sb.Append(PushEnvironment.VectorStartSymbol);
     43      interpreter.PrintStack.Push(PushEnvironment.VectorStartSymbol);
    4744
    4845      if (vector.Count > 0) {
    49         sb.Append(vector[0]);
     46        interpreter.PrintStack.Push(vector[0]);
    5047
    5148        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]);
    5451        }
    5552      }
    5653
    57       sb.Append(PushEnvironment.VectorEndSymbol);
    58 
    59       var value = sb.ToString();
    60       interpreter.PrintStack.Push(value);
     54      interpreter.PrintStack.Push(PushEnvironment.VectorEndSymbol);
    6155    }
    6256  }
     
    165159
    166160    public override void Eval(IInternalPushInterpreter interpreter) {
    167       Eval(interpreter, interpreter.IntegerStack);
     161      var value = interpreter.IntegerStack.Pop();
     162      interpreter.PrintStack.Push(value);
    168163    }
    169164  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs

    r15017 r15189  
    88  using Data.Pool;
    99  using Extensions;
     10
     11  using HeuristicLab.Common;
     12
    1013  using Interpreter;
    1114  using Persistence.Default.CompositeSerializers.Storable;
     
    4144    }
    4245
     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
    4358    public bool IsEmpty { get { return Count == 0; } }
    4459    public int Count { get { return expressions.Count; } }
     
    5166      return program;
    5267    }
     68
     69    void IPooledObject.Init() { }
    5370
    5471    void IPooledObject.Reset() {
     
    263280            yield return sub;
    264281        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        }
    265299      }
    266300    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs

    r15017 r15189  
    6969    }
    7070
     71    void IPooledObject.Init() { }
     72
    7173    public void Reset() {
    7274      State = default(T);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs

    r15032 r15189  
    453453        .Where(x => !string.IsNullOrWhiteSpace(x))
    454454        .Reverse()
    455         .ToArray();
    456 
    457       if (words.Length == 0) {
     455        .ToList();
     456
     457      if (words.Count == 0) {
    458458        interpreter.StringStack.Pop();
    459459      } else {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorButLastExpressions.cs

    r15032 r15189  
    2525      vectorStack.Top = vectorStack.Top
    2626        .Take(vectorStack.Top.Count - 1)
    27         .ToArray();
     27        .ToList();
    2828    }
    2929  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIterateExpressions.cs

    r15032 r15189  
    5656        }
    5757
    58         vectorStack.Top = vector.Take(last).ToArray();
     58        vectorStack.Top = vector.Take(last).ToList();
    5959      }
    6060    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs

    r15032 r15189  
    2323
    2424    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    25       var vector = vectorStack.Pop().Reverse().ToArray();
     25      var vector = vectorStack.Pop().Reverse().ToList();
    2626      literalStack.Push(vector);
    2727    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRemoveExpressions.cs

    r15032 r15189  
    2525    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
    2626      var literal = literalStack.Pop();
    27       vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToArray();
     27      vectorStack.Top = vectorStack.Top.Where(x => !x.Equals(literal)).ToList();
    2828    }
    2929  }
     
    9292  [PushExpression(
    9393    StackTypes.StringVector,
     94    "STRING[].REMOVE",
    9495    "Removes all occurrences of the top STRING in the top STRING[].",
    95     "STRING[].REMOVE",
    9696    StackTypes.String)]
    9797  public class StringVectorRemoveExpression : VectorRemoveExpression<string> {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRestExpressions.cs

    r15032 r15189  
    4242      }
    4343
    44       vectorStack.Top = vector.Skip(1).ToArray();
     44      vectorStack.Top = vector.Skip(1).ToList();
    4545    }
    4646  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorReverseExpressions.cs

    r15032 r15189  
    2525
    2626    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack) {
    27       vectorStack.Top = vectorStack.Top.Reverse().ToArray();
     27      vectorStack.Top = vectorStack.Top.Reverse().ToList();
    2828    }
    2929  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSubExpressions.cs

    r15032 r15189  
    5151      }
    5252
    53       vectorStack.Top = vector.Skip(first).Take(lenght).ToArray();
     53      vectorStack.Top = vector.Skip(first).Take(lenght).ToList();
    5454    }
    5555  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorTakeExpressions.cs

    r15032 r15189  
    5353      }
    5454
    55       vectorStack.Top = vector.Take(count).ToArray();
     55      vectorStack.Top = vector.Take(count).ToList();
    5656    }
    5757  }
Note: See TracChangeset for help on using the changeset viewer.