Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (8 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs

    r14914 r15017  
    44
    55  public interface IPushStack<T> : ICollection<T>, IPushStack {
    6     T Top { get; }
     6    T Top { get; set; }
    77    T TopOrDefault { get; }
    88    T Bottom { get; }
     
    2323    void Insert(int index, T item);
    2424    T ReverseElementAt(int offset);
    25     void SetTop(T value);
    2625    T Pop();
    2726    T[] Pop(int count);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/InterpreterStackStringifier.cs

    r14952 r15017  
    33
    44namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack {
     5  using System.Globalization;
     6
    57  using HeuristicLab.Problems.ProgramSynthesis.Push.Constants;
     8  using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
    69  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
    710
    8   public class InterpreterStackStringifier {
     11  public static class InterpreterStackStringifier {
    912
    10     public static IEnumerable<string> StringifyStack(IPushInterpreter interpreter, StackTypes type) {
     13    public static IEnumerable<string> StringifyStack(this IPushInterpreter interpreter, StackTypes type) {
    1114      switch (type) {
    1215        case StackTypes.Boolean: return StringifyLiteralStack(interpreter.BooleanStack);
    1316        case StackTypes.Integer: return StringifyLiteralStack(interpreter.IntegerStack);
    14         case StackTypes.Float: return StringifyLiteralStack(interpreter.FloatStack);
    15         case StackTypes.Char: return StringifyLiteralStack(interpreter.CharStack);
    16         case StackTypes.String: return StringifyLiteralStack(interpreter.StringStack, "\"", "\"");
     17        case StackTypes.Float: return StringifyFloatStack(interpreter.FloatStack, interpreter.Configuration.FloatStringFormat);
     18        case StackTypes.Char: return StringifyCharStack(interpreter.CharStack);
     19        case StackTypes.String: return StringifyLiteralStack(interpreter.StringStack, PushEnvironment.StringSymbolStr, PushEnvironment.StringSymbolStr);
    1720        case StackTypes.Name: return StringifyLiteralStack(interpreter.NameStack);
    1821        case StackTypes.Code: return StringifyLiteralStack(interpreter.CodeStack);
    1922        case StackTypes.Exec: return StringifyLiteralStack(interpreter.ExecStack);
    20         case StackTypes.Print: return StringifyLiteralStack(interpreter.PrintStack);
     23        case StackTypes.Print: return StringifyLiteralStack(interpreter.PrintStack, PushEnvironment.StringSymbolStr, PushEnvironment.StringSymbolStr, false);
    2124
    2225        case StackTypes.BooleanVector: return StringifyVectorStack(interpreter.BooleanVectorStack);
    2326        case StackTypes.IntegerVector: return StringifyVectorStack(interpreter.IntegerVectorStack);
    24         case StackTypes.FloatVector: return StringifyVectorStack(interpreter.FloatVectorStack);
    25         case StackTypes.StringVector: return StringifyVectorStack(interpreter.StringVectorStack, "\"", "\"");
     27        case StackTypes.FloatVector: return StringifyFloatVectorStack(interpreter.FloatVectorStack, interpreter.Configuration.FloatStringFormat);
     28        case StackTypes.StringVector: return StringifyVectorStack(interpreter.StringVectorStack, PushEnvironment.StringSymbolStr, PushEnvironment.StringSymbolStr);
    2629
    2730        default: return Enumerable.Empty<string>();
     
    2932    }
    3033
    31     private static IEnumerable<string> StringifyLiteralStack<T>(IPushStack<T> stack, string prefix = "", string postfix = "") {
    32       return stack.Reverse().Select(x => prefix + x.ToString().Replace(PushEnvironment.NewLine, "\\n") + postfix);
     34    private static IEnumerable<string> StringifyCharStack(IPushStack<char> stack) {
     35      var result = stack.AsEnumerable();
     36
     37      return result.Select(x => PushEnvironment.CharSymbol + x.Printify() + PushEnvironment.CharSymbol);
    3338    }
    3439
    35     private static IEnumerable<string> StringifyVectorStack<T>(IPushStack<List<T>> stack, string prefix = "", string postfix = "") {
     40    private static IEnumerable<string> StringifyFloatStack(IPushStack<double> stack, string format) {
     41      var result = stack.AsEnumerable();
     42
     43      return result.Select(x => x.ToString(format, CultureInfo.InvariantCulture));
     44    }
     45
     46    private static IEnumerable<string> StringifyLiteralStack<T>(IPushStack<T> stack, string prefix = "", string postfix = "", bool reverse = true) {
     47      var result = stack.AsEnumerable();
     48
     49      if (reverse)
     50        result = result.Reverse();
     51
     52      return result.Select(x => prefix + x.ToString() + postfix);
     53    }
     54
     55    private static IEnumerable<string> StringifyFloatVectorStack(IPushStack<IReadOnlyList<double>> stack, string format) {
     56      var separator = PushEnvironment.VectorSeparatorSymbol.ToString();
     57      return stack
     58        .Reverse()
     59        .Select(x => PushEnvironment.VectorStartSymbol + string.Join(separator, x.Select(_ => _.ToString(format, CultureInfo.InvariantCulture))) + PushEnvironment.VectorEndSymbol);
     60    }
     61
     62    private static IEnumerable<string> StringifyVectorStack<T>(IPushStack<IReadOnlyList<T>> stack, string prefix = "", string postfix = "") {
    3663      var separator = PushEnvironment.VectorSeparatorSymbol.ToString();
    3764      return stack
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs

    r14914 r15017  
    4343        return data[Count - 1];
    4444      }
     45
     46      set
     47      {
     48        data[Count - 1] = value;
     49      }
    4550    }
    4651
     
    119124    public T ReverseElementAt(int offset) {
    120125      return data[offset];
    121     }
    122 
    123     public void SetTop(T value) {
    124       data[Count - 1] = value;
    125126    }
    126127
     
    276277
    277278    public override string ToString() {
    278       var data = this.data as IEnumerable<T>;
    279       return string.Join(Delimiter, data.Reverse());
     279      return string.Join(Delimiter, data.Select(x => x.ToString()).Reverse());
    280280    }
    281281
Note: See TracChangeset for help on using the changeset viewer.