Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11718


Ignore:
Timestamp:
12/23/14 10:45:20 (9 years ago)
Author:
ehopf
Message:

#2278: Replaced the collect result values method in the ResultCollection-class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Classification-Extensions/HeuristicLab.Optimization/3.3/ResultCollection.cs

    r11689 r11718  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using System.Linq;
    2627
    27 namespace HeuristicLab.Optimization {
     28namespace HeuristicLab.Optimization {   
    2829  [StorableClass]
    2930  [Item("ResultCollection", "Represents a collection of results.")]
     
    4546    }
    4647
    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); 
    5250    }
    5351
    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);
    6062        }
    6163      }
    6264    }
     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
    6377  }
    6478}
Note: See TracChangeset for help on using the changeset viewer.