Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16731 was 16644, checked in by gkronber, 6 years ago

#2971: removed duplicate usings of HEAL.Attic and unnecessary usings

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