Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/NamedIntervals.cs @ 16548

Last change on this file since 16548 was 16548, checked in by chaider, 5 years ago

#2971

  • Removed Storable from Intervals
  • Changed copy constructor from NamedIntervals class
File size: 2.3 KB
Line 
1using HeuristicLab.Collections;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5using System;
6using System.Collections.Generic;
7using System.Drawing;
8using System.Linq;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace HeuristicLab.Problems.DataAnalysis.Implementation {
13  [Item("NamedIntervals", "Represents variables with their interval ranges.")]
14  [StorableClass]
15  public class NamedIntervals : Item {   
16    ObservableDictionary<string, Interval> variableIntervals = new ObservableDictionary<string, Interval>();
17    public ObservableDictionary<string, Interval> VariableIntervals {
18      get { return variableIntervals; }
19    }
20
21    [Storable(Name = "StorableIntervalInformation")]
22    private IEnumerable<Tuple<string, double, double>> StorableIntervalInformation {
23      get {
24        foreach (var varInt in variableIntervals)
25          yield return Tuple.Create(varInt.Key, varInt.Value.LowerBound, varInt.Value.UpperBound);
26      }
27
28      set {
29        foreach (var varInt in value)
30          variableIntervals.Add(varInt.Item1,new Interval(varInt.Item2,varInt.Item3));
31      }
32    }
33
34    public NamedIntervals() : base(){}
35    protected NamedIntervals(bool deserializing) : base(deserializing) { }
36
37    protected NamedIntervals(NamedIntervals original, Cloner cloner) : base(original, cloner) {
38      foreach (var keyValuePair in original.VariableIntervals) {
39        variableIntervals.Add(keyValuePair.Key, keyValuePair.Value);
40      }
41    }
42
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new NamedIntervals(this, cloner);
45    }
46
47    public bool ReadOnly { get; }
48
49    public bool InsertMany(IEnumerable<KeyValuePair<string, Interval>> entries) {
50      if (entries == null) throw new ArgumentNullException("The given dataset is null.");
51      if (entries.Count() != 0) {
52        foreach (var entry in entries) {
53          if (variableIntervals.ContainsKey(entry.Key))
54            variableIntervals[entry.Key] = entry.Value;
55          else
56            variableIntervals.Add(entry.Key, entry.Value);
57        }
58      }
59      return true;
60    }
61
62    public bool Add(string key, Interval value) {
63      variableIntervals[key] = value;
64      return true;
65    }
66   
67  }
68}
69
Note: See TracBrowser for help on using the repository browser.