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/Interpreter
Files:
5 edited

Legend:

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

    r15017 r15189  
    2525
    2626    public static Type GetStackEntryType(this StackTypes stackType) {
     27      if (StackProperties.ContainsKey(stackType) &&
     28          StackProperties[stackType].PropertyType.IsGenericType) {
     29        var genericTypeDef = StackProperties[stackType].PropertyType.GetGenericTypeDefinition();
     30        if (genericTypeDef == typeof(IPushStack<>))
     31          return genericTypeDef.GetGenericArguments()[0];
     32      }
     33
    2734      return StackProperties.ContainsKey(stackType)
    28         ? StackProperties[stackType].PropertyType.GetGenericArguments().Single()
     35        ? StackProperties[stackType]
     36            .PropertyType
     37            .GetInterfaces()
     38            .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPushStack<>))
     39            .GetGenericArguments()
     40            .First()
    2941        : null;
    3042    }
    3143
    3244    public static void PrintStacks(this IPushInterpreter interpreter) {
    33       var stackTypesType = typeof(StackTypes);
    34 
    35       foreach (StackTypes type in Enum.GetValues(stackTypesType)) {
    36         if (!interpreter.Stacks.ContainsKey(type)) continue;
    37 
    38         var stackName = Enum.GetName(stackTypesType, type);
    39         var stack = interpreter.Stacks[type];
     45      foreach (var pair in interpreter.Stacks) {
     46        var stackName = pair.Key.ToString();
     47        var stack = interpreter.Stacks[pair.Key];
    4048
    4149        if (stack.IsEmpty || !stack.IsEnabled) continue;
    4250
    43         var stackString = string.Join(" ", interpreter.StringifyStack(type).Reverse());
     51        var stackString = string.Join(" ", interpreter.StringifyStack(pair.Key).Reverse());
    4452        Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stackString);
    4553      }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IInternalPushInterpreter.cs

    r14834 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter {
     2  using System.Collections.Generic;
     3
     4  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     5
    26  public interface IInternalPushInterpreter : IPushInterpreter {
    37    InterpreterPoolContainer PoolContainer { get; }
    48    bool IsNameQuoteFlagSet { get; set; }
     9    IReadOnlyList<Expression> InputExpressions { get; }
    510  }
    611}
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs

    r15017 r15189  
    2424    IPushStack<IReadOnlyList<bool>> BooleanVectorStack { get; }
    2525    IPushStack<IReadOnlyList<string>> StringVectorStack { get; }
    26     IPushStack<string> PrintStack { get; }
     26    IPrintStack PrintStack { get; }
    2727    IDictionary<string, Expression> CustomExpressions { get; }
    2828    IReadOnlyDictionary<StackTypes, IPushStack> Stacks { get; }
     
    3030    void Clear();
    3131    void Reset();
     32
     33    void SetInput(
     34      IReadOnlyList<long> integers = null,
     35      IReadOnlyList<double> floats = null,
     36      IReadOnlyList<bool> booleans = null,
     37      IReadOnlyList<char> chars = null,
     38      IReadOnlyList<string> strings = null,
     39      IReadOnlyList<IReadOnlyList<long>> integerVectors = null,
     40      IReadOnlyList<IReadOnlyList<double>> floatVectors = null,
     41      IReadOnlyList<IReadOnlyList<string>> stringVectors = null);
    3242
    3343    void Run(bool stepwise);
  • 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();
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs

    r15032 r15189  
    4747      PushProgramPoolProvider.Clear();
    4848      ExpressionListPoolProvider.Clear();
     49      pool.Clear();
    4950    }
    5051  }
Note: See TracChangeset for help on using the changeset viewer.