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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r15032 r15189  
    22  using System;
    33  using System.Collections.Generic;
     4  using System.Linq;
    45  using System.Runtime.CompilerServices;
    56  using System.Threading;
     
    3536      BooleanVectorStack = new PushStack<IReadOnlyList<bool>>();
    3637      StringVectorStack = new PushStack<IReadOnlyList<string>>();
    37       PrintStack = new PushStack<string>();
     38      PrintStack = new PrintStack();
    3839
    3940      Stacks = new Dictionary<StackTypes, IPushStack> {
     
    5354      };
    5455
     56      supportedStackTypes = Stacks.Keys.ToArray();
     57
    5558      CustomExpressions = new Dictionary<string, Expression>();
    5659      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
     
    6366    }
    6467
     68    private readonly StackTypes[] supportedStackTypes;
    6569    public IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; private set; }
    6670
     
    128132    public IPushStack<IReadOnlyList<string>> StringVectorStack { get; private set; }
    129133    [PushStack(StackTypes.Print)]
    130     public IPushStack<string> PrintStack { get; private set; }
     134    public IPrintStack PrintStack { get; private set; }
    131135
    132136    public IDictionary<string, Expression> CustomExpressions { get; private set; }
    133137
    134138    public bool IsNameQuoteFlagSet { get; set; }
     139
     140    private readonly List<Expression> inputExpressions = new List<Expression>();
     141    IReadOnlyList<Expression> IInternalPushInterpreter.InputExpressions { get { return inputExpressions; } }
     142
     143    public void SetInput(
     144      IReadOnlyList<long> integers = null,
     145      IReadOnlyList<double> floats = null,
     146      IReadOnlyList<bool> booleans = null,
     147      IReadOnlyList<char> chars = null,
     148      IReadOnlyList<string> strings = null,
     149      IReadOnlyList<IReadOnlyList<long>> integerVectors = null,
     150      IReadOnlyList<IReadOnlyList<double>> floatVectors = null,
     151      IReadOnlyList<IReadOnlyList<string>> stringVectors = null) {
     152
     153      // Integer
     154      if (integers != null && integers.Count > 0) {
     155        var integerPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerPushExpression>();
     156
     157        for (var i = 0; i < integers.Count; i++) {
     158          var expression = IntegerPushExpression.Create(integerPushExpressionPool, integers[i]);
     159          inputExpressions.Add(expression);
     160        }
     161      }
     162
     163      // Float
     164      if (floats != null && floats.Count > 0) {
     165        var floatPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatPushExpression>();
     166
     167        for (var i = 0; i < floats.Count; i++) {
     168          var expression = FloatPushExpression.Create(floatPushExpressionPool, floats[i]);
     169          inputExpressions.Add(expression);
     170        }
     171      }
     172
     173      // Booleans
     174      if (booleans != null && booleans.Count > 0) {
     175        var booleanPushExpressionPool = PoolContainer.GetStatefulExpressionPool<BooleanPushExpression>();
     176
     177        for (var i = 0; i < booleans.Count; i++) {
     178          var expression = BooleanPushExpression.Create(booleanPushExpressionPool, booleans[i]);
     179          inputExpressions.Add(expression);
     180        }
     181      }
     182
     183      // Char
     184      if (chars != null && chars.Count > 0) {
     185        var charPushExpressionPool = PoolContainer.GetStatefulExpressionPool<CharPushExpression>();
     186
     187        for (var i = 0; i < chars.Count; i++) {
     188          var expression = CharPushExpression.Create(charPushExpressionPool, chars[i]);
     189          inputExpressions.Add(expression);
     190        }
     191      }
     192
     193      // String
     194      if (strings != null && strings.Count > 0) {
     195        var stringPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringPushExpression>();
     196
     197        for (var i = 0; i < strings.Count; i++) {
     198          var expression = StringPushExpression.Create(stringPushExpressionPool, strings[i]);
     199          inputExpressions.Add(expression);
     200        }
     201      }
     202
     203      // IntegerVector
     204      if (integerVectors != null && integerVectors.Count > 0) {
     205        var integerVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<IntegerVectorPushExpression>();
     206
     207        for (var i = 0; i < integerVectors.Count; i++) {
     208          var expression = IntegerVectorPushExpression.Create(integerVectorPushExpressionPool, integerVectors[i]);
     209          inputExpressions.Add(expression);
     210        }
     211      }
     212
     213      // FloatVector
     214      if (floatVectors != null && floatVectors.Count > 0) {
     215        var floatVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<FloatVectorPushExpression>();
     216
     217        for (var i = 0; i < floatVectors.Count; i++) {
     218          var expression = FloatVectorPushExpression.Create(floatVectorPushExpressionPool, floatVectors[i]);
     219          inputExpressions.Add(expression);
     220        }
     221      }
     222
     223      // StringVector
     224      if (stringVectors != null && stringVectors.Count > 0) {
     225        var stringVectorPushExpressionPool = PoolContainer.GetStatefulExpressionPool<StringVectorPushExpression>();
     226
     227        for (var i = 0; i < stringVectors.Count; i++) {
     228          var expression = StringVectorPushExpression.Create(stringVectorPushExpressionPool, stringVectors[i]);
     229          inputExpressions.Add(expression);
     230        }
     231      }
     232    }
     233
    135234
    136235    public Task RunAsync(string code, CancellationToken token = default(CancellationToken)) {
     
    240339      currentProgram = null;
    241340
     341      inputExpressions.Clear();
    242342      Clear();
    243343      ConfigureStacks();
     
    245345
    246346    private void ConfigureStacks() {
    247       foreach (var pair in this.Stacks) {
    248         pair.Value.IsEnabled = Configuration.IsStackEnabled(pair.Key);
     347      for (var i = 0u; i < supportedStackTypes.Length; i++) {
     348        var key = supportedStackTypes[i];
     349        Stacks[key].IsEnabled = Configuration.IsStackEnabled(key);
    249350      }
    250351
     
    257358    /// </summary>
    258359    public void Clear() {
    259       foreach (var stack in Stacks)
    260         stack.Value.Clear();
     360      for (var i = 0u; i < supportedStackTypes.Length; i++) {
     361        var key = supportedStackTypes[i];
     362        Stacks[key].Clear();
     363      }
    261364
    262365      CustomExpressions.Clear();
Note: See TracChangeset for help on using the changeset viewer.