Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/11 14:50:59 (14 years ago)
Author:
svonolfe
Message:

Implemented various changes as proposed by vdorfer and swinkler (#1392)

  • Collecting the successful values now works when elites are enabled
  • The initial iteration (0) is not collected
  • The DataTable now has a Name
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SuccessProgressAnalysis/SuccessProgressAnalyzer.cs

    r5379 r5492  
    4040  [StorableClass]
    4141  public sealed class SuccessProgressAnalyzer: SingleSuccessorOperator, IAnalyzer {
    42     public ScopeTreeLookupParameter<BoolValue> SuccessfulOffspring {
    43       get { return (ScopeTreeLookupParameter<BoolValue>)Parameters["SuccessfulOffspring"]; }
     42    public ValueParameter<StringValue> SuccessfulOffspringFlag {
     43      get { return (ValueParameter<StringValue>)Parameters["SuccessfulOffspringFlag"]; }
    4444    }
    4545
     
    6464    public SuccessProgressAnalyzer()
    6565      : base() {
    66         Parameters.Add(new ScopeTreeLookupParameter<BoolValue>("SuccessfulOffspring", "Indicates if the individual was successful."));
     66        Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", "Indicates if the individual was successful.", new StringValue("SuccessfulOffspring")));
    6767        Parameters.Add(new ValueParameter<ItemCollection<StringValue>>("CollectedValues", "The values that should be collected.", new ItemCollection<StringValue>()));
    6868        Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the succedd progress analysis results should be stored."));
     
    7373      ResultCollection results = ResultsParameter.ActualValue;
    7474     
    75       ItemArray<BoolValue> successfulOffspring = SuccessfulOffspring.ActualValue;
    7675      ItemCollection<StringValue> collectedValues = CollectedValues.Value;
    77 
    78       int successfulCount = successfulOffspring.Where(s => s.Value).Count();
    79       if (successfulCount > 0 && collectedValues.Count > 0 && successfulOffspring.Length == ExecutionContext.Scope.SubScopes.Count) {
    8076        foreach (StringValue collected in collectedValues) {
    8177          Dictionary<String, int> counts = new Dictionary<String, int>();
    8278          for (int i = 0; i < ExecutionContext.Scope.SubScopes.Count; i++) {
    8379            IScope child = ExecutionContext.Scope.SubScopes[i];
     80            string successfulOffspringFlag = SuccessfulOffspringFlag.Value.Value;
     81            if (child.Variables.ContainsKey(collected.Value) &&
     82                child.Variables.ContainsKey(successfulOffspringFlag) &&
     83                (child.Variables[successfulOffspringFlag].Value is BoolValue) &&
     84                (child.Variables[successfulOffspringFlag].Value as BoolValue).Value) {
     85              String key = child.Variables[collected.Value].Value.ToString();
    8486
    85             if (successfulOffspring[i].Value && child.Variables.ContainsKey(collected.Value)) {
    86               String key = child.Variables[collected.Value].Value.ToString();
    87  
    8887              if (!counts.ContainsKey(key))
    89                counts.Add(key, 1);
     88                counts.Add(key, 1);
    9089              else
    91                counts[key]++;
     90                counts[key]++;
    9291            }
    9392          }
     
    9796          if (!results.ContainsKey(resultKey)) {
    9897            successProgressAnalysis = new DataTable();
     98            successProgressAnalysis.Name = "Success Progress Analysis";
    9999            results.Add(new Result(resultKey, successProgressAnalysis));
    100100          } else {
    101101            successProgressAnalysis = results[resultKey].Value as DataTable;
     102          }
     103
     104          int successfulCount = 0;
     105          foreach (string key in counts.Keys) {
     106            successfulCount += counts[key];
    102107          }
    103108
     
    108113              int iterations = Generations.ActualValue.Value;
    109114
    110               for (int i = 0; i < iterations; i++)
     115              for (int i = 1; i < iterations; i++)
    111116                row.Values.Add(0);
    112117
     
    124129          }
    125130        } 
    126       }
    127131
    128132      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.