1 | using HeuristicLab.Collections;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
5 | using System;
|
---|
6 | using System.Collections.Generic;
|
---|
7 | using System.Drawing;
|
---|
8 | using System.Linq;
|
---|
9 | using System.Text;
|
---|
10 | using System.Threading.Tasks;
|
---|
11 |
|
---|
12 | namespace 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 |
|
---|