[16426] | 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]
|
---|
[16548] | 15 | public class NamedIntervals : Item {
|
---|
[16588] | 16 | Dictionary<string, Interval> variableIntervals = new Dictionary<string, Interval>();
|
---|
| 17 | public Dictionary<string, Interval> VariableIntervals => variableIntervals;
|
---|
[16426] | 18 |
|
---|
[16548] | 19 | [Storable(Name = "StorableIntervalInformation")]
|
---|
| 20 | private IEnumerable<Tuple<string, double, double>> StorableIntervalInformation {
|
---|
| 21 | get {
|
---|
| 22 | foreach (var varInt in variableIntervals)
|
---|
| 23 | yield return Tuple.Create(varInt.Key, varInt.Value.LowerBound, varInt.Value.UpperBound);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | set {
|
---|
| 27 | foreach (var varInt in value)
|
---|
| 28 | variableIntervals.Add(varInt.Item1,new Interval(varInt.Item2,varInt.Item3));
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[16426] | 32 | public NamedIntervals() : base(){}
|
---|
| 33 | protected NamedIntervals(bool deserializing) : base(deserializing) { }
|
---|
| 34 |
|
---|
[16548] | 35 | protected NamedIntervals(NamedIntervals original, Cloner cloner) : base(original, cloner) {
|
---|
| 36 | foreach (var keyValuePair in original.VariableIntervals) {
|
---|
| 37 | variableIntervals.Add(keyValuePair.Key, keyValuePair.Value);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[16426] | 41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 42 | return new NamedIntervals(this, cloner);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[16545] | 45 | public bool ReadOnly { get; }
|
---|
| 46 |
|
---|
[16426] | 47 | public bool InsertMany(IEnumerable<KeyValuePair<string, Interval>> entries) {
|
---|
| 48 | if (entries == null) throw new ArgumentNullException("The given dataset is null.");
|
---|
| 49 | if (entries.Count() != 0) {
|
---|
| 50 | foreach (var entry in entries) {
|
---|
| 51 | if (variableIntervals.ContainsKey(entry.Key))
|
---|
| 52 | variableIntervals[entry.Key] = entry.Value;
|
---|
| 53 | else
|
---|
| 54 | variableIntervals.Add(entry.Key, entry.Value);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | return true;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public bool Add(string key, Interval value) {
|
---|
| 61 | variableIntervals[key] = value;
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|