Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problem.ProgramSynthesis.BenchmarkSuite/Problems/Syllables.cs @ 15334

Last change on this file since 15334 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

File size: 3.2 KB
Line 
1namespace HeuristicLab.BenchmarkSuite.Problems {
2  using System;
3
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
8  public class Syllables : BenchmarkSuiteDataDescriptor {
9    private const string name = "Syllables - Hard";
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() {
20      return new ProblemData(ProblemType.Syllables) {
21        Name = Name,
22        Description = Description,
23        ProgramExecutionBudget = 30000000,
24        Examples = CloneExamples(),
25        BestResult = 0,
26        WorstResult = 5000,
27        InputArgumentTypes = new[] { ExampleArgumentType.String },
28        OutputArgumentTypes = new[] { ExampleArgumentType.Print },
29        TrainingCount = 100,
30        TestCount = 1000,
31        EnabledDataTypes = DataTypes.Exec | DataTypes.Integer | DataTypes.Boolean | DataTypes.Char | DataTypes.String | DataTypes.Print,
32        MaxSize = 800,
33        EvalLimit = 1600,
34        ErcOptions = {
35          ErcProbability = 0.05,
36          StringErcOptions = new StringErcOptions(
37            new StringConstantErc("The number of syllables is ", "aeiouy" ),
38            new StringRandomErc {
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 (
48            new IntegerConstantErc('a', 'e', 'i', 'o', 'u'),
49            new IntegerRangeErc(0x20, 0x7e))
50        }
51      };
52    }
53
54    protected override Example ParseExample(string[] input, string[] output) {
55      long numberOfSyllables;
56      if (!GetNumberOfSyllables(output[0], out numberOfSyllables))
57        throw new InvalidOperationException("Unable to parse number of syllables.");
58
59      return new Example {
60        InputArgs = input,
61        OutputArgs = output,
62        InputString = input,
63        OutputPrint = output[0],
64
65        // help
66        OutputInteger = new[] { numberOfSyllables }
67      };
68    }
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    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.