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/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    }
Note: See TracChangeset for help on using the changeset viewer.