Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/NumericRange.cs @ 4516

Last change on this file since 4516 was 4516, checked in by cneumuel, 14 years ago

initial prototype for Meta Optimization Problem (#1215)

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7
8namespace HeuristicLab.Problems.MetaOptimization {
9  public class NumericRange : Item, INumericRange {
10    private IntValue lowerBound;
11    public IntValue LowerBound {
12      get { return lowerBound; }
13      set {
14        if (lowerBound != value) {
15          if (lowerBound != null) {
16            lowerBound.ValueChanged -= new EventHandler(lowerBound_ValueChanged);
17          }
18          lowerBound = value;
19          if (lowerBound != null) {
20            lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
21          }
22          OnLowerBoundChanged();
23        }
24      }
25    }
26
27    private IntValue upperBound;
28    public IntValue UpperBound {
29      get { return upperBound; }
30      set {
31        if (upperBound != value) {
32          if (upperBound != null) {
33            upperBound.ValueChanged -= new EventHandler(upperBound_ValueChanged);
34          }
35          upperBound = value;
36          if (upperBound != null) {
37            upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
38          }
39          OnUpperBoundChanged();
40        }
41      }
42    }
43
44    private IntValue stepSize;
45    public IntValue StepSize {
46      get { return stepSize; }
47      set {
48        if (stepSize != value) {
49          if (stepSize != null) {
50            stepSize.ValueChanged -= new EventHandler(upperBound_ValueChanged);
51          }
52          stepSize = value;
53          if (stepSize != null) {
54            stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
55          }
56          OnStepSizeChanged();
57        }
58      }
59    }
60
61    public NumericRange() {
62      LowerBound = new IntValue(0);
63      UpperBound = new IntValue(0);
64      StepSize = new IntValue(1);
65    }
66
67    void lowerBound_ValueChanged(object sender, EventArgs e) {
68      OnToStringChanged();
69    }
70    void upperBound_ValueChanged(object sender, EventArgs e) {
71      OnToStringChanged();
72    }
73    void stepSize_ValueChanged(object sender, EventArgs e) {
74      OnToStringChanged();
75    }
76
77    public event EventHandler LowerBoundChanged;
78    private void OnLowerBoundChanged() {
79      var handler = LowerBoundChanged;
80      if (handler != null) handler(this, EventArgs.Empty);
81    }
82
83    public event EventHandler UpperBoundChanged;
84    private void OnUpperBoundChanged() {
85      var handler = UpperBoundChanged;
86      if (handler != null) handler(this, EventArgs.Empty);
87    }
88    public event EventHandler StepSizeChanged;
89    private void OnStepSizeChanged() {
90      var handler = StepSizeChanged;
91      if (handler != null) handler(this, EventArgs.Empty);
92    }
93
94    public override string ToString() {
95      return string.Format("[{0},{1}:{2}]", LowerBound.ToString(), UpperBound.ToString(), StepSize.ToString());
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.