Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/BenchmarkSuite/Problems/Grades.cs @ 15771

Last change on this file since 15771 was 15771, checked in by bburlacu, 6 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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