using System.Collections.Generic; namespace HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator { using HeuristicLab.Core; using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; using HeuristicLab.Random; public class LinearCodeGenerator { public static PushProgram RandomProgram(IManagedPool pool, IManagedPool> expressionListPool, int maxPoints, IRandom random = null, IReadOnlyPushConfiguration pushGpConfiguration = null, IDictionary customExpressions = null) { var code = RandomCode(maxPoints, expressionListPool, random, pushGpConfiguration, customExpressions); return PushProgram.Create(pool, code); } public static PushProgram RandomProgram(IManagedPool> expressionListPool, int maxPoints, IRandom random = null, IReadOnlyPushConfiguration pushGpConfiguration = null, IDictionary customExpressions = null) { var code = RandomCode(maxPoints, expressionListPool, random, pushGpConfiguration, customExpressions); return new PushProgram(code); } public static PushProgram RandomProgram(int maxPoints, IRandom random = null, IReadOnlyPushConfiguration pushGpConfiguration = null, IDictionary customExpressions = null) { var code = RandomCode(maxPoints, null, random, pushGpConfiguration, customExpressions); return new PushProgram(code); } public static IReadOnlyList RandomCode( int maxPoints, IManagedPool> expressionListPool = null, IRandom random = null, IReadOnlyPushConfiguration pushConfiguration = null, IDictionary customExpressions = null) { if (maxPoints == 0) return new Expression[0]; random = random ?? new FastRandom(); pushConfiguration = pushConfiguration ?? new PushConfiguration(); var size = maxPoints <= 1 ? 1 : random.Next(1, maxPoints); var expressions = expressionListPool == null ? new List(size) : expressionListPool.Get(); for (var i = 0; i < size; i++) { var expression = CodeGeneratorUtils.CreateExpressionOrErc( random, pushConfiguration.EnabledExpressions, pushConfiguration.ErcOptions, customExpressions); expressions.Add(expression); } return expressions; } } }