Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/29/12 09:22:21 (12 years ago)
Author:
jkarder
Message:

#1853:

  • enhanced combinations count calculation
  • restructured code
  • minor code improvements
  • added license information
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/Range.cs

    r8517 r8535  
    3838        if (lowerBound != value) {
    3939          if (lowerBound != null) {
     40            lowerBound.ValueChanged -= new EventHandler(lowerBound_ValueChanged);
    4041            lowerBound.ValueChanged -= new EventHandler(lowerBound_ToStringChanged);
    4142          }
    4243          lowerBound = value;
    4344          if (lowerBound != null) {
     45            lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
    4446            lowerBound.ValueChanged += new EventHandler(lowerBound_ToStringChanged);
    4547          }
     
    5658        if (upperBound != value) {
    5759          if (upperBound != null) {
     60            upperBound.ValueChanged -= new EventHandler(upperBound_ValueChanged);
    5861            upperBound.ValueChanged -= new EventHandler(upperBound_ToStringChanged);
    5962          }
    6063          upperBound = value;
    6164          if (upperBound != null) {
     65            upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
    6266            upperBound.ValueChanged += new EventHandler(upperBound_ToStringChanged);
    6367          }
     
    7478        if (stepSize != value) {
    7579          if (stepSize != null) {
     80            stepSize.ValueChanged -= new EventHandler(stepSize_ValueChanged);
    7681            stepSize.ValueChanged -= new EventHandler(stepSize_ToStringChanged);
    7782          }
    7883          stepSize = value;
    7984          if (stepSize != null) {
     85            stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
    8086            stepSize.ValueChanged += new EventHandler(stepSize_ToStringChanged);
    8187          }
     
    101107
    102108    #region Constructors and Cloning
    103     public Range(T lowerBound, T upperBound, T stepSize) {
    104       this.LowerBound = lowerBound;
    105       this.UpperBound = upperBound;
    106       this.StepSize = stepSize;
    107     }
    108 
    109109    [StorableConstructor]
    110110    protected Range(bool deserializing) : base(deserializing) { }
     
    115115      this.StepSize = cloner.Clone(original.StepSize);
    116116    }
    117 
     117    public Range(T lowerBound, T upperBound, T stepSize)
     118      : base() {
     119      this.LowerBound = lowerBound;
     120      this.UpperBound = upperBound;
     121      this.StepSize = stepSize;
     122    }
    118123    [StorableHook(HookType.AfterDeserialization)]
    119124    private void AfterDeserialization() {
    120125      if (lowerBound != null) {
     126        lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged);
    121127        lowerBound.ValueChanged += new EventHandler(lowerBound_ToStringChanged);
    122128      }
    123129      if (upperBound != null) {
     130        upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged);
    124131        upperBound.ValueChanged += new EventHandler(upperBound_ToStringChanged);
    125132      }
    126133      if (stepSize != null) {
     134        stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged);
    127135        stepSize.ValueChanged += new EventHandler(stepSize_ToStringChanged);
    128136      }
     
    131139
    132140    #region Events
     141    private void lowerBound_ValueChanged(object sender, EventArgs e) {
     142      OnLowerBoundChanged();
     143    }
     144    private void upperBound_ValueChanged(object sender, EventArgs e) {
     145      OnUpperBoundChanged();
     146    }
     147    private void stepSize_ValueChanged(object sender, EventArgs e) {
     148      OnStepSizeChanged();
     149    }
    133150    private void lowerBound_ToStringChanged(object sender, EventArgs e) {
    134151      OnToStringChanged();
     
    189206    }
    190207    public bool Validate(string value, out string errorMessage) {
    191       // TODO: check that upper is larger than lower and that stepsize < upper-lower
     208      // TODO: check that stepsize < upper - lower
    192209      T lower = (T)lowerBound.Clone();
    193210      T upper = (T)upperBound.Clone();
     
    206223          upperBound.SetValue(parts2[1]) &&
    207224          stepSize.SetValue(parts1[1])) {
     225        if (Comparer<T>.Default.Compare(lowerBound, upperBound) >= 0) {
     226          errorMessage = "Invalid bounds. (Lower >= Upper)"; return false;
     227        }
    208228        errorMessage = string.Empty; return true;
    209229      } else {
Note: See TracChangeset for help on using the changeset viewer.