#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 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;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Optimization.BubbleChart {
[Item("RecursiveDataItem", "")]
[StorableClass]
public class RecursiveDataItem : NamedItem, IEnumerable, IEnumerable> {
[Storable]
private readonly ObservableDictionary data;
[Storable]
private readonly ObservableList children;
public ObservableDictionary Data { get { return data; } }
public ObservableList Children { get { return children; } }
[StorableConstructor]
private RecursiveDataItem(bool deserializing) : base(deserializing) { }
private RecursiveDataItem(RecursiveDataItem original, Cloner cloner)
: base(original, cloner) {
data = new ObservableDictionary(original.Data.ToDictionary(x => x.Key, x => cloner.Clone(x.Value)));
children = new ObservableList(original.Children.Select(x => cloner.Clone(x)));
}
public RecursiveDataItem()
: base() {
data = new ObservableDictionary();
children = new ObservableList();
}
public RecursiveDataItem(string name)
: base(name) {
data = new ObservableDictionary();
children = new ObservableList();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new RecursiveDataItem(this, cloner);
}
IEnumerator> IEnumerable>.GetEnumerator() {
return data.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return children.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return data.GetEnumerator();
}
public void Add(string key, IItem item) {
data.Add(key, item);
}
public void Add(string key, double value) {
data.Add(key, new DoubleValue(value));
}
public void Add(string key, int value) {
data.Add(key, new IntValue(value));
}
public void Add(string key, string value) {
data.Add(key, new StringValue(value));
}
public void Add(string key, DateTime value) {
data.Add(key, new DateTimeValue(value));
}
public void Add(RecursiveDataItem child) {
children.Add(child);
}
}
static class test {
static test() {
var run = new RecursiveDataItem("Run") {
{"CurrentBestQuality", new DoubleValue(100)},
{"Selector", new StringValue("TournamentSelector")},
new RecursiveDataItem("Layers") {
new RecursiveDataItem("Layer0") {
{"CurrentBestQuality", new DoubleValue(10)}
},
new RecursiveDataItem("Layer1") {
{"CurrentBestQuality", new DoubleValue(50)}
},
new RecursiveDataItem("Layer2") {
{"CurrentBestQuality", new DoubleValue(100)}
}
}
};
//var run = new RecursiveDataItem(
// name: "Run",
// data: new Dictionary {
// {"CurrentBestQuality", new DoubleValue(100)},
// {"Selector", new StringValue("TournamentSelector")}, {
// "Layers", new RecursiveDataItem("Layers") {
// new RecursiveDataItem(
// name: "Layer0",
// data: new Dictionary {
// {"CurrentBestQuality", new DoubleValue(10)}
// }
// ),
// new RecursiveDataItem(
// name: "Layer1",
// data: new Dictionary {
// {"CurrentBestQuality", new DoubleValue(50)}
// }
// ),
// new RecursiveDataItem(
// name: "Layer2",
// data: new Dictionary {
// {"CurrentBestQuality", new DoubleValue(100)}
// }
// )
// }
// }
// }
//);
}
}
}