Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/17 12:48:46 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added Dictionary of stacks to interperter, clear all stacks

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  
    2424    }
    2525
    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 
    3226    public static Type GetStackEntryType(this StackTypes stackType) {
    3327      return StackProperties.ContainsKey(stackType)
     
    4135      foreach (StackTypes type in Enum.GetValues(stackTypesType)) {
    4236        var stackName = Enum.GetName(stackTypesType, type);
    43         var stack = GetStackBaseByType(interpreter, type);
     37        var stack = interpreter.Stacks[type];
    4438
    4539        if (stack.IsEmpty || !stack.IsEnabled) return;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs

    r14897 r14914  
    2626    IPushStack<string> PrintStack { get; }
    2727    IDictionary<string, Expression> CustomExpressions { get; }
     28    IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; }
    2829    IReadOnlyPushConfiguration Configuration { get; }
    2930    void Clear();
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r14908 r14914  
    55  using System.Threading;
    66  using System.Threading.Tasks;
    7   using Attributes;
    87  using Configuration;
    98  using Core;
    109  using Expressions;
     10
     11  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
     12
    1113  using Parser;
    1214  using Random;
     
    2628      Configuration = config ?? new PushConfiguration();
    2729
    28       // setting the capacity of the stacks to max points ensures that there will be enough memory at runtime
     30      // setting the capacity of the Stacks to max points ensures that there will be enough memory at runtime
    2931      ExecStack = new PushStack<Expression>(Configuration.MaxPointsInProgram);
    3032
     
    7779      };
    7880
     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
    7997      CustomExpressions = new Dictionary<string, Expression>();
    8098      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
     
    84102      : this(config, new FastRandom(seed)) {
    85103    }
     104
     105    public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; }
    86106
    87107    public IRandom Random { get; set; }
     
    123143
    124144    public IReadOnlyPushConfiguration Configuration { get; protected set; }
    125 
    126145    [PushStack(StackTypes.Code)]
    127146    public IPushStack<Expression> CodeStack { get; private set; }
    128 
    129147    [PushStack(StackTypes.Exec)]
    130148    public IPushStack<Expression> ExecStack { get; private set; }
    131 
    132149    [PushStack(StackTypes.Name)]
    133150    public IPushStack<string> NameStack { get; private set; }
    134 
    135151    [PushStack(StackTypes.Boolean)]
    136152    public IPushStack<bool> BooleanStack { get; private set; }
    137 
    138153    [PushStack(StackTypes.Integer)]
    139154    public IPushStack<long> IntegerStack { get; private set; }
    140 
    141155    [PushStack(StackTypes.Float)]
    142156    public IPushStack<double> FloatStack { get; private set; }
    143 
    144157    [PushStack(StackTypes.Char)]
    145158    public IPushStack<char> CharStack { get; private set; }
    146 
    147159    [PushStack(StackTypes.String)]
    148160    public IPushStack<string> StringStack { get; private set; }
    149 
    150161    [PushStack(StackTypes.IntegerVector)]
    151162    public IPushStack<List<long>> IntegerVectorStack { get; private set; }
    152 
    153163    [PushStack(StackTypes.FloatVector)]
    154164    public IPushStack<List<double>> FloatVectorStack { get; private set; }
    155 
    156165    [PushStack(StackTypes.BooleanVector)]
    157166    public IPushStack<List<bool>> BooleanVectorStack { get; private set; }
    158 
    159167    [PushStack(StackTypes.StringVector)]
    160168    public IPushStack<List<string>> StringVectorStack { get; private set; }
    161 
    162169    [PushStack(StackTypes.Print)]
    163170    public IPushStack<string> PrintStack { get; private set; }
     
    275282
    276283    /// <summary>
    277     /// Clears stacks and custom expressions
     284    /// Clears Stacks and custom expressions
    278285    /// </summary>
    279286    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();
    286289
    287290      CustomExpressions.Clear();
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStack.cs

    r14909 r14914  
    33  using System.Collections.Generic;
    44
    5   public interface IPushStack<T> : ICollection<T>, IPushStackBase {
     5  public interface IPushStack<T> : ICollection<T>, IPushStack {
    66    T Top { get; }
    77    T TopOrDefault { get; }
     
    99    T BottomOrDefault { get; }
    1010    T this[int key] { get; set; }
     11    new int Count { get; }
    1112    void Push(T item);
    1213    void Push(T item1, T item2);
    1314    void Push(T item1, T item2, T item3);
    1415    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);
    1617    void Push(IReadOnlyList<T> items);
    1718    void Push(IEnumerable<T> items);
     19    new void Clear();
    1820    T Peek();
    1921    T[] Peek(int count);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPushStackBase.cs

    r14834 r14914  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack {
    22  using System.Collections;
     3  using System.Collections.Generic;
    34
    4   public interface IPushStackBase : IEnumerable {
     5  public interface IPushStack : IEnumerable {
    56    bool IsEmpty { get; }
     7    bool IsEnabled { get; }
     8    int Count { get; }
    69
    7     bool IsEnabled { get; }
    8 
     10    void Clear();
    911    void Swap(int count);
    10 
    1112    void Yank(int index);
    1213    void RemoveTop();
    13 
    1414    void Remove(int count);
    15 
    1615    void RemoveAt(int index);
    17 
    1816    void RemoveAt(int index, int count);
     17    IEnumerable<string> AsStrings();
     18    IEnumerable<object> AsObjects();
    1919  }
    2020}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs

    r14909 r14914  
    66
    77  /// <summary>
    8   ///     While Push's stacks are generally treated as genuine stacks---that is, inclassions take their arguments from the
     8  ///     While Push's Stacks are generally treated as genuine Stacks---that is, inclassions take their arguments from the
    99  ///     tops of
    10   ///     the stacks and push their results onto the tops of the stacks---a few inclassions (like YANK and SHOVE) do allow
     10  ///     the Stacks and push their results onto the tops of the Stacks---a few inclassions (like YANK and SHOVE) do allow
    1111  ///     direct access
    12   ///     to "deep" stack elements by means of integer indices. To this extent the stacks can be used as general, random
     12  ///     to "deep" stack elements by means of integer indices. To this extent the Stacks can be used as general, random
    1313  ///     access memory
    1414  ///     classures. This is one of the features that ensures the Turing-completeness of Push (another being the arbitrary
     
    279279      return string.Join(Delimiter, data.Reverse());
    280280    }
     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    }
    281289  }
    282290}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushDebuggerView.cs

    r14897 r14914  
    228228      };
    229229
     230      // align numbers right
    230231      var stackEntryType = type.GetStackEntryType();
    231232      if (stackEntryType == typeof(double) ||
     
    270271
    271272      foreach (var pair in debugControlDict) {
    272         var stack = interpreter.GetStackEntriesByType<object>(pair.Key);
     273        var stack = interpreter.Stacks[pair.Key];
    273274        var name = Enum.GetName(typeof(StackTypes), pair.Key);
    274275
    275         pair.Value.Items.AddRange(stack.Reverse().ToArray());
     276        pair.Value.Items.AddRange(stack.AsObjects().Reverse().ToArray());
    276277        ((GroupBox)pair.Value.Parent).Text = string.Format(GroupBoxTextStringFormat, name, pair.Value.Items.Count);
    277278      }
Note: See TracChangeset for help on using the changeset viewer.