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/ValueConfigurations
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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.