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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.