Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator
Files:
3 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.
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/LinearCodeGenerator.cs

    r14834 r15273  
    3131      IManagedPool<PooledList<Expression>> expressionListPool = null,
    3232      IRandom random = null,
    33       IReadOnlyPushConfiguration pushConfiguration = null,
     33      IReadOnlyPushConfiguration config = null,
    3434      IDictionary<string, Expression> customExpressions = null) {
    3535      if (maxPoints == 0)
    3636        return new Expression[0];
    3737
    38       random = random ?? new FastRandom();
    39       pushConfiguration = pushConfiguration ?? new PushConfiguration();
     38      random = random ?? new MersenneTwister();
     39      config = config ?? new PushConfiguration();
    4040
    4141      var size = maxPoints <= 1 ? 1 : random.Next(1, maxPoints);
     
    4343
    4444      for (var i = 0; i < size; i++) {
    45         var expression = CodeGeneratorUtils.CreateExpressionOrErc(
     45        var expression = CodeGeneratorUtils.MapToExpression(
    4646          random,
    47           pushConfiguration.EnabledExpressions,
    48           pushConfiguration.ErcOptions,
     47          config.ErcOptions,
     48          config,
    4949          customExpressions);
    5050
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Generators/CodeGenerator/RecursiveCodeGenerator.cs

    r15189 r15273  
    4949    private static IEnumerable<Expression> RandomCodeWithSize(int points, IRandom random, IReadOnlyPushConfiguration pushConfiguration, IDictionary<string, Expression> customExpressions = null) {
    5050      if (points == 1) {
    51         return new[] { CodeGeneratorUtils.CreateExpressionOrErc(
     51        return new[] { CodeGeneratorUtils.MapToExpression(
    5252          random,
    53           pushConfiguration.EnabledExpressions,
    5453          pushConfiguration.ErcOptions,
     54          pushConfiguration,
    5555          customExpressions)
    5656        };
Note: See TracChangeset for help on using the changeset viewer.