[16644] | 1 | using HeuristicLab.Common;
|
---|
[16426] | 2 | using HeuristicLab.Core;
|
---|
| 3 | using System;
|
---|
| 4 | using System.Collections.Generic;
|
---|
| 5 | using System.Linq;
|
---|
[16628] | 6 | using HEAL.Attic;
|
---|
[16426] | 7 |
|
---|
| 8 | namespace HeuristicLab.Problems.DataAnalysis.Implementation {
|
---|
| 9 | [Item("NamedIntervals", "Represents variables with their interval ranges.")]
|
---|
[16628] | 10 | [StorableType("230B4E4B-41E5-4D33-9BC3-E2DAADDCA5AE")]
|
---|
[16590] | 11 | public class NamedIntervals : Item {
|
---|
[16588] | 12 | Dictionary<string, Interval> variableIntervals = new Dictionary<string, Interval>();
|
---|
| 13 | public Dictionary<string, Interval> VariableIntervals => variableIntervals;
|
---|
[16426] | 14 |
|
---|
[16548] | 15 | [Storable(Name = "StorableIntervalInformation")]
|
---|
[16590] | 16 | private KeyValuePair<string, double[]>[] StorableIntervalInformation {
|
---|
[16548] | 17 | get {
|
---|
[16590] | 18 | var l = new List<KeyValuePair<string, double[]>>();
|
---|
[16548] | 19 | foreach (var varInt in variableIntervals)
|
---|
[16590] | 20 |
|
---|
| 21 | l.Add(new KeyValuePair<string, double[]>(varInt.Key,
|
---|
| 22 | new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound }));
|
---|
| 23 | return l.ToArray();
|
---|
[16548] | 24 | }
|
---|
| 25 |
|
---|
| 26 | set {
|
---|
| 27 | foreach (var varInt in value)
|
---|
[16590] | 28 | variableIntervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
|
---|
[16548] | 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[16590] | 32 | public NamedIntervals() : base() { }
|
---|
[16628] | 33 | [StorableConstructor]
|
---|
| 34 | protected NamedIntervals(StorableConstructorFlag _) : base(_) { }
|
---|
[16426] | 35 |
|
---|
[16548] | 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 |
|
---|
[16426] | 42 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 43 | return new NamedIntervals(this, cloner);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[16545] | 46 | public bool ReadOnly { get; }
|
---|
| 47 |
|
---|
[16426] | 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 | }
|
---|
[16590] | 65 |
|
---|
[16426] | 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|