1 | namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc {
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 |
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
|
---|
12 |
|
---|
13 | [StorableClass]
|
---|
14 | public class FloatErcOptions : ErcOption, IReadOnlyFloatErcOptions {
|
---|
15 | private const string ConstantsParameterName = "Constants";
|
---|
16 | private const string RangeParameterName = "Range";
|
---|
17 |
|
---|
18 | public FloatErcOptions() : this(default(double), default(double)) {
|
---|
19 | IsEnabled = false;
|
---|
20 | }
|
---|
21 |
|
---|
22 | public FloatErcOptions(double start, double end) : this(start, end, new double[0]) {
|
---|
23 | }
|
---|
24 |
|
---|
25 | public FloatErcOptions(double[] constants) : this(default(double), default(double), constants) {
|
---|
26 | }
|
---|
27 |
|
---|
28 | public FloatErcOptions(double start, double end, double[] constants) {
|
---|
29 | if (start > end) {
|
---|
30 | throw new InvalidOperationException("start >= end");
|
---|
31 | }
|
---|
32 |
|
---|
33 | IsEnabled = true;
|
---|
34 | Parameters.Add(new ValueParameter<DoubleArray>(ConstantsParameterName, new DoubleArray(constants) { Resizable = true }));
|
---|
35 | Parameters.Add(new FixedValueParameter<DoubleRange>(RangeParameterName, new DoubleRange(start, end)));
|
---|
36 | }
|
---|
37 |
|
---|
38 | [StorableConstructor]
|
---|
39 | private FloatErcOptions(bool deserializing) : base(deserializing) { }
|
---|
40 |
|
---|
41 | public FloatErcOptions(FloatErcOptions origin, Cloner cloner) : base(origin, cloner) { }
|
---|
42 |
|
---|
43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
44 | return new FloatErcOptions(this, cloner);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public IValueParameter<DoubleArray> ConstantsParameter
|
---|
48 | {
|
---|
49 | get { return (IValueParameter<DoubleArray>)Parameters[ConstantsParameterName]; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IReadOnlyList<double> Constants
|
---|
53 | {
|
---|
54 | get { return ConstantsParameter.Value.Data; }
|
---|
55 | set { ConstantsParameter.Value = new DoubleArray(value.ToArray()); }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public IValueParameter<DoubleRange> RangeParameter
|
---|
59 | {
|
---|
60 | get { return (IValueParameter<DoubleRange>)Parameters[RangeParameterName]; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /// <summary>
|
---|
64 | /// The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND.
|
---|
65 | /// </summary>
|
---|
66 | public double Start
|
---|
67 | {
|
---|
68 | get { return RangeParameter.Value.Start; }
|
---|
69 | set { RangeParameter.Value.Start = value; }
|
---|
70 | }
|
---|
71 |
|
---|
72 | /// <summary>
|
---|
73 | /// The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND.
|
---|
74 | /// </summary>
|
---|
75 | public double End
|
---|
76 | {
|
---|
77 | get { return RangeParameter.Value.End; }
|
---|
78 | set { RangeParameter.Value.End = value; }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|