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
Location:
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints
Files:
5 edited

Legend:

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

    r8517 r8535  
    8686    }
    8787
    88     #region constructors and cloning
    89     public ConstrainedValue() { }
     88    #region Constructors and Cloning
    9089    [StorableConstructor]
    9190    protected ConstrainedValue(bool deserializing) : base(deserializing) { }
    92     public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable) {
    93       this.Value = value;
    94       this.ValueDataType = valueDataType;
    95       this.ValidValues = validValues;
    96       this.isNullable = isNullable;
    97     }
    9891    protected ConstrainedValue(ConstrainedValue original, Cloner cloner)
    9992      : base(original, cloner) {
     
    10396      this.isNullable = original.isNullable;
    10497    }
    105     public override IDeepCloneable Clone(Cloner cloner) {
    106       return new ConstrainedValue(this, cloner);
     98    public ConstrainedValue() : base() { }
     99    public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable)
     100      : base() {
     101      this.Value = value;
     102      this.ValueDataType = valueDataType;
     103      this.ValidValues = validValues;
     104      this.isNullable = isNullable;
    107105    }
    108106    [StorableHook(HookType.AfterDeserialization)]
    109107    private void AfterDeserialization() {
    110108      if (this.value != null) RegisterEvents();
     109    }
     110    public override IDeepCloneable Clone(Cloner cloner) {
     111      return new ConstrainedValue(this, cloner);
    111112    }
    112113    #endregion
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/DoubleValueRange.cs

    r8517 r8535  
    3030  [StorableClass]
    3131  public class DoubleValueRange : Range<DoubleValue> {
    32 
    33     public override DoubleValue LowerBound {
    34       get {
    35         return base.LowerBound;
    36       }
    37       set {
    38         base.LowerBound = value;
    39       }
    40     }
    41 
    42     public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { }
     32    #region Constructors and Cloning
    4333    [StorableConstructor]
    4434    protected DoubleValueRange(bool deserializing) : base(deserializing) { }
    4535    protected DoubleValueRange(DoubleValueRange original, Cloner cloner) : base(original, cloner) { }
     36    public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    4637    public override IDeepCloneable Clone(Cloner cloner) {
    4738      return new DoubleValueRange(this, cloner);
    4839    }
     40    #endregion
    4941
    5042    protected override DoubleValue GetRandomSample(IRandom random) {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/IntValueRange.cs

    r8517 r8535  
    3030  [StorableClass]
    3131  public class IntValueRange : Range<IntValue> {
    32 
    33     public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { }
     32    #region Constructors and Cloning
    3433    [StorableConstructor]
    3534    protected IntValueRange(bool deserializing) : base(deserializing) { }
    3635    protected IntValueRange(IntValueRange original, Cloner cloner) : base(original, cloner) { }
     36    public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    3737    public override IDeepCloneable Clone(Cloner cloner) {
    3838      return new IntValueRange(this, cloner);
    3939    }
     40    #endregion
    4041
    4142    protected override IntValue GetRandomSample(IRandom random) {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/PercentValueRange.cs

    r8517 r8535  
    3030  [StorableClass]
    3131  public class PercentValueRange : Range<PercentValue> {
    32 
    33     public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { }
     32    #region Constructors and Cloning
    3433    [StorableConstructor]
    3534    protected PercentValueRange(bool deserializing) : base(deserializing) { }
    3635    protected PercentValueRange(PercentValueRange original, Cloner cloner) : base(original, cloner) { }
     36    public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    3737    public override IDeepCloneable Clone(Cloner cloner) {
    3838      return new PercentValueRange(this, cloner);
    3939    }
     40    #endregion
    4041
    4142    protected override PercentValue GetRandomSample(IRandom random) {
  • 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.