Changeset 11718
- Timestamp:
- 12/23/14 10:45:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Classification-Extensions/HeuristicLab.Optimization/3.3/ResultCollection.cs
r11689 r11718 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using System.Linq; 26 27 27 namespace HeuristicLab.Optimization { 28 namespace HeuristicLab.Optimization { 28 29 [StorableClass] 29 30 [Item("ResultCollection", "Represents a collection of results.")] … … 45 46 } 46 47 47 public void CollectResultValues(IDictionary<string, IItem> values) { 48 CollectResultsRecursively("", this, values); 49 } 50 public void CollectResultValues(IDictionary<string, IItem> values, string resultsRootName) { 51 CollectResultsRecursively(resultsRootName, this, values); 48 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 49 CollectResultValues(values, string.Empty); 52 50 } 53 51 54 protected void CollectResultsRecursively(string path, ResultCollection results, IDictionary<string, IItem> values) { 55 foreach (IResult result in results) { 56 values.Add(path + result.Name, result.Value); 57 ResultCollection childCollection = result.Value as ResultCollection; 58 if (childCollection != null) { 59 CollectResultsRecursively(path + result.Name + ".", childCollection, values); 52 public virtual void CollectResultValues(IDictionary<string, IItem> values, string rootPath) { 53 foreach (IResult result in this) { 54 var children = GetCollectedResults(result); 55 string path = string.Empty; 56 if (!string.IsNullOrWhiteSpace(rootPath)) 57 path = rootPath + "."; 58 foreach (var c in children) { 59 if (string.IsNullOrEmpty(c.Key)) 60 values.Add(path + result.Name, c.Value); 61 else values.Add(path + result.Name + "." + c.Key, c.Value); 60 62 } 61 63 } 62 64 } 65 66 protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedResults(IResult result) { 67 if (result.Value == null) yield break; 68 yield return new KeyValuePair<string, IItem>(string.Empty, result.Value); 69 var resultCollection = result.Value as ResultCollection; 70 if (resultCollection != null) { 71 var children = new Dictionary<string, IItem>(); 72 resultCollection.CollectResultValues(children); 73 foreach (var child in children) yield return child; 74 } 75 } 76 63 77 } 64 78 }
Note: See TracChangeset
for help on using the changeset viewer.