Changeset 14328 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/CodeGenerator.cs
- Timestamp:
- 10/08/16 12:04:25 (8 years ago)
- 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; 1 using System.Collections.Generic; 3 2 using System.Linq; 4 3 using HeuristicLab.Algorithms.PushGP.Expressions; 4 using HeuristicLab.Random; 5 5 6 6 namespace HeuristicLab.Algorithms.PushGP.Generators … … 8 8 public static class CodeGenerator 9 9 { 10 private static FastRandom random = new FastRandom(); 10 11 public static IEnumerable<Expression> RandomCode(int maxPoints) 11 12 { 12 var actualPoints = StaticRandom.Next(1, maxPoints);13 var actualPoints = random.Next(1, maxPoints); 13 14 14 15 return RandomCodeWithSize(actualPoints).ToArray(); … … 19 20 if (points == 1) 20 21 { 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); 23 24 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) }; 32 26 } 33 27 else … … 35 29 var sizesThisLevel = Decompose(points - 1, points - 1); 36 30 37 return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)) ;31 return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)).Shuffle(random); 38 32 } 39 33 } … … 47 41 else 48 42 { 49 var thisPart = StaticRandom.Next(1, number - 1);43 var thisPart = random.Next(1, number - 1); 50 44 51 45 return new[] { thisPart }.Concat(Decompose(number - thisPart, maxParts - 1));
Note: See TracChangeset
for help on using the changeset viewer.