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
RevLine 
[5112]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[5277]8using HeuristicLab.Collections;
[5112]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]
[5277]14  public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList {
[5112]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
[5313]27    public CheckedValueConfigurationList(IItemSet<IItem> validValues) {
[5231]28      this.validValues = validValues;
[5112]29      RegisterEvents();
30    }
[5277]31    public CheckedValueConfigurationList() {
[5112]32      RegisterEvents();
33    }
34    [StorableConstructor]
[5277]35    protected CheckedValueConfigurationList(bool deserializing) : base(deserializing) {
[5112]36      RegisterEvents();
37    }
[5277]38    protected CheckedValueConfigurationList(CheckedValueConfigurationList original, Cloner cloner) : base(original, cloner) {
[5112]39      this.minItemCount = original.MinItemCount;
40      this.validValues = original.validValues;
41      RegisterEvents();
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
[5277]44      return new CheckedValueConfigurationList(this, cloner);
[5112]45    }
46    [StorableHook(HookType.AfterDeserialization)]
47    private void AfterDeserialization() {
48      RegisterEvents();
49    }
50
51    private void RegisterEvents() {
[5359]52      this.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
[5277]53      this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
[5112]54    }
[5277]55
[5112]56    private void DeregisterEvents() {
[5277]57      this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);
[5359]58      this.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded);
[5112]59    }
60
[5359]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
[5277]70    private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
[5112]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    }
[5277]81
[5112]82  }
83}
Note: See TracBrowser for help on using the repository browser.