Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • renamed RunsAnalyzer to SolutionCacheAnalyzer
  • only most recent results will stay in cache to avoid memory problems
  • some minor tweaks and bugfixes
File size: 3.2 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(IItemSet<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.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
53      this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
54    }
55
56    private void DeregisterEvents() {
57      this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
58      this.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
59    }
60
61    void CheckedValueConfigurationList_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
62      foreach (var item in e.Items) {
63        if(this.Where(x => x.ItemName == item.Value.ItemName).Count() > 0) {
64          int maxNumber = this.Where(x => x.ItemName == item.Value.ItemName).Select(x => x.Number).Max();
65          item.Value.Number = maxNumber + 1;
66        }
67      }
68    }
69
70    private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
71      // auch collectionreset gehört berücksichtigt
72      // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt
73      //if (this.Count < minItemCount) {
74      //  foreach (var item in e.Items) {
75      //    if (this.Count >= minItemCount)
76      //      break;
77      //    this.Add(item);
78      //  }
79      //}
80    }
81
82  }
83}
Note: See TracBrowser for help on using the repository browser.