Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs @ 5207

Last change on this file since 5207 was 5207, checked in by cneumuel, 13 years ago

#1215

  • lots of memory-consumption improvements
  • validValues -> validTypes (this saves memory!)
  • changed manipulators; modifications are less significant, out-of-bound-values are resampled instead of set to lower or upper bound
  • changed the way a base-level algorithm gets executed -> introduced AlgorithmExecutor
File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.MetaOptimization {
10  // todo: check that at least 1 elements needs to be selected
11  // todo: control creatable item types
12  [StorableClass]
13  public class CheckedValueConfigurationCollection : CheckedItemCollection<IValueConfiguration>, ICheckedValueConfigurationCollection {
14    [Storable]
15    private int minItemCount = 1;
16    public int MinItemCount {
17      get { return minItemCount; }
18    }
19
20    [Storable]
21    protected IItemSet<IItem> validValues;
22    public IItemSet<IItem> ValidValues {
23      get { return validValues; }
24    }
25
26    public CheckedValueConfigurationCollection(IEnumerable<Type> validTypes) {
27      this.validValues = new ItemSet<IItem>();
28      foreach (Type t in validTypes) {
29        this.validValues.Add((IItem)Activator.CreateInstance(t));
30      }
31      RegisterEvents();
32    }
33    public CheckedValueConfigurationCollection() {
34      RegisterEvents();
35    }
36    [StorableConstructor]
37    protected CheckedValueConfigurationCollection(bool deserializing) : base(deserializing) {
38      RegisterEvents();
39    }
40    protected CheckedValueConfigurationCollection(CheckedValueConfigurationCollection original, Cloner cloner) : base(original, cloner) {
41      this.minItemCount = original.MinItemCount;
42      this.validValues = original.validValues;
43      RegisterEvents();
44    }
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new CheckedValueConfigurationCollection(this, cloner);
47    }
48    [StorableHook(HookType.AfterDeserialization)]
49    private void AfterDeserialization() {
50      RegisterEvents();
51    }
52
53    private void RegisterEvents() {
54      this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
55    }
56    private void DeregisterEvents() {
57      this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved);
58    }
59
60    private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) {
61      // auch collectionreset gehört berücksichtigt
62      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
63      //if (this.Count < minItemCount) {
64      //  foreach (var item in e.Items) {
65      //    if (this.Count >= minItemCount)
66      //      break;
67      //    this.Add(item);
68      //  }
69      //}
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.