1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
10 | [StorableClass]
|
---|
11 | public class NumericRange : Item, INumericRange {
|
---|
12 | [Storable]
|
---|
13 | private IntValue lowerBound;
|
---|
14 | public IntValue LowerBound {
|
---|
15 | get { return lowerBound; }
|
---|
16 | set {
|
---|
17 | if (lowerBound != value) {
|
---|
18 | if (lowerBound != null) {
|
---|
19 | lowerBound.ValueChanged -= new EventHandler(lowerBound_ValueChanged);
|
---|
20 | }
|
---|
21 | lowerBound = value;
|
---|
22 | if (lowerBound != null) {
|
---|
23 | lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
|
---|
24 | }
|
---|
25 | OnLowerBoundChanged();
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [Storable]
|
---|
31 | private IntValue upperBound;
|
---|
32 | public IntValue UpperBound {
|
---|
33 | get { return upperBound; }
|
---|
34 | set {
|
---|
35 | if (upperBound != value) {
|
---|
36 | if (upperBound != null) {
|
---|
37 | upperBound.ValueChanged -= new EventHandler(upperBound_ValueChanged);
|
---|
38 | }
|
---|
39 | upperBound = value;
|
---|
40 | if (upperBound != null) {
|
---|
41 | upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
|
---|
42 | }
|
---|
43 | OnUpperBoundChanged();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | [Storable]
|
---|
49 | private IntValue stepSize;
|
---|
50 | public IntValue StepSize {
|
---|
51 | get { return stepSize; }
|
---|
52 | set {
|
---|
53 | if (stepSize != value) {
|
---|
54 | if (stepSize != null) {
|
---|
55 | stepSize.ValueChanged -= new EventHandler(upperBound_ValueChanged);
|
---|
56 | }
|
---|
57 | stepSize = value;
|
---|
58 | if (stepSize != null) {
|
---|
59 | stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
|
---|
60 | }
|
---|
61 | OnStepSizeChanged();
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public NumericRange() {
|
---|
67 | LowerBound = new IntValue(0);
|
---|
68 | UpperBound = new IntValue(0);
|
---|
69 | StepSize = new IntValue(1);
|
---|
70 | }
|
---|
71 |
|
---|
72 | [StorableConstructor]
|
---|
73 | protected NumericRange(bool deserializing) : base(deserializing) { }
|
---|
74 |
|
---|
75 | [StorableHook(HookType.AfterDeserialization)]
|
---|
76 | private void AfterDeserialization() {
|
---|
77 | if (lowerBound != null) {
|
---|
78 | lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
|
---|
79 | }
|
---|
80 | if (upperBound != null) {
|
---|
81 | upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
|
---|
82 | }
|
---|
83 | if (stepSize != null) {
|
---|
84 | stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | void lowerBound_ValueChanged(object sender, EventArgs e) {
|
---|
89 | OnToStringChanged();
|
---|
90 | }
|
---|
91 | void upperBound_ValueChanged(object sender, EventArgs e) {
|
---|
92 | OnToStringChanged();
|
---|
93 | }
|
---|
94 | void stepSize_ValueChanged(object sender, EventArgs e) {
|
---|
95 | OnToStringChanged();
|
---|
96 | }
|
---|
97 |
|
---|
98 | public event EventHandler LowerBoundChanged;
|
---|
99 | private void OnLowerBoundChanged() {
|
---|
100 | var handler = LowerBoundChanged;
|
---|
101 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public event EventHandler UpperBoundChanged;
|
---|
105 | private void OnUpperBoundChanged() {
|
---|
106 | var handler = UpperBoundChanged;
|
---|
107 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
108 | }
|
---|
109 | public event EventHandler StepSizeChanged;
|
---|
110 | private void OnStepSizeChanged() {
|
---|
111 | var handler = StepSizeChanged;
|
---|
112 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
113 | }
|
---|
114 |
|
---|
115 | public override string ToString() {
|
---|
116 | return string.Format("[{0},{1}:{2}]", LowerBound.ToString(), UpperBound.ToString(), StepSize.ToString());
|
---|
117 | }
|
---|
118 |
|
---|
119 | #region Cloning
|
---|
120 | public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
|
---|
121 | NumericRange clone = (NumericRange)base.Clone(cloner);
|
---|
122 | clone.LowerBound = (IntValue)this.LowerBound.Clone();
|
---|
123 | clone.UpperBound = (IntValue)this.UpperBound.Clone();
|
---|
124 | clone.StepSize = (IntValue)this.StepSize.Clone();
|
---|
125 | return base.Clone(cloner);
|
---|
126 | }
|
---|
127 | #endregion
|
---|
128 | }
|
---|
129 | }
|
---|