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
Files:
22 edited

Legend:

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

    r8517 r8535  
    4141    [StorableConstructor]
    4242    protected AlgorithmProblemItem(bool deserializing) : base(deserializing) { }
    43     public AlgorithmProblemItem() {
     43    protected AlgorithmProblemItem(AlgorithmProblemItem original, Cloner cloner) : base(original, cloner) { }
     44    public AlgorithmProblemItem()
     45      : base() {
    4446      this.Parameters.Add(new ValueParameter<IAlgorithm>("Algorithm"));
    4547      this.Parameters.Add(new ValueParameter<IProblem>("Problem"));
    46     }
    47     protected AlgorithmProblemItem(AlgorithmProblemItem original, Cloner cloner)
    48       : base(original, cloner) {
    4948    }
    5049    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ConstrainedItemList.cs

    r8517 r8535  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using HeuristicLab.Common;
    324using HeuristicLab.Core;
     
    1940    }
    2041
    21     public ConstrainedItemList() {
    22       Type = typeof(T);
    23     }
     42    #region Constructors and Cloning
    2443    [StorableConstructor]
    2544    protected ConstrainedItemList(bool deserializing) : base(deserializing) { }
     
    2847      this.Type = original.Type;
    2948    }
     49    public ConstrainedItemList()
     50      : base() {
     51      Type = typeof(T);
     52    }
    3053    public override IDeepCloneable Clone(Cloner cloner) {
    3154      return new ConstrainedItemList<T>(this, cloner);
    3255    }
     56    #endregion
    3357  }
    3458}
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ConstrainedTypeValue.cs

    r8517 r8535  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    1132  [StorableClass]
    1233  public class ConstrainedTypeValue : TypeValue {
    13 
    1434    private IEnumerable<Type> validTypes;
    1535    public IEnumerable<Type> ValidTypes {
     
    2545    }
    2646
     47    #region Constructors and Cloning
     48    [StorableConstructor]
     49    protected ConstrainedTypeValue(bool deserializing) : base(deserializing) { }
     50    protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner)
     51      : base(original, cloner) {
     52      if (original.validTypes != null)
     53        this.validTypes = new List<Type>(original.validTypes);
     54    }
    2755    public ConstrainedTypeValue()
    2856      : base() {
     
    3361      this.Value = value;
    3462    }
    35 
    36     [StorableConstructor]
    37     protected ConstrainedTypeValue(bool deserializing) : base(deserializing) { }
    38     protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner)
    39       : base(original, cloner) {
    40       if (original.validTypes != null)
    41         this.validTypes = new List<Type>(original.validTypes);
    42     }
    4363    public override IDeepCloneable Clone(Cloner cloner) {
    4464      return new ConstrainedTypeValue(this, cloner);
    4565    }
     66    #endregion
    4667  }
    4768
     
    4970  [StorableClass]
    5071  public class ConstrainedTypeValue<T> : ConstrainedTypeValue where T : class, IItem {
    51 
     72    [StorableConstructor]
     73    protected ConstrainedTypeValue(bool deserializing)
     74      : base(deserializing) {
     75      if (deserializing) {
     76        this.ValidTypes = ApplicationManager.Manager.GetTypes(typeof(T), true).ToList();
     77      }
     78    }
     79    protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner) : base(original, cloner) { }
    5280    public ConstrainedTypeValue()
    5381      : base() {
     
    6088      this.Value = value;
    6189    }
    62 
    63     [StorableConstructor]
    64     protected ConstrainedTypeValue(bool deserializing)
    65       : base(deserializing) {
    66       if (deserializing) {
    67         this.ValidTypes = ApplicationManager.Manager.GetTypes(typeof(T), true).ToList();
    68       }
    69     }
    70 
    71     protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner) : base(original, cloner) { }
    7290    public override IDeepCloneable Clone(Cloner cloner) {
    7391      return new ConstrainedTypeValue<T>(this, cloner);
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Interfaces/IOptimizable.cs

    r8517 r8535  
    4242    event EventHandler IsOptimizableChanged;
    4343    event EventHandler OptimizeChanged;
     44    event EventHandler CombinationsCountChanged;
    4445
    4546    /// <summary>
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Interfaces/IValueConfiguration.cs

    r8517 r8535  
    2828
    2929    event EventHandler ValueChanged;
    30 
    31     //void Parameterize(IParameterizedItem item);
    3230  }
    3331}
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/NullValue.cs

    r8517 r8535  
    2727  [StorableClass]
    2828  public class NullValue : ValueTypeValue<int> {
    29 
    30     public NullValue() { }
    3129    [StorableConstructor]
    3230    protected NullValue(bool deserializing) : base(deserializing) { }
    33     protected NullValue(NullValue original, Cloner cloner)
    34       : base(original, cloner) {
    35     }
     31    protected NullValue(NullValue original, Cloner cloner) : base(original, cloner) { }
     32    public NullValue() : base() { }
    3633    public override IDeepCloneable Clone(Cloner cloner) {
    3734      return new NullValue(this, cloner);
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurationTree.cs

    r8524 r8535  
    3737  [StorableClass]
    3838  public class ParameterConfigurationTree : ParameterizedValueConfiguration, IEnumerable {
     39    [Storable]
     40    private long combinationsCount;
     41    public long CombinationsCount {
     42      get { return combinationsCount; }
     43      private set {
     44        if (combinationsCount != value) {
     45          combinationsCount = value;
     46          OnCombinationsCountChanged();
     47        }
     48      }
     49    }
     50
    3951    [Storable]
    4052    private DoubleValue quality;
     
    213225      this.Name = algorithm.ItemName;
    214226
    215       var algproblemitem = new AlgorithmProblemItem();
    216       algproblemitem.AlgorithmParameter.Value = algorithm;
    217       algproblemitem.ProblemParameter.Value = problem;
     227      var algProblemItem = new AlgorithmProblemItem();
     228      algProblemItem.AlgorithmParameter.Value = algorithm;
     229      algProblemItem.ProblemParameter.Value = problem;
    218230      this.discoverValidValues = false;
    219231
    220       this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Algorithm", algproblemitem.AlgorithmParameter));
    221       this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Problem", algproblemitem.ProblemParameter));
     232      var algConfig = new SingleValuedParameterConfiguration("Algorithm", algProblemItem.AlgorithmParameter);
     233      var problemConfig = new SingleValuedParameterConfiguration("Problem", algProblemItem.ProblemParameter);
     234
     235      algConfig.CombinationsCountChanged += new EventHandler(UpdateConfigurationsCount);
     236      problemConfig.CombinationsCountChanged += new EventHandler(UpdateConfigurationsCount);
     237
     238      this.parameterConfigurations.Add(algConfig);
     239      this.parameterConfigurations.Add(problemConfig);
    222240
    223241      // problems can be modified in the list of problem instances, so the parameters which are not Optimize=true,
    224242      // must not be modifiable in the parameter configuration tree. otherwise the parameter values would be ambiguous
    225243      ProblemConfiguration.ValuesReadOnly = true;
     244
     245      CombinationsCount = GetCombinationCount(0);
    226246    }
    227247
     
    233253    private void AfterDeserialization() {
    234254      if (ProblemConfiguration != null) ProblemConfiguration.ValuesReadOnly = true;
     255      CombinationsCount = GetCombinationCount(0);
    235256    }
    236257    #endregion
     
    265286    private void Quality_ValueChanged(object sender, EventArgs e) {
    266287      OnQualityChanged();
     288    }
     289
     290    private void UpdateConfigurationsCount(object sender, EventArgs e) {
     291      CombinationsCount = GetCombinationCount(0);
    267292    }
    268293
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurations/ParameterConfiguration.cs

    r8517 r8535  
    5757          }
    5858          OnOptimizeChanged();
     59          OnCombinationsCountChanged();
    5960          OnToStringChanged();
     61        }
     62      }
     63    }
     64
     65    [Storable]
     66    protected long combinationsCount;
     67    public virtual long CombinationsCount {
     68      get { return combinationsCount; }
     69      set {
     70        if (combinationsCount != value) {
     71          combinationsCount = value;
     72          OnCombinationsCountChanged();
    6073        }
    6174      }
     
    179192
    180193    #region Constructors and Cloning
    181     public ParameterConfiguration(string parameterName, IValueParameter valueParameter, bool discoverValidValues) {
     194    public ParameterConfiguration(string parameterName, IValueParameter valueParameter, bool discoverValidValues)
     195      : base() {
    182196      this.AutoPopulateValueConfigurations = true;
    183197      this.ParameterName = parameterName;
     
    202216      }
    203217    }
    204     public ParameterConfiguration(string parameterName, Type type, IItem actualValue, IEnumerable<IValueConfiguration> valueConfigurations) {
     218    public ParameterConfiguration(string parameterName, Type type, IItem actualValue, IEnumerable<IValueConfiguration> valueConfigurations)
     219      : base() {
    205220      this.AutoPopulateValueConfigurations = false;
    206221      this.ParameterName = parameterName;
     
    211226      this.validTypes = new Type[] { type };
    212227      this.IsNullable = false;
    213       this.itemImage = valueConfigurations.Count() > 0 ? valueConfigurations.FirstOrDefault().ItemImage : null;
     228      this.itemImage = valueConfigurations.Any() ? valueConfigurations.First().ItemImage : null;
    214229      this.ValueConfigurations = new CheckedValueConfigurationList(valueConfigurations);
    215230      this.ActualValue = new ConstrainedValue(actualValue, type, CreateValidValues(), this.IsNullable);
    216231    }
    217     public ParameterConfiguration(string parameterName, Type type, IItem actualValue) {
     232    public ParameterConfiguration(string parameterName, Type type, IItem actualValue)
     233      : base() {
    218234      this.AutoPopulateValueConfigurations = true;
    219235      this.ParameterName = parameterName;
     
    231247      }
    232248    }
    233     protected ParameterConfiguration() { }
     249    protected ParameterConfiguration() : base() { }
    234250    [StorableConstructor]
    235251    protected ParameterConfiguration(bool deserializing) { }
    236 
    237252    protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner)
    238253      : base(original, cloner) {
     
    316331              }
    317332            }
     333            valueConfiguration.CombinationsCountChanged += (sender, args) => OnCombinationsCountChanged();
    318334            this.ValueConfigurations.Add(valueConfiguration, true);
    319335          }
     
    357373        return new List<Type> { parameter };
    358374
    359       //TODO: not sure if this if makes sense; maybe only leave else branch here
     375      // TODO: check if this makes sense; maybe only leave else branch here
    360376      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
    361377        // use existing validvalues if known
     
    391407
    392408      // copy value from ValidValues; this ensures that previously set ActualNames for a type are kept
    393       IItem value = this.validValues.Where(v => v.GetType() == type).SingleOrDefault();
     409      IItem value = this.validValues.SingleOrDefault(v => v.GetType() == type);
    394410      if (value != null)
    395411        return value;
     
    425441    private void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    426442      OnToStringChanged();
     443      OnCombinationsCountChanged();
    427444      KeepActualValueConfigurationIndexConsistent();
    428445    }
     
    430447    private void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    431448      OnToStringChanged();
     449      OnCombinationsCountChanged();
    432450      KeepActualValueConfigurationIndexConsistent();
    433451    }
    434452    private void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    435453      OnToStringChanged();
     454      OnCombinationsCountChanged();
    436455      KeepActualValueConfigurationIndexConsistent();
    437456    }
     
    451470    public virtual bool CanChangeName {
    452471      get { return false; }
    453     }
    454     public override string ItemDescription {
    455       get { return base.ItemDescription; }
    456     }
    457     public override string ItemName {
    458       get { return base.ItemName; }
    459472    }
    460473    #endregion
     
    494507    protected virtual void OnOptimizeChanged() {
    495508      var handler = OptimizeChanged;
     509      if (handler != null) handler(this, EventArgs.Empty);
     510    }
     511
     512    public event EventHandler CombinationsCountChanged;
     513    protected void OnCombinationsCountChanged() {
     514      var handler = CombinationsCountChanged;
    496515      if (handler != null) handler(this, EventArgs.Empty);
    497516    }
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurations/SingleValuedParameterConfiguration.cs

    r8517 r8535  
    2929  [StorableClass]
    3030  public class SingleValuedParameterConfiguration : ParameterConfiguration {
    31 
    3231    #region Constructors and Cloning
    3332    [StorableConstructor]
    3433    protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { }
     34    protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner) : base(original, cloner) { }
    3535    public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter)
    3636      : base(parameterName, valueParameter, false) {
     
    5757        this.validValues,
    5858        this.IsNullable);
    59     }
    60     protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)
    61       : base(original, cloner) {
    6259    }
    6360    public override IDeepCloneable Clone(Cloner cloner) {
  • 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 {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/SymbolicExpressionGrammar/SymbolValueConfiguration.cs

    r8517 r8535  
    4343    [StorableConstructor]
    4444    protected SymbolValueConfiguration(bool deserializing) : base(deserializing) { }
     45    protected SymbolValueConfiguration(SymbolValueConfiguration original, Cloner cloner)
     46      : base(original, cloner) {
     47      RegisterInitialFrequencyEvents();
     48      this.parentOptimizable = cloner.Clone(original.parentOptimizable);
     49    }
    4550    public SymbolValueConfiguration(Symbol symbol)
    4651      : base() {
     
    5055      this.ActualValue = new ConstrainedValue(symbol, symbol.GetType(), new ItemSet<IItem> { symbol }, false);
    5156    }
    52     protected SymbolValueConfiguration(SymbolValueConfiguration original, Cloner cloner)
    53       : base(original, cloner) {
     57    [StorableHook(HookType.AfterDeserialization)]
     58    private void AfterDeserialization() {
    5459      RegisterInitialFrequencyEvents();
    55       this.parentOptimizable = cloner.Clone(original.parentOptimizable);
    5660    }
    5761    public override IDeepCloneable Clone(Cloner cloner) {
    5862      return new SymbolValueConfiguration(this, cloner);
    59     }
    60     [StorableHook(HookType.AfterDeserialization)]
    61     private void AfterDeserialization() {
    62       RegisterInitialFrequencyEvents();
    6363    }
    6464    #endregion
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/SymbolicExpressionGrammar/SymbolicExpressionGrammarValueConfiguration.cs

    r8517 r8535  
    2929  [StorableClass]
    3030  public class SymbolicExpressionGrammarValueConfiguration : ParameterizedValueConfiguration {
    31 
    3231    #region Constructors and Cloning
    3332    [StorableConstructor]
    3433    protected SymbolicExpressionGrammarValueConfiguration(bool deserializing) : base(deserializing) { }
     34    protected SymbolicExpressionGrammarValueConfiguration(SymbolicExpressionGrammarValueConfiguration original, Cloner cloner) : base(original, cloner) { }
    3535    public SymbolicExpressionGrammarValueConfiguration() : base() { }
    36     public SymbolicExpressionGrammarValueConfiguration(ISymbolicExpressionGrammar grammar) {
     36    public SymbolicExpressionGrammarValueConfiguration(ISymbolicExpressionGrammar grammar)
     37      : base() {
    3738      this.IsOptimizable = true;
    3839      this.ActualValue = new ConstrainedValue(grammar, grammar.GetType(), new ItemSet<IItem> { grammar }, false);
    39     }
    40     protected SymbolicExpressionGrammarValueConfiguration(SymbolicExpressionGrammarValueConfiguration original, Cloner cloner)
    41       : base(original, cloner) {
    4240    }
    4341    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/TypeValue.cs

    r8517 r8535  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Drawing;
    324using HeuristicLab.Common;
     
    3253    }
    3354
     55    #region Constructors and Cloning
     56    [StorableConstructor]
     57    protected TypeValue(bool deserializing) : base(deserializing) { }
     58    protected TypeValue(TypeValue original, Cloner cloner)
     59      : base(original, cloner) {
     60      this.value = original.value;
     61      this.readOnly = original.readOnly;
     62    }
    3463    public TypeValue()
    3564      : base() {
     
    4170      this.readOnly = false;
    4271    }
    43     [StorableConstructor]
    44     protected TypeValue(bool deserializing) : base(deserializing) { }
    45     protected TypeValue(TypeValue original, Cloner cloner)
    46       : base(original, cloner) {
    47       this.value = original.value;
    48       this.readOnly = original.readOnly;
    49     }
    5072    public override IDeepCloneable Clone(Cloner cloner) {
    5173      return new TypeValue(this, cloner);
    5274    }
     75    #endregion
    5376
    5477    public virtual TypeValue AsReadOnly() {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/CheckedValueConfigurationCollection.cs

    r8517 r8535  
    2828
    2929namespace HeuristicLab.Encodings.ParameterConfigurationEncoding {
    30   // todo: check that at least 1 elements needs to be selected
    31   // todo: control creatable item types
     30  // TODO: check that at least 1 element needs to be selected
     31  // TODO: control creatable item types
    3232  [StorableClass]
    3333  public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList {
     
    4444    }
    4545
    46     public CheckedValueConfigurationList(IItemSet<IItem> validValues) {
    47       this.validValues = validValues;
    48       RegisterEvents();
    49     }
    50     public CheckedValueConfigurationList(IEnumerable<IValueConfiguration> collection)
    51       : base(collection) {
    52       validValues = null;
    53       // event wiring not needed
    54     }
    55     public CheckedValueConfigurationList() {
    56       RegisterEvents();
    57     }
     46    #region Constructors and Cloning
    5847    [StorableConstructor]
    5948    protected CheckedValueConfigurationList(bool deserializing)
     
    6756      RegisterEvents();
    6857    }
    69 
     58    public CheckedValueConfigurationList(IItemSet<IItem> validValues)
     59      : base() {
     60      this.validValues = validValues;
     61      RegisterEvents();
     62    }
     63    public CheckedValueConfigurationList(IEnumerable<IValueConfiguration> collection)
     64      : base(collection) {
     65      validValues = null;
     66      // event wiring not needed
     67    }
     68    public CheckedValueConfigurationList()
     69      : base() {
     70      RegisterEvents();
     71    }
    7072    public override IDeepCloneable Clone(Cloner cloner) {
    7173      return new CheckedValueConfigurationList(this, cloner);
     
    7577      RegisterEvents();
    7678    }
     79    #endregion
    7780
    7881    private void RegisterEvents() {
    7982      this.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
    80       this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
    8183    }
    8284
    8385    private void DeregisterEvents() {
    84       this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
    8586      this.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
    8687    }
     
    9596      }
    9697    }
    97 
    98     private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    99       // auch collectionreset gehört berücksichtigt
    100       // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
    101       //if (this.Count < minItemCount) {
    102       //  foreach (var item in e.Items) {
    103       //    if (this.Count >= minItemCount)
    104       //      break;
    105       //    this.Add(item);
    106       //  }
    107       //}
    108     }
    109 
    11098  }
    11199}
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/NullValueConfiguration.cs

    r8517 r8535  
    2828  [StorableClass]
    2929  public class NullValueConfiguration : ValueConfiguration {
    30 
    31     public NullValueConfiguration() {
    32       this.ActualValue = new ConstrainedValue(null, null, null, true);
    33       this.IsOptimizable = false;
    34     }
     30    #region Constructors and Cloning
    3531    [StorableConstructor]
    3632    protected NullValueConfiguration(bool deserializing) : base(deserializing) { }
     
    3834      : base(original, cloner) {
    3935    }
     36    public NullValueConfiguration()
     37      : base() {
     38      this.ActualValue = new ConstrainedValue(null, null, null, true);
     39      this.IsOptimizable = false;
     40    }
    4041    public override IDeepCloneable Clone(Cloner cloner) {
    4142      return new NullValueConfiguration(this, cloner);
    4243    }
     44    #endregion
    4345
    4446    public override string ToString() {
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/ParameterizedValueConfiguration.cs

    r8517 r8535  
    8383    [StorableConstructor]
    8484    protected ParameterizedValueConfiguration(bool deserializing) : base(deserializing) { }
    85     public ParameterizedValueConfiguration() {
     85    protected ParameterizedValueConfiguration(ParameterizedValueConfiguration original, Cloner cloner)
     86      : base(original, cloner) {
     87      this.discoverValidValues = original.discoverValidValues;
     88      this.ParameterConfigurations = cloner.Clone(original.parameterConfigurations);
     89    }
     90    public ParameterizedValueConfiguration()
     91      : base() {
    8692      this.ParameterConfigurations = new ItemList<IParameterConfiguration>();
    8793    }
     
    8995      : base(value, valueDataType) {
    9096      this.discoverValidValues = discoverValidValues;
    91     }
    92     protected ParameterizedValueConfiguration(ParameterizedValueConfiguration original, Cloner cloner)
    93       : base(original, cloner) {
    94       this.discoverValidValues = original.discoverValidValues;
    95       this.ParameterConfigurations = cloner.Clone(original.parameterConfigurations);
    9697    }
    9798    public override IDeepCloneable Clone(Cloner cloner) {
     
    107108          if (valueParameter != null) {
    108109            var pc = new ParameterConfiguration(valueParameter.Name, valueParameter, discoverValidValues);
     110            pc.CombinationsCountChanged += (sender, args) => OnCombinationsCountChanged();
    109111            this.parameterConfigurations.Add(pc);
    110112          }
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/RangeValueConfiguration.cs

    r8517 r8535  
    4646    [StorableConstructor]
    4747    protected RangeValueConfiguration(bool deserializing) : base(deserializing) { }
    48     public RangeValueConfiguration() {
    49 
    50     }
    5148    protected RangeValueConfiguration(RangeValueConfiguration original, Cloner cloner)
    5249      : base(original, cloner) {
     
    5451      RegisterRangeConstraintEvents();
    5552    }
     53    public RangeValueConfiguration() : base() { }
    5654    public RangeValueConfiguration(IItem value, Type valueDataType)
    5755      : base(value, valueDataType) {
     
    6866      }
    6967    }
    70     public override IDeepCloneable Clone(Cloner cloner) {
    71       return new RangeValueConfiguration(this, cloner);
    72     }
    7368    [StorableHook(HookType.AfterDeserialization)]
    7469    private void AfterDeserialization() {
    7570      RegisterRangeConstraintEvents();
    7671    }
     72    public override IDeepCloneable Clone(Cloner cloner) {
     73      return new RangeValueConfiguration(this, cloner);
     74    }
    7775    #endregion
    7876
    7977    private void RegisterRangeConstraintEvents() {
    80       if (this.RangeConstraint != null) this.RangeConstraint.ToStringChanged += new EventHandler(RangeConstraint_ToStringChanged);
     78      if (this.RangeConstraint != null) {
     79        this.RangeConstraint.ToStringChanged += new EventHandler(RangeConstraint_ToStringChanged);
     80        this.RangeConstraint.LowerBoundChanged += new EventHandler(RangeConstraintParametersChanged);
     81        this.RangeConstraint.UpperBoundChanged += new EventHandler(RangeConstraintParametersChanged);
     82        this.RangeConstraint.StepSizeChanged += new EventHandler(RangeConstraintParametersChanged);
     83      }
    8184    }
     85
    8286    private void DeregisterRangeConstraintEvents() {
    83       if (this.RangeConstraint != null) this.RangeConstraint.ToStringChanged -= new EventHandler(RangeConstraint_ToStringChanged);
     87      if (this.RangeConstraint != null) {
     88        this.RangeConstraint.ToStringChanged -= new EventHandler(RangeConstraint_ToStringChanged);
     89        this.RangeConstraint.LowerBoundChanged -= new EventHandler(RangeConstraintParametersChanged);
     90        this.RangeConstraint.UpperBoundChanged -= new EventHandler(RangeConstraintParametersChanged);
     91        this.RangeConstraint.StepSizeChanged -= new EventHandler(RangeConstraintParametersChanged);
     92      }
    8493    }
    8594
     
    119128      OnToStringChanged();
    120129    }
     130    private void RangeConstraintParametersChanged(object sender, EventArgs e) {
     131      OnCombinationsCountChanged();
     132    }
    121133    #endregion
    122134  }
  • branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/ValueConfiguration.cs

    r8524 r8535  
    6161          optimize = value;
    6262          OnOptimizeChanged();
     63          OnCombinationsCountChanged();
    6364          OnToStringChanged();
    6465        }
     
    117118    }
    118119    protected ValueConfiguration() : base() { }
    119     protected ValueConfiguration(IItem value, Type valueDataType) {
     120    protected ValueConfiguration(IItem value, Type valueDataType)
     121      : base() {
    120122      this.ActualValue = new ConstrainedValue(value, valueDataType, new ItemSet<IItem> { value }, false);
    121123      this.IsOptimizable = true;
     
    168170      if (handler != null) handler(this, EventArgs.Empty);
    169171    }
     172
     173    public event EventHandler CombinationsCountChanged;
     174    protected void OnCombinationsCountChanged() {
     175      var handler = CombinationsCountChanged;
     176      if (handler != null) handler(this, EventArgs.Empty);
     177    }
    170178    #endregion
    171179
Note: See TracChangeset for help on using the changeset viewer.