namespace HeuristicLab.BenchmarkSuite.Problems { using System; using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Char; using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Integer; using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String; public class Syllables : BenchmarkSuiteDataDescriptor { private const string name = "Syllables - Hard"; private const string fileName = "Syllables.csv"; private const string description = "Given a string containing symbols, spaces, digits, and lowercase letters, count the number of occurrences of vowels(a, e, i, o, u, y) in the string and print that number as X in The number of syllables is X."; protected override string FileName { get { return fileName; } } public override string Name { get { return name; } } public override string Description { get { return description; } } protected override int InputArgumentCount { get { return 1; } } protected override int OutputArgumentCount { get { return 1; } } public override ProblemData CreateProblemData() { return new ProblemData(ProblemType.Syllables) { Name = Name, Description = Description, ProgramExecutionBudget = 30000000, Examples = CloneExamples(), BestResult = 0, WorstResult = 5000, InputArgumentTypes = new[] { ExampleArgumentType.String }, OutputArgumentTypes = new[] { ExampleArgumentType.Print }, TrainingCount = 100, TestCount = 1000, EnabledDataTypes = DataTypes.Exec | DataTypes.Integer | DataTypes.Boolean | DataTypes.Char | DataTypes.String | DataTypes.Print, MaxSize = 800, EvalLimit = 1600, ErcOptions = { ErcProbability = 0.05, StringErcOptions = new StringErcOptions( new StringConstantErc("The number of syllables is ", "aeiouy" ), new StringRandomErc { AllowLowercaseLetters = true, AllowUppercaseLetters = false, AllowDigits = true, AllowSymbols = true, AllowSpace = true, SpaceProbability = 0.2, VowelProbability = 0.2 }), CharErcOptions = new CharErcOptions ( new IntegerConstantErc('a', 'e', 'i', 'o', 'u'), new IntegerRangeErc(0x20, 0x7e)) } }; } protected override Example ParseExample(string[] input, string[] output) { long numberOfSyllables; if (!GetNumberOfSyllables(output[0], out numberOfSyllables)) throw new InvalidOperationException("Unable to parse number of syllables."); return new Example { InputArgs = input, OutputArgs = output, InputString = input, OutputPrint = output[0], // help OutputInteger = new[] { numberOfSyllables } }; } public static bool GetNumberOfSyllables(string str, out long numberOfSyllables) { if (str.Length == 0) { numberOfSyllables = 0; return false; } var lastIndex = str.Length - 1; var lastCharStr = str[lastIndex].ToString(); return long.TryParse(lastCharStr, out numberOfSyllables); } } }