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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Collections;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Data;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 |
|
---|
32 | namespace 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 |
|
---|
80 | public void Add(string key, double value) {
|
---|
81 | data.Add(key, new DoubleValue(value));
|
---|
82 | }
|
---|
83 | public void Add(string key, int value) {
|
---|
84 | data.Add(key, new IntValue(value));
|
---|
85 | }
|
---|
86 | public void Add(string key, string value) {
|
---|
87 | data.Add(key, new StringValue(value));
|
---|
88 | }
|
---|
89 | public void Add(string key, DateTime value) {
|
---|
90 | data.Add(key, new DateTimeValue(value));
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | public void Add(RecursiveDataItem child) {
|
---|
95 | children.Add(child);
|
---|
96 | }
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 | static class test {
|
---|
101 | static test() {
|
---|
102 | var run = new RecursiveDataItem("Run") {
|
---|
103 | {"CurrentBestQuality", new DoubleValue(100)},
|
---|
104 | {"Selector", new StringValue("TournamentSelector")},
|
---|
105 | new RecursiveDataItem("Layers") {
|
---|
106 | new RecursiveDataItem("Layer0") {
|
---|
107 | {"CurrentBestQuality", new DoubleValue(10)}
|
---|
108 | },
|
---|
109 | new RecursiveDataItem("Layer1") {
|
---|
110 | {"CurrentBestQuality", new DoubleValue(50)}
|
---|
111 | },
|
---|
112 | new RecursiveDataItem("Layer2") {
|
---|
113 | {"CurrentBestQuality", new DoubleValue(100)}
|
---|
114 | }
|
---|
115 | }
|
---|
116 | };
|
---|
117 | //var run = new RecursiveDataItem(
|
---|
118 | // name: "Run",
|
---|
119 | // data: new Dictionary<string, IItem> {
|
---|
120 | // {"CurrentBestQuality", new DoubleValue(100)},
|
---|
121 | // {"Selector", new StringValue("TournamentSelector")}, {
|
---|
122 | // "Layers", new RecursiveDataItem("Layers") {
|
---|
123 | // new RecursiveDataItem(
|
---|
124 | // name: "Layer0",
|
---|
125 | // data: new Dictionary<string, IItem> {
|
---|
126 | // {"CurrentBestQuality", new DoubleValue(10)}
|
---|
127 | // }
|
---|
128 | // ),
|
---|
129 | // new RecursiveDataItem(
|
---|
130 | // name: "Layer1",
|
---|
131 | // data: new Dictionary<string, IItem> {
|
---|
132 | // {"CurrentBestQuality", new DoubleValue(50)}
|
---|
133 | // }
|
---|
134 | // ),
|
---|
135 | // new RecursiveDataItem(
|
---|
136 | // name: "Layer2",
|
---|
137 | // data: new Dictionary<string, IItem> {
|
---|
138 | // {"CurrentBestQuality", new DoubleValue(100)}
|
---|
139 | // }
|
---|
140 | // )
|
---|
141 | // }
|
---|
142 | // }
|
---|
143 | // }
|
---|
144 | //);
|
---|
145 |
|
---|
146 | }
|
---|
147 | }
|
---|
148 | } |
---|