Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs

    r14909 r14952  
    99
    1010  public static class ExpressionTable {
    11     public static readonly IReadOnlyDictionary<string, Expression> StatelessExpressionTable;
    12     public static readonly IReadOnlyDictionary<string, Func<Expression>> StatefulExpressionFactory;
     11    public static readonly IReadOnlyDictionary<Type, Expression> StatelessExpressionTable;
     12    public static readonly IReadOnlyDictionary<Type, Func<Expression>> StatefulExpressionFactory;
    1313    public static readonly IReadOnlyList<string> ExpressionNames;
    1414    public static readonly int ExpressionCount;
     
    3030      StatelessExpressionTable = GetStatelessExpressionTable();
    3131      StatefulExpressionFactory = GetStatefulExpressionFactory();
    32       ExpressionNames = StatelessExpressionTable.Keys.Concat(StatefulExpressionFactory.Keys).ToArray();
     32
     33      ExpressionNames = StatelessExpressionTable.Keys
     34        .Concat(StatefulExpressionFactory.Keys)
     35        .Select(type => typeToNameTable[type])
     36        .ToArray();
    3337
    3438      ExpressionCount = StatelessExpressionTable.Count + StatefulExpressionFactory.Count;
     
    4246    public static IReadOnlyDictionary<Type, PushExpressionAttribute> TypeToAttributeTable { get { return typeToAttributeTable; } }
    4347
    44     private static Dictionary<string, Expression> GetStatelessExpressionTable() {
    45       var dictionary = new Dictionary<string, Expression>();
     48    private static Dictionary<Type, Expression> GetStatelessExpressionTable() {
     49      var dictionary = new Dictionary<Type, Expression>();
    4650
    4751      foreach (var type in StatelessExpressionTypes) {
     
    5054
    5155        typeToAttributeTable.Add(type, attribute);
    52         dictionary.Add(attribute.ExpressionName, expression);
     56        dictionary.Add(type, expression);
    5357        indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.ExpressionName);
    5458        typeToNameTable.Add(type, attribute.ExpressionName);
     
    7276    }
    7377
    74     private static Dictionary<string, Func<Expression>> GetStatefulExpressionFactory() {
    75       var dictionary = new Dictionary<string, Func<Expression>>();
     78    private static Dictionary<Type, Func<Expression>> GetStatefulExpressionFactory() {
     79      var dictionary = new Dictionary<Type, Func<Expression>>();
    7680
    7781      foreach (var type in StatefulExpressionTypes) {
     
    8488
    8589        typeToAttributeTable.Add(type, attribute);
    86         dictionary.Add(attribute.ExpressionName, creator);
     90        dictionary.Add(type, creator);
    8791        indexToNameTable.Add(indexToNameTable.Keys.Count, attribute.ExpressionName);
    8892        typeToNameTable.Add(type, attribute.ExpressionName);
     
    180184
    181185    public static Expression GetStatelessExpression(string name) {
    182       if (StatelessExpressionTable.ContainsKey(name))
    183         return StatelessExpressionTable[name];
     186      if (NameToTypeTable.ContainsKey(name) && StatelessExpressionTable.ContainsKey(NameToTypeTable[name]))
     187        return StatelessExpressionTable[NameToTypeTable[name]];
    184188      throw new NotSupportedException("Expression not supported: " + name);
    185189    }
    186190
    187191    public static bool TryGetStatelessExpression(string name, out Expression expression) {
    188       if (!StatelessExpressionTable.ContainsKey(name)) {
     192      if (!NameToTypeTable.ContainsKey(name) || !StatelessExpressionTable.ContainsKey(NameToTypeTable[name])) {
    189193        expression = null;
    190194        return false;
    191195      }
    192196
    193       expression = StatelessExpressionTable[name];
    194 
     197      expression = StatelessExpressionTable[NameToTypeTable[name]];
    195198      return true;
    196199    }
     
    201204
    202205    public static Expression GetStatefulExpression(string name) {
    203       Func<Expression> creator;
    204       if (StatefulExpressionFactory.TryGetValue(name, out creator))
    205         return creator();
     206      if (NameToTypeTable.ContainsKey(name)) {
     207        Func<Expression> creator;
     208        var type = NameToTypeTable[name];
     209
     210        if (StatefulExpressionFactory.TryGetValue(type, out creator))
     211          return creator();
     212      }
     213
    206214      throw new NotSupportedException("Expression not supported: " + name);
    207215    }
    208216
    209217    public static bool TryGetStatefulExpression(string name, out Expression expression) {
    210       if (StatefulExpressionFactory.ContainsKey(name)) {
    211         expression = StatefulExpressionFactory[name]();
     218      if (NameToTypeTable.ContainsKey(name)) {
     219        expression = StatefulExpressionFactory[NameToTypeTable[name]]();
    212220        return true;
    213221      }
Note: See TracChangeset for help on using the changeset viewer.