Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/21 14:00:36 (4 years ago)
Author:
gkronber
Message:

#3073: intermediate comment while refactoring the branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17631 r17887  
    3434      get => HeuristicLab.Common.Resources.VSImageLibrary.Object;
    3535    }
    36     private IDictionary<string, Interval> intervals { get; } = new Dictionary<string, Interval>();
    3736
    38     [Storable(Name = "StorableIntervalInformation")]
     37    //[Storable]
     38    private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>();
     39
     40    [Storable(OldName = "StorableIntervalInformation")]
    3941    private KeyValuePair<string, double[]>[] StorableIntervalInformation {
     42      set {
     43        foreach (var varInt in value)
     44          intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     45      }
     46    }
     47
     48    [Storable]
     49    private object[] StorableIntervals {
    4050      get {
    41         var l = new List<KeyValuePair<string, double[]>>();
    42         foreach (var varInt in intervals)
     51        var names = intervals.Keys.ToArray();
     52        var lowerBounds = intervals.Values.Select(i => i.LowerBound).ToArray();
     53        var upperBounds = intervals.Values.Select(i => i.UpperBound).ToArray();
    4354
    44           l.Add(new KeyValuePair<string, double[]>(varInt.Key,
    45             new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound }));
    46         return l.ToArray();
     55        return new object[] { names, lowerBounds, upperBounds };
    4756      }
    4857
    4958      set {
    50         foreach (var varInt in value)
    51           intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     59        var names = (string[])value[0];
     60        var lowerBounds = (double[])value[1];
     61        var upperBounds = (double[])value[2];
     62
     63        for (int i = 0; i < names.Length; i++) {
     64          intervals.Add(names[i], new Interval(lowerBounds[i], upperBounds[i]));
     65        }
    5266      }
    5367    }
     
    8094    public void SetInterval(string identifier, Interval interval) {
    8195      intervals[identifier] = interval;
     96      RaiseChanged();
    8297    }
    8398
    8499    public void AddInterval(string identifier, Interval interval) {
    85100      intervals.Add(identifier, interval);
     101      RaiseChanged();
    86102    }
    87103
    88104    public void DeleteInterval(string identifier) {
    89105      intervals.Remove(identifier);
     106      RaiseChanged();
    90107    }
    91108
     
    102119        yield return Tuple.Create(variableInterval.Key, variableInterval.Value);
    103120    }
     121
     122    public event EventHandler Changed;
     123    private void RaiseChanged() {
     124      OnChanged();
     125      var handler = Changed;
     126      if (handler != null)
     127        handler(this, EventArgs.Empty);
     128    }
     129
     130    protected virtual void OnChanged() {  }
    104131  }
    105132}
Note: See TracChangeset for help on using the changeset viewer.