#region License Information /* HeuristicLab * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; namespace HeuristicLab.Problems.DataAnalysis { [Item("IntervalCollection", "Represents variables with their interval ranges.")] [StorableType("230B4E4B-41E5-4D33-9BC3-E2DAADDCA5AE")] public class IntervalCollection : Item { public static new System.Drawing.Image StaticItemImage { get => HeuristicLab.Common.Resources.VSImageLibrary.Object; } private IDictionary VariableIntervals { get; } = new Dictionary(); [Storable(Name = "StorableIntervalInformation")] private KeyValuePair[] StorableIntervalInformation { get { var l = new List>(); foreach (var varInt in VariableIntervals) l.Add(new KeyValuePair(varInt.Key, new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound })); return l.ToArray(); } set { foreach (var varInt in value) VariableIntervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1])); } } public IntervalCollection() : base() { } [StorableConstructor] protected IntervalCollection(StorableConstructorFlag _) : base(_) { } protected IntervalCollection(IntervalCollection original, Cloner cloner) : base(original, cloner) { foreach (var keyValuePair in original.VariableIntervals) { VariableIntervals.Add(keyValuePair.Key, new Interval(keyValuePair.Value.LowerBound, keyValuePair.Value.UpperBound)); } } public override IDeepCloneable Clone(Cloner cloner) { return new IntervalCollection(this, cloner); } public IntervalCollection(IDictionary variableIntervals) { this.VariableIntervals = variableIntervals; } public Interval GetInterval(string variable) { if (!VariableIntervals.ContainsKey(variable)) throw new ArgumentException($"The given variable:{ variable } is not present!"); return VariableIntervals[variable]; } public void SetInterval(string key, Interval interval) { VariableIntervals[key] = interval; } public void AddInterval(string key, Interval interval) { VariableIntervals.Add(key, interval); } public void DeleteInterval(string key) { VariableIntervals.Remove(key); } public IDictionary GetIntervals() { return VariableIntervals; } } }