Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/16 12:04:25 (8 years ago)
Author:
pkimmesw
Message:

#2665 Set .NET version to 4.5, C# version to 5.0, Added expression templates and factory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/CodeGenerator.cs

    r14323 r14328  
    1 using System;
    2 using System.Collections.Generic;
     1using System.Collections.Generic;
    32using System.Linq;
    43using HeuristicLab.Algorithms.PushGP.Expressions;
     4using HeuristicLab.Random;
    55
    66namespace HeuristicLab.Algorithms.PushGP.Generators
     
    88    public static class CodeGenerator
    99    {
     10        private static FastRandom random = new FastRandom();
    1011        public static IEnumerable<Expression> RandomCode(int maxPoints)
    1112        {
    12             var actualPoints = StaticRandom.Next(1, maxPoints);
     13            var actualPoints = random.Next(1, maxPoints);
    1314
    1415            return RandomCodeWithSize(actualPoints).ToArray();
     
    1920            if (points == 1)
    2021            {
    21                 OpCode opCode;
    22                 Func<Expression> creator;
     22                // TODO: If this is an "ephemeral random constant"???? then return a randomly - chosen value of the appropriate type;
     23                var opCode = (OpCode)random.Next(OpCodeExtensions.Min, OpCodeExtensions.Max);
    2324
    24                 do
    25                 {
    26                     // TODO: If this is an "ephemeral random constant"???? then return a randomly - chosen value of the appropriate type;
    27                     opCode = (OpCode)StaticRandom.Next(OpCodeExtensions.Min, OpCodeExtensions.Max);
    28                 }
    29                 while (!ExpressionCreatorTable.TryGetCreator(opCode, out creator));
    30 
    31                 return new[] { creator.Invoke() };
     25                return new[] { ExpressionFactory.Create(opCode) };
    3226            }
    3327            else
     
    3529                var sizesThisLevel = Decompose(points - 1, points - 1);
    3630
    37                 return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size));
     31                return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)).Shuffle(random);
    3832            }
    3933        }
     
    4741            else
    4842            {
    49                 var thisPart = StaticRandom.Next(1, number - 1);
     43                var thisPart = random.Next(1, number - 1);
    5044
    5145                return new[] { thisPart }.Concat(Decompose(number - thisPart, maxParts - 1));
Note: See TracChangeset for help on using the changeset viewer.