[14875] | 1 | namespace HeuristicLab.BenchmarkSuite.Problems {
|
---|
[15334] | 2 | using System;
|
---|
| 3 |
|
---|
[14897] | 4 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Char;
|
---|
| 5 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Integer;
|
---|
| 6 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String;
|
---|
| 7 |
|
---|
[14875] | 8 | public class Syllables : BenchmarkSuiteDataDescriptor {
|
---|
[14952] | 9 | private const string name = "Syllables - Hard";
|
---|
[14875] | 10 | private const string fileName = "Syllables.csv";
|
---|
| 11 | 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.";
|
---|
| 12 |
|
---|
| 13 | protected override string FileName { get { return fileName; } }
|
---|
| 14 | public override string Name { get { return name; } }
|
---|
| 15 | public override string Description { get { return description; } }
|
---|
| 16 | protected override int InputArgumentCount { get { return 1; } }
|
---|
| 17 | protected override int OutputArgumentCount { get { return 1; } }
|
---|
| 18 |
|
---|
| 19 | public override ProblemData CreateProblemData() {
|
---|
[15017] | 20 | return new ProblemData(ProblemType.Syllables) {
|
---|
[14875] | 21 | Name = Name,
|
---|
| 22 | Description = Description,
|
---|
[15334] | 23 | ProgramExecutionBudget = 30000000,
|
---|
[14875] | 24 | Examples = CloneExamples(),
|
---|
| 25 | BestResult = 0,
|
---|
[15334] | 26 | WorstResult = 5000,
|
---|
[14875] | 27 | InputArgumentTypes = new[] { ExampleArgumentType.String },
|
---|
[14909] | 28 | OutputArgumentTypes = new[] { ExampleArgumentType.Print },
|
---|
[14875] | 29 | TrainingCount = 100,
|
---|
| 30 | TestCount = 1000,
|
---|
[15017] | 31 | EnabledDataTypes = DataTypes.Exec | DataTypes.Integer | DataTypes.Boolean | DataTypes.Char | DataTypes.String | DataTypes.Print,
|
---|
[14875] | 32 | MaxSize = 800,
|
---|
| 33 | EvalLimit = 1600,
|
---|
| 34 | ErcOptions = {
|
---|
| 35 | ErcProbability = 0.05,
|
---|
[14897] | 36 | StringErcOptions = new StringErcOptions(
|
---|
[14952] | 37 | new StringConstantErc("The number of syllables is ", "aeiouy" ),
|
---|
| 38 | new StringRandomErc {
|
---|
[14897] | 39 | AllowLowercaseLetters = true,
|
---|
| 40 | AllowUppercaseLetters = false,
|
---|
| 41 | AllowDigits = true,
|
---|
| 42 | AllowSymbols = true,
|
---|
| 43 | AllowSpace = true,
|
---|
| 44 | SpaceProbability = 0.2,
|
---|
| 45 | VowelProbability = 0.2
|
---|
| 46 | }),
|
---|
| 47 | CharErcOptions = new CharErcOptions (
|
---|
[14952] | 48 | new IntegerConstantErc('a', 'e', 'i', 'o', 'u'),
|
---|
| 49 | new IntegerRangeErc(0x20, 0x7e))
|
---|
[14875] | 50 | }
|
---|
| 51 | };
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected override Example ParseExample(string[] input, string[] output) {
|
---|
[15334] | 55 | long numberOfSyllables;
|
---|
| 56 | if (!GetNumberOfSyllables(output[0], out numberOfSyllables))
|
---|
| 57 | throw new InvalidOperationException("Unable to parse number of syllables.");
|
---|
| 58 |
|
---|
[14875] | 59 | return new Example {
|
---|
| 60 | InputArgs = input,
|
---|
| 61 | OutputArgs = output,
|
---|
| 62 | InputString = input,
|
---|
[14897] | 63 | OutputPrint = output[0],
|
---|
[15334] | 64 |
|
---|
| 65 | // help
|
---|
| 66 | OutputInteger = new[] { numberOfSyllables }
|
---|
[14875] | 67 | };
|
---|
| 68 | }
|
---|
[15334] | 69 |
|
---|
| 70 | public static bool GetNumberOfSyllables(string str, out long numberOfSyllables) {
|
---|
| 71 | if (str.Length == 0) {
|
---|
| 72 | numberOfSyllables = 0;
|
---|
| 73 | return false;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | var lastIndex = str.Length - 1;
|
---|
| 77 | var lastCharStr = str[lastIndex].ToString();
|
---|
| 78 |
|
---|
| 79 | return long.TryParse(lastCharStr, out numberOfSyllables);
|
---|
| 80 | }
|
---|
[14875] | 81 | }
|
---|
| 82 | }
|
---|