Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/17 01:15:25 (8 years ago)
Author:
pkimmesw
Message:

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/CodeGeneratorUtils.cs

    r14834 r14875  
    33
    44namespace HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator {
     5
    56  using HeuristicLab.Core;
    6   using HeuristicLab.Problems.ProgramSynthesis.Push.Erc.Interfaces;
     7  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
    78  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    89  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
    910
    1011  internal static class CodeGeneratorUtils {
    11     internal static Expression CreateExpression(IRandom random, IReadOnlyList<string> enabledExpressions, IDictionary<string, Expression> customExpressions = null) {
    12       var customCount = customExpressions == null ? 0 : customExpressions.Count;
    13       var index = random.Next(0, enabledExpressions.Count + customCount);
    14 
    15       if ((index >= 0) && (index < enabledExpressions.Count)) {
    16         var name = enabledExpressions[index];
    17         return ExpressionTable.GetExpression(name);
    18       }
    19 
    20       return customExpressions.ElementAt(index - (enabledExpressions.Count - 1)).Value;
    21     }
    22 
    2312    internal static Expression CreateExpressionOrErc(
    2413      IRandom random,
     
    2615      IReadOnlyErcOptions ercOptions,
    2716      IDictionary<string, Expression> customExpressions = null) {
    28       var expression = CreateExpression(random, enabledExpressions, customExpressions);
    29       return CreateExpressionOrErc(expression, random, ercOptions);
     17      var customCount = customExpressions == null ? 0 : customExpressions.Count;
     18      var index = random.Next(enabledExpressions.Count + customCount);
     19
     20      return index >= enabledExpressions.Count
     21        ? customExpressions.ElementAt(index - (enabledExpressions.Count - 1)).Value
     22        : CreateExpressionOrErc(index, random, enabledExpressions, ercOptions);
    3023    }
    3124
     
    3629      IReadOnlyErcOptions ercOptions) {
    3730      var name = enabledExpressions[index];
    38       var expression = ExpressionTable.GetExpression(name);
    3931
    40       return CreateExpressionOrErc(expression, random, ercOptions);
     32      return CreateExpressionOrErc(name, random, ercOptions);
    4133    }
    4234
    4335    private static Expression CreateExpressionOrErc(
    44       Expression expression,
     36      string expressionName,
    4537      IRandom random,
    4638      IReadOnlyErcOptions ercOptions) {
    4739      var x = random.NextDouble();
     40      Expression expression = null;
    4841
    4942      if (x < ercOptions.ErcProbability) {
    50         var tmp = CreateRandomErcExpression(
    51             ExpressionTable.TypeToAttributeTable[expression.GetType()].StackType,
     43        var expressionType = ExpressionTable.NameToTypeTable[expressionName];
     44        expression = CreateRandomErcExpression(
     45            ExpressionTable.TypeToAttributeTable[expressionType].StackType,
    5246            random,
    5347            ercOptions);
     48      }
    5449
    55         if (!(tmp is ExecNoopExpression)) {
    56           expression = tmp;
    57         }
     50      if (expression == null || expression is ExecNoopExpression) {
     51        expression = ExpressionTable.GetExpression(expressionName);
    5852      }
    5953
Note: See TracChangeset for help on using the changeset viewer.