Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/20/17 11:39:53 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added PlushEncoding, ZeroErrorDistributionAnalzer

File:
1 edited

Legend:

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

    r15273 r15275  
    5757      var name = config.EnabledExpressions[index];
    5858      return ExpressionTable.GetExpression(name);
     59    }
     60
     61    public static Expression GetRandomExpression(IRandom random, IReadOnlyErcOptions ercOptions, IReadOnlyExpressionsConfiguration instructions, double inInstructionProbability) {
     62      var x = random.NextDouble();
     63      var inInstructionRelativeProbability = ercOptions.ErcProbability + inInstructionProbability;
     64
     65      Expression expression;
     66
     67      if (ercOptions.ErcProbability > 0 && x <= ercOptions.ErcProbability) {
     68        var stackType = instructions.ExpressionsPerStackCount.RandomWeightedOrDefault(random, pair => pair.Value).Key;
     69
     70        expression = stackType == default(StackTypes)
     71          ? GetRandomExpression(random, instructions)
     72          : CreateRandomErcExpression(stackType, random, ercOptions);
     73      } else if (
     74        inInstructionProbability > 0 &&
     75        x <= inInstructionRelativeProbability &&
     76        instructions.InExpressionCount > 0) {
     77
     78        var nr = random.Next(0, instructions.InExpressionCount) + 1;
     79        expression = ExpressionTable.InExpressionTable[nr];
     80      } else {
     81        expression = GetRandomExpression(random, instructions);
     82      }
     83
     84      return expression;
     85    }
     86
     87    private static Expression GetRandomExpression(
     88      IRandom random,
     89      IReadOnlyExpressionsConfiguration instructionsConfig) {
     90      var index = random.Next(0, instructionsConfig.EnabledExpressions.Count);
     91      var expressionName = instructionsConfig.EnabledExpressions[index];
     92      var expression = ExpressionTable.GetExpression(expressionName);
     93
     94      return expression;
    5995    }
    6096
Note: See TracChangeset for help on using the changeset viewer.