1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Generators {
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
|
---|
4 |
|
---|
5 | internal static class ErcUtils {
|
---|
6 | internal static int GetInteger(IReadOnlyIntegerErcOptions options, IRandom random) {
|
---|
7 | var x = options.Constants.Count == 0
|
---|
8 | ? 1
|
---|
9 | : random.Next(0, options.Constants.Count + 1);
|
---|
10 |
|
---|
11 | var value = x < options.Constants.Count
|
---|
12 | ? options.Constants[x]
|
---|
13 | : random.Next(options.Start, options.End);
|
---|
14 |
|
---|
15 | return value;
|
---|
16 | }
|
---|
17 |
|
---|
18 | internal static double GetDouble(IReadOnlyFloatErcOptions options, IRandom random) {
|
---|
19 | var x = options.Constants.Count == 0 ?
|
---|
20 | 1 :
|
---|
21 | random.Next(0, options.Constants.Count + 1);
|
---|
22 |
|
---|
23 | var value = x < options.Constants.Count
|
---|
24 | ? options.Constants[x]
|
---|
25 | : random.NextDouble() * (options.End - options.Start) + options.Start;
|
---|
26 |
|
---|
27 | return value;
|
---|
28 | }
|
---|
29 |
|
---|
30 | internal static bool GetBoolean(IReadOnlyBooleanErcOptions options, IRandom random) {
|
---|
31 | var value = options.GetRandom(random);
|
---|
32 | return value;
|
---|
33 | }
|
---|
34 |
|
---|
35 | internal static string GetString(IReadOnlyStringErcOptions options, IRandom random) {
|
---|
36 | var value = StringGenerator.RandomString(options, random);
|
---|
37 | return value;
|
---|
38 | }
|
---|
39 |
|
---|
40 | internal static char GetChar(IReadOnlyCharErcOptions options, IRandom random) {
|
---|
41 | var value = StringGenerator.RandomChar(options.Start, options.End + 1, random);
|
---|
42 | return value;
|
---|
43 | }
|
---|
44 |
|
---|
45 | internal static string GetName(IReadOnlyNameErcOptions options, IRandom random) {
|
---|
46 | var value = StringGenerator.RandomString(options, random);
|
---|
47 | return value;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|