Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/17 12:55:58 (7 years ago)
Author:
pkimmesw
Message:

#2665 Started Plush Encoding, Added Zero Error Individual Count Analyzer

File:
1 edited

Legend:

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

    r15189 r15273  
    77
    88  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
     9  using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions;
     10  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
     11  using HeuristicLab.Problems.ProgramSynthesis.Push.SolutionCreator;
    912
    1013  using Stack;
    1114
    1215  internal static class CodeGeneratorUtils {
    13     internal static Expression CreateExpressionOrErc(
     16    private static readonly Expression Noop = ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
     17
     18    internal static Expression MapToExpression(
    1419      IRandom random,
    15       IReadOnlyList<string> enabledExpressions,
    1620      IReadOnlyErcOptions ercOptions,
     21      IReadOnlyExpressionsConfiguration config,
    1722      IDictionary<string, Expression> customExpressions = null) {
    1823      var customCount = customExpressions == null ? 0 : customExpressions.Count;
    19       var index = random.Next(enabledExpressions.Count + customCount);
     24      var enabledExpressionCount = config.EnabledExpressions.Count;
     25      var index = random.Next(enabledExpressionCount + customCount);
    2026
    21       return index >= enabledExpressions.Count
    22         ? customExpressions.Values.ElementAt(index - enabledExpressions.Count)
    23         : CreateExpressionOrErc(index, random, enabledExpressions, ercOptions);
     27      return index >= config.EnabledExpressions.Count
     28        ? customExpressions.Values.ElementAt(index - enabledExpressionCount)
     29        : MapToExpression(index, random, ercOptions, config);
    2430    }
    2531
    26     internal static Expression CreateExpressionOrErc(
     32    internal static Expression MapToExpression(
    2733      int index,
    2834      IRandom random,
    29       IReadOnlyList<string> enabledExpressions,
    30       IReadOnlyErcOptions ercOptions) {
    31       var name = enabledExpressions[index];
     35      IReadOnlyErcOptions ercOptions,
     36      IReadOnlyExpressionsConfiguration config) {
    3237
    33       return CreateExpressionOrErc(name, random, ercOptions);
     38      switch (index) {
     39        case PushSolutionEncoding.Noop:
     40          return Noop;
     41
     42        case PushSolutionEncoding.Erc:
     43          var stackType = config.ExpressionsPerStackCount.RandomWeightedOrDefault(random, pair => pair.Value).Key;
     44
     45          if (stackType == default(StackTypes))
     46            break;
     47
     48          return CreateRandomErcExpression(stackType, random, ercOptions);
     49
     50        case PushSolutionEncoding.In:
     51          if (config.InExpressionCount == 0) break;
     52
     53          var nr = random.Next(0, config.InExpressionCount) + 1;
     54          return ExpressionTable.InExpressionTable[nr];
     55      }
     56
     57      var name = config.EnabledExpressions[index];
     58      return ExpressionTable.GetExpression(name);
    3459    }
    3560
    36     private static Expression CreateExpressionOrErc(
    37       string expressionName,
    38       IRandom random,
    39       IReadOnlyErcOptions ercOptions) {
    40       //var x = random.NextDouble();
    41       //Expression expression = null;
     61    //private static Expression CreateExpressionOrErc(
     62    //  string expressionName,
     63    //  IRandom random,
     64    //  IReadOnlyErcOptions ercOptions) {
     65    //  var x = random.NextDouble();
     66    //  Expression expression = null;
    4267
    43       //if (x < ercOptions.ErcProbability) {
    44       //  var expressionType = ExpressionTable.NameToTypeTable[expressionName];
    45       //  expression = CreateRandomErcExpression(
    46       //      ExpressionTable.TypeToAttributeTable[expressionType].StackType,
    47       //      random,
    48       //      ercOptions);
    49       //}
     68    //  if (x < ercOptions.ErcProbability) {
     69    //    var expressionType = ExpressionTable.NameToTypeTable[expressionName];
     70    //    expression = CreateRandomErcExpression(
     71    //        ExpressionTable.TypeToAttributeTable[expressionType].StackType,
     72    //        random,
     73    //        ercOptions);
     74    //  }
    5075
    51       //if (expression == null || expression is ExecNoopExpression) {
    52       //  expression = ExpressionTable.GetExpression(expressionName);
    53       //}
     76    //  if (expression == null || expression is ExecNoopExpression) {
     77    //    expression = ExpressionTable.GetExpression(expressionName);
     78    //  }
    5479
    55       //return expression;
     80    //  return expression;
     81    //}
    5682
    57       var expression = ExpressionTable.GetExpression(expressionName);
    58 
    59       return expression;
    60     }
    61 
    62     private static readonly Expression Noop = ExpressionTable.GetStatelessExpression<ExecNoopExpression>();
    6383    /// <summary>
    6484    /// Create a ErcExpression whereby the type of the expression conforms to the passed stack type.
Note: See TracChangeset for help on using the changeset viewer.