Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/17 19:34:13 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

Location:
branches/PushGP/HeuristicLab.PushGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore set to
      *.user
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs

    r15273 r15289  
    55  using System;
    66  using System.Collections;
     7  using System.Globalization;
    78  using System.Reflection;
    89
     
    2627    }
    2728
    28     public static Type GetStackEntryType(this StackTypes stackType) {
    29       if (StackProperties.ContainsKey(stackType) &&
    30           StackProperties[stackType].PropertyType.IsGenericType) {
    31         var genericTypeDef = StackProperties[stackType].PropertyType.GetGenericTypeDefinition();
    32         if (genericTypeDef == typeof(IPushStack<>))
    33           return genericTypeDef.GetGenericArguments()[0];
     29    public static string StringifyResult(this IPushInterpreter interpreter, ExampleArgumentType type, int offset) {
     30      var emptyString = string.Empty;
     31
     32      switch (type) {
     33        case ExampleArgumentType.Integer:
     34          return GetEntryAsString(offset, interpreter.IntegerStack);
     35
     36        case ExampleArgumentType.IntegerVector:
     37          return GetVectorEntryAsString(offset, interpreter.IntegerVectorStack);
     38
     39        case ExampleArgumentType.Float:
     40          return interpreter.FloatStack.Count > offset
     41            ? interpreter.FloatStack[offset].ToString(CultureInfo.CurrentUICulture)
     42            : emptyString;
     43
     44        case ExampleArgumentType.FloatVector:
     45          return GetVectorEntryAsString(offset, interpreter.FloatVectorStack);
     46
     47        case ExampleArgumentType.Boolean:
     48          return GetEntryAsString(offset, interpreter.BooleanStack);
     49
     50        case ExampleArgumentType.Char:
     51          return GetEntryAsString(offset, interpreter.CharStack);
     52
     53        case ExampleArgumentType.Print:
     54          return interpreter.PrintStack.ToString();
     55
     56        case ExampleArgumentType.String:
     57          return GetEntryAsString(offset, interpreter.StringStack);
     58
     59        case ExampleArgumentType.StringVector:
     60          return GetVectorEntryAsString(offset, interpreter.StringVectorStack);
     61
     62        default: return string.Empty;
    3463      }
     64    }
    3565
    36       return StackProperties.ContainsKey(stackType)
    37         ? StackProperties[stackType]
    38             .PropertyType
    39             .GetInterfaces()
    40             .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPushStack<>))
    41             .GetGenericArguments()
    42             .First()
    43         : null;
     66    private static string GetEntryAsString<T>(int offset, IPushStack<T> stack) {
     67      return stack.Count > offset
     68       ? stack[offset].ToString()
     69       : string.Empty;
     70    }
     71
     72    private static string GetVectorEntryAsString<T>(int offset, IPushStack<IReadOnlyList<T>> vectorStack) {
     73      return vectorStack.Count > offset
     74       ? "[" + string.Join(",", vectorStack[offset]) + "]"
     75       : string.Empty;
    4476    }
    4577
Note: See TracChangeset for help on using the changeset viewer.