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