Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis.Views/BenchmarkSuite/ViewHelper.cs @ 16413

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

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

File size: 4.0 KB
Line 
1namespace HeuristicLab.BenchmarkSuite.Views {
2  using System;
3  using System.Collections.Generic;
4  using System.Globalization;
5  using System.Linq;
6
7  public static class ViewHelper {
8    public static string StringifyInput(ExampleArgumentType type, int offset, string floatFormat, Example example, string valueSeparator) {
9      switch (type) {
10        case ExampleArgumentType.Integer: return example.InputInteger[offset].ToString();
11        case ExampleArgumentType.IntegerVector: return "[" + string.Join(", ", example.InputIntegerVector[offset]) + "]";
12
13        case ExampleArgumentType.Float: return example.InputFloat[offset].ToString(floatFormat, CultureInfo.CurrentUICulture);
14        case ExampleArgumentType.FloatVector: return "[" + string.Join(", ", example.InputFloatVector[offset].Select(x => x.ToString(floatFormat, CultureInfo.InvariantCulture))) + "]";
15
16        case ExampleArgumentType.Boolean: return example.InputBoolean[offset].ToString();
17        case ExampleArgumentType.Char: return example.InputChar[offset].ToString();
18
19        case ExampleArgumentType.String: return example.InputString[offset];
20        case ExampleArgumentType.StringVector: return "[" + string.Join(", ", example.InputStringVector[offset]) + "]";
21
22        default: return string.Empty;
23      }
24    }
25
26    public static string StringifyOutput(ExampleArgumentType type, int offset, string floatFormat, Example example, string valueSeparator) {
27      switch (type) {
28        case ExampleArgumentType.Integer: return example.OutputInteger[offset].ToString();
29        case ExampleArgumentType.IntegerVector: return "[" + string.Join(", ", example.OutputIntegerVector[offset]) + "]";
30
31        case ExampleArgumentType.Float: return example.OutputFloat[offset].ToString(floatFormat, CultureInfo.InvariantCulture);
32        case ExampleArgumentType.FloatVector: return "[" + string.Join(", ", example.OutputFloatVector[offset].Select(x => x.ToString(floatFormat, CultureInfo.InvariantCulture))) + "]";
33
34        case ExampleArgumentType.Boolean: return example.OutputBoolean[offset].ToString();
35        case ExampleArgumentType.Char: return example.OutputChar[offset].ToString();
36
37        case ExampleArgumentType.String: return example.OutputString[offset];
38        case ExampleArgumentType.Print: return example.OutputPrint;
39        case ExampleArgumentType.StringVector: return "[" + string.Join(", ", example.OutputStringVector[offset]) + "]";
40
41        default: return string.Empty;
42      }
43    }
44
45    private const string IntegerColumnHeader = "int";
46    private const string IntegersColumnHeader = "int[]";
47    private const string DoubleColumnHeader = "float";
48    private const string DoublesColumnHeader = "float[]";
49    private const string BooleanColumnHeader = "bool";
50    private const string CharColumnHeader = "char";
51    private const string StringColumnHeader = "string";
52    private const string PrintColumnHeader = "print";
53    private const string StringsColumnHeader = "string[]";
54    public static string GetHeaderTypeName(ExampleArgumentType type) {
55      switch (type) {
56        case ExampleArgumentType.Integer: return IntegerColumnHeader;
57        case ExampleArgumentType.Float: return DoubleColumnHeader;
58        case ExampleArgumentType.Boolean: return BooleanColumnHeader;
59        case ExampleArgumentType.Char: return CharColumnHeader;
60        case ExampleArgumentType.String: return StringColumnHeader;
61        case ExampleArgumentType.Print: return PrintColumnHeader;
62        case ExampleArgumentType.IntegerVector: return IntegersColumnHeader;
63        case ExampleArgumentType.FloatVector: return DoublesColumnHeader;
64        case ExampleArgumentType.StringVector: return StringsColumnHeader;
65        default: return string.Empty;
66      }
67    }
68
69    public static Dictionary<ExampleArgumentType, int> CreateArgumentCountDict() {
70      return Enum.GetValues(typeof(ExampleArgumentType)).Cast<ExampleArgumentType>().ToDictionary(type => type, _ => 0);
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.