1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Linq;
|
---|
6 | using HEAL.Attic;
|
---|
7 |
|
---|
8 | namespace 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 |
|
---|