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 IntegerErcOptions : ErcOption, IReadOnlyIntegerErcOptions {
|
---|
15 | private const string ConstantsParameterName = "Constants";
|
---|
16 | private const string RangeParameterName = "Range";
|
---|
17 |
|
---|
18 | public IntegerErcOptions() : this(default(int), default(int)) {
|
---|
19 | IsEnabled = false;
|
---|
20 | }
|
---|
21 |
|
---|
22 | public IntegerErcOptions(int start, int end) : this(start, end, new int[0]) {
|
---|
23 | }
|
---|
24 |
|
---|
25 | public IntegerErcOptions(int[] constants) : this(default(int), default(int), constants) {
|
---|
26 | }
|
---|
27 |
|
---|
28 | public IntegerErcOptions(int start, int end, int[] constants) {
|
---|
29 | if (start > end) {
|
---|
30 | throw new InvalidOperationException("start >= end");
|
---|
31 | }
|
---|
32 |
|
---|
33 | IsEnabled = true;
|
---|
34 | Parameters.Add(new ValueParameter<IntArray>(ConstantsParameterName, new IntArray(constants)));
|
---|
35 | Parameters.Add(new FixedValueParameter<IntRange>(RangeParameterName, new IntRange(start, end)));
|
---|
36 | }
|
---|
37 |
|
---|
38 | [StorableConstructor]
|
---|
39 | private IntegerErcOptions(bool deserializing) : base(deserializing) { }
|
---|
40 |
|
---|
41 | public IntegerErcOptions(IntegerErcOptions origin, Cloner cloner) : base(origin, cloner) { }
|
---|
42 |
|
---|
43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
44 | return new IntegerErcOptions(this, cloner);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public IValueParameter<IntArray> ConstantsParameter
|
---|
48 | {
|
---|
49 | get { return (IValueParameter<IntArray>)Parameters[ConstantsParameterName]; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IReadOnlyList<int> Constants
|
---|
53 | {
|
---|
54 | get { return ConstantsParameter.Value.Data; }
|
---|
55 | set { ConstantsParameter.Value = new IntArray(value.ToArray()); }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public IValueParameter<IntRange> RangeParameter
|
---|
59 | {
|
---|
60 | get { return (IValueParameter<IntRange>)Parameters[RangeParameterName]; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | /// <summary>
|
---|
64 | /// The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND.
|
---|
65 | /// </summary>
|
---|
66 | public int Start
|
---|
67 | {
|
---|
68 | get { return RangeParameter.Value.Start; }
|
---|
69 | set { RangeParameter.Value.Start = value; }
|
---|
70 | }
|
---|
71 |
|
---|
72 | /// <summary>
|
---|
73 | /// The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND.
|
---|
74 | /// </summary>
|
---|
75 | public int End
|
---|
76 | {
|
---|
77 | get { return RangeParameter.Value.End; }
|
---|
78 | set { RangeParameter.Value.End = value; }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|