Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problem.ProgramSynthesis.BenchmarkSuite/Problems/Grades.cs @ 17104

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

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

File size: 2.9 KB
Line 
1namespace HeuristicLab.BenchmarkSuite.Problems {
2  using System;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Integer;
5  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String;
6
7  public class Grades : BenchmarkSuiteDataDescriptor {
8    private const string name = "Grades - Hard";
9    private const string fileName = "Grades.csv";
10    private const string description = "Given 5 integers, the first four represent the lower numeric thresholds for achieving an A, B, C, and D, and will be distinct and in descending order. The fifth represents the student’s numeric grade. The program must print Student has a X grade., where X is A, B, C, D, or F depending on the thresholds and the numeric grade.";
11
12    protected override string FileName { get { return fileName; } }
13    public override string Name { get { return name; } }
14    public override string Description { get { return description; } }
15    protected override int InputArgumentCount { get { return 5; } }
16    protected override int OutputArgumentCount { get { return 1; } }
17
18    public override ProblemData CreateProblemData() {
19      return new ProblemData(ProblemType.Grades) {
20        Name = Name,
21        Description = Description,
22        ProgramExecutionBudget = 60000000,
23        Examples = CloneExamples(),
24        BestResult = 0,
25        WorstResult = 5000,
26        InputArgumentTypes = new[] { ExampleArgumentType.Integer, ExampleArgumentType.Integer, ExampleArgumentType.Integer, ExampleArgumentType.Integer, ExampleArgumentType.Integer },
27        OutputArgumentTypes = new[] { ExampleArgumentType.Print },
28        TrainingCount = 200,
29        TestCount = 2000,
30        EnabledDataTypes = DataTypes.Exec | DataTypes.Integer | DataTypes.Boolean | DataTypes.String | DataTypes.Print,
31        MaxSize = 400,
32        EvalLimit = 800,
33        ErcOptions = {
34          ErcProbability = 0.05,
35          IntegerErcOptions = new IntegerErcOptions(
36            new IntegerRangeErc(0, 100)),
37          StringErcOptions = new StringErcOptions(
38            new StringConstantErc("Student has a ", " grade", "A", "B", "C", "D", "F"))
39        }
40      };
41    }
42
43    protected override Example ParseExample(string[] input, string[] output) {
44      char grade;
45      if (!GetGrade(output[0], out grade))
46        throw new InvalidOperationException("Unable to parse grade.");
47
48      return new Example {
49        InputArgs = input,
50        OutputArgs = output,
51        InputInteger = ExampleArgumentConverter.ConvertIntegers(input),
52        OutputPrint = output[0],
53
54        // help
55        OutputChar = new[] { grade }
56      };
57    }
58
59    public static bool GetGrade(string str, out char grade) {
60      const string start = "Student has a ";
61
62      if (str.StartsWith(start) && str.Length > start.Length) {
63        grade = str[start.Length];
64        return true;
65      }
66
67      grade = default(char);
68      return false;
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.