Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • implemented crossover and manipulator operators for int and double values
File size: 2.5 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;
8using HeuristicLab.Collections;
9
10namespace HeuristicLab.Problems.MetaOptimization {
11  // todo: check that at least 1 elements needs to be selected
12  // todo: control creatable item types
13  [StorableClass]
14  public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList {
15    [Storable]
16    private int minItemCount = 1;
17    public int MinItemCount {
18      get { return minItemCount; }
19    }
20
21    [Storable]
22    protected IItemSet<IItem> validValues;
23    public IItemSet<IItem> ValidValues {
24      get { return validValues; }
25    }
26
27    public CheckedValueConfigurationList(ItemSet<IItem> validValues) {
28      this.validValues = validValues;
29      RegisterEvents();
30    }
31    public CheckedValueConfigurationList() {
32      RegisterEvents();
33    }
34    [StorableConstructor]
35    protected CheckedValueConfigurationList(bool deserializing) : base(deserializing) {
36      RegisterEvents();
37    }
38    protected CheckedValueConfigurationList(CheckedValueConfigurationList original, Cloner cloner) : base(original, cloner) {
39      this.minItemCount = original.MinItemCount;
40      this.validValues = original.validValues;
41      RegisterEvents();
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new CheckedValueConfigurationList(this, cloner);
45    }
46    [StorableHook(HookType.AfterDeserialization)]
47    private void AfterDeserialization() {
48      RegisterEvents();
49    }
50
51    private void RegisterEvents() {
52      this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
53    }
54
55    private void DeregisterEvents() {
56      this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
57    }
58
59    private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
60      // auch collectionreset gehört berücksichtigt
61      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
62      //if (this.Count < minItemCount) {
63      //  foreach (var item in e.Items) {
64      //    if (this.Count >= minItemCount)
65      //      break;
66      //    this.Add(item);
67      //  }
68      //}
69    }
70
71  }
72}
Note: See TracBrowser for help on using the repository browser.