[4516] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
[4525] | 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[4516] | 8 |
|
---|
| 9 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
[4525] | 10 | [StorableClass]
|
---|
[4516] | 11 | public class NumericRange : Item, INumericRange {
|
---|
[4525] | 12 | [Storable]
|
---|
[4516] | 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 |
|
---|
[4525] | 30 | [Storable]
|
---|
[4516] | 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 |
|
---|
[4525] | 48 | [Storable]
|
---|
[4516] | 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 |
|
---|
[4525] | 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 |
|
---|
[4516] | 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 | }
|
---|
[4525] | 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
|
---|
[4516] | 128 | }
|
---|
| 129 | }
|
---|