Free cookie consent management tool by TermsFeed Policy Generator

source: branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/RecursiveDataItem.cs @ 12499

Last change on this file since 12499 was 12498, checked in by pfleck, 9 years ago

#2379

  • Adapted parts of categorical mapping from RunCollectionBubbleChart.
  • Small changes and optimizations.
  • Updated ALPS sample.
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Collections;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Optimization.BubbleChart {
33  [Item("RecursiveDataItem", "")]
34  [StorableClass]
35  public class RecursiveDataItem : NamedItem, IEnumerable<RecursiveDataItem>, IEnumerable<KeyValuePair<string, IItem>> {
36    [Storable]
37    private readonly ObservableDictionary<string, IItem> data;
38    [Storable]
39    private readonly ObservableList<RecursiveDataItem> children;
40
41    public ObservableDictionary<string, IItem> Data { get { return data; } }
42    public ObservableList<RecursiveDataItem> Children { get { return children; } }
43
44    [StorableConstructor]
45    private RecursiveDataItem(bool deserializing) : base(deserializing) { }
46    private RecursiveDataItem(RecursiveDataItem original, Cloner cloner)
47      : base(original, cloner) {
48      data = new ObservableDictionary<string, IItem>(original.Data.ToDictionary(x => x.Key, x => cloner.Clone(x.Value)));
49      children = new ObservableList<RecursiveDataItem>(original.Children.Select(x => cloner.Clone(x)));
50    }
51    public RecursiveDataItem()
52      : base() {
53      data = new ObservableDictionary<string, IItem>();
54      children = new ObservableList<RecursiveDataItem>();
55    }
56    public RecursiveDataItem(string name)
57      : base(name) {
58      data = new ObservableDictionary<string, IItem>();
59      children = new ObservableList<RecursiveDataItem>();
60    }
61
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new RecursiveDataItem(this, cloner);
64    }
65
66    IEnumerator<KeyValuePair<string, IItem>> IEnumerable<KeyValuePair<String, IItem>>.GetEnumerator() {
67      return data.GetEnumerator();
68    }
69    IEnumerator<RecursiveDataItem> IEnumerable<RecursiveDataItem>.GetEnumerator() {
70      return children.GetEnumerator();
71    }
72    IEnumerator IEnumerable.GetEnumerator() {
73      return data.GetEnumerator();
74    }
75
76    public void Add(string key, IItem item) {
77      data.Add(key, item);
78    }
79    public void Add(RecursiveDataItem child) {
80      children.Add(child);
81    }
82
83  }
84
85  static class test {
86    static test() {
87      var run = new RecursiveDataItem("Run") {
88          {"CurrentBestQuality", new DoubleValue(100)},
89          {"Selector", new StringValue("TournamentSelector")},
90          new RecursiveDataItem("Layers") {
91            new RecursiveDataItem("Layer0") {
92               {"CurrentBestQuality", new DoubleValue(10)}
93            },
94            new RecursiveDataItem("Layer1") {
95               {"CurrentBestQuality", new DoubleValue(50)}
96            },
97            new RecursiveDataItem("Layer2") {
98               {"CurrentBestQuality", new DoubleValue(100)}
99            }
100          }
101      };
102      //var run = new RecursiveDataItem(
103      //  name: "Run",
104      //  data: new Dictionary<string, IItem> {
105      //    {"CurrentBestQuality", new DoubleValue(100)},
106      //    {"Selector", new StringValue("TournamentSelector")}, {
107      //      "Layers", new RecursiveDataItem("Layers") {
108      //        new RecursiveDataItem(
109      //          name: "Layer0",
110      //          data: new Dictionary<string, IItem> {
111      //            {"CurrentBestQuality", new DoubleValue(10)}
112      //          }
113      //        ),
114      //        new RecursiveDataItem(
115      //          name: "Layer1",
116      //          data: new Dictionary<string, IItem> {
117      //            {"CurrentBestQuality", new DoubleValue(50)}
118      //          }
119      //        ),
120      //        new RecursiveDataItem(
121      //          name: "Layer2",
122      //          data: new Dictionary<string, IItem> {
123      //            {"CurrentBestQuality", new DoubleValue(100)}
124      //          }
125      //        )
126      //      }
127      //    }
128      //  }
129      //);
130
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.