Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/12/11 03:39:04 (13 years ago)
Author:
swagner
Message:

Disabled run-time intensive analyzers by default (#1584)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SuccessfulOffspringAnalysis/SuccessfulOffspringAnalyzer.cs

    r5725 r7172  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Text;
     25using HeuristicLab.Analysis;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Data;
    2829using HeuristicLab.Operators;
    2930using HeuristicLab.Optimization;
    30 using HeuristicLab.Common;
    3131using HeuristicLab.Parameters;
    32 using HeuristicLab.Data;
    33 using HeuristicLab.Analysis;
     32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3433
    3534namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
     
    4039  [StorableClass]
    4140  public sealed class SuccessfulOffspringAnalyzer : SingleSuccessorOperator, IAnalyzer {
     41    public bool EnabledByDefault {
     42      get { return false; }
     43    }
     44
    4245    public ValueParameter<StringValue> SuccessfulOffspringFlagParameter {
    4346      get { return (ValueParameter<StringValue>)Parameters["SuccessfulOffspringFlag"]; }
     
    5356
    5457    public LookupParameter<ResultCollection> SuccessfulOffspringAnalysisParameter {
    55       get { return (LookupParameter<ResultCollection>)Parameters["SuccessfulOffspringAnalysis"];  }
     58      get { return (LookupParameter<ResultCollection>)Parameters["SuccessfulOffspringAnalysis"]; }
    5659    }
    5760
     
    6366      get { return (ValueParameter<IntValue>)Parameters["Depth"]; }
    6467    }
    65    
     68
    6669    public override IDeepCloneable Clone(Cloner cloner) {
    6770      return new SuccessfulOffspringAnalyzer(this, cloner);
    68     }   
     71    }
    6972    [StorableConstructor]
    7073    private SuccessfulOffspringAnalyzer(bool deserializing) : base(deserializing) { }
     
    7275    public SuccessfulOffspringAnalyzer()
    7376      : base() {
    74         Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", "The name of the flag which indicates if the individual was successful.", new StringValue("SuccessfulOffspring")));
    75         Parameters.Add(new ValueParameter<ItemCollection<StringValue>>("CollectedValues", "The properties of the successful offspring that should be collected.", new ItemCollection<StringValue>()));
    76         Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the succedd progress analysis results should be stored."));
    77         Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations.")); 
    78         Parameters.Add(new LookupParameter<ResultCollection>("SuccessfulOffspringAnalysis", "The successful offspring analysis which is created."));
    79         Parameters.Add(new ValueParameter<IntValue>("Depth", "The depth of the individuals in the scope tree.", new IntValue(1)));
     77      Parameters.Add(new ValueParameter<StringValue>("SuccessfulOffspringFlag", "The name of the flag which indicates if the individual was successful.", new StringValue("SuccessfulOffspring")));
     78      Parameters.Add(new ValueParameter<ItemCollection<StringValue>>("CollectedValues", "The properties of the successful offspring that should be collected.", new ItemCollection<StringValue>()));
     79      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the succedd progress analysis results should be stored."));
     80      Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
     81      Parameters.Add(new LookupParameter<ResultCollection>("SuccessfulOffspringAnalysis", "The successful offspring analysis which is created."));
     82      Parameters.Add(new ValueParameter<IntValue>("Depth", "The depth of the individuals in the scope tree.", new IntValue(1)));
    8083    }
    8184
     
    8891
    8992      ItemCollection<StringValue> collectedValues = CollectedValuesParameter.Value;
    90         foreach (StringValue collected in collectedValues) {
    91           //collect the values of the successful offspring
    92           Dictionary<String, int> counts = new Dictionary<String, int>();
    93           for (int i = 0; i < scopes.Count; i++) {
    94             IScope child = scopes[i];
    95             string successfulOffspringFlag = SuccessfulOffspringFlagParameter.Value.Value;
    96             if (child.Variables.ContainsKey(collected.Value) &&
    97                 child.Variables.ContainsKey(successfulOffspringFlag) &&
    98                 (child.Variables[successfulOffspringFlag].Value is BoolValue) &&
    99                 (child.Variables[successfulOffspringFlag].Value as BoolValue).Value) {
    100               String key = child.Variables[collected.Value].Value.ToString();
     93      foreach (StringValue collected in collectedValues) {
     94        //collect the values of the successful offspring
     95        Dictionary<String, int> counts = new Dictionary<String, int>();
     96        for (int i = 0; i < scopes.Count; i++) {
     97          IScope child = scopes[i];
     98          string successfulOffspringFlag = SuccessfulOffspringFlagParameter.Value.Value;
     99          if (child.Variables.ContainsKey(collected.Value) &&
     100              child.Variables.ContainsKey(successfulOffspringFlag) &&
     101              (child.Variables[successfulOffspringFlag].Value is BoolValue) &&
     102              (child.Variables[successfulOffspringFlag].Value as BoolValue).Value) {
     103            String key = child.Variables[collected.Value].Value.ToString();
    101104
    102               if (!counts.ContainsKey(key))
    103                 counts.Add(key, 1);
    104               else
    105                 counts[key]++;
    106             }
     105            if (!counts.ContainsKey(key))
     106              counts.Add(key, 1);
     107            else
     108              counts[key]++;
     109          }
     110        }
     111
     112        //create a data table containing the collected values
     113        ResultCollection successfulOffspringAnalysis;
     114
     115        if (SuccessfulOffspringAnalysisParameter.ActualValue == null) {
     116          successfulOffspringAnalysis = new ResultCollection();
     117          SuccessfulOffspringAnalysisParameter.ActualValue = successfulOffspringAnalysis;
     118        } else {
     119          successfulOffspringAnalysis = SuccessfulOffspringAnalysisParameter.ActualValue;
     120        }
     121
     122        string resultKey = "SuccessfulOffspringAnalyzer Results";
     123        if (!results.ContainsKey(resultKey)) {
     124          results.Add(new Result(resultKey, successfulOffspringAnalysis));
     125        } else {
     126          results[resultKey].Value = successfulOffspringAnalysis;
     127        }
     128
     129        DataTable successProgressAnalysis;
     130        if (!successfulOffspringAnalysis.ContainsKey(collected.Value)) {
     131          successProgressAnalysis = new DataTable();
     132          successProgressAnalysis.Name = collected.Value;
     133          successfulOffspringAnalysis.Add(new Result(collected.Value, successProgressAnalysis));
     134        } else {
     135          successProgressAnalysis = successfulOffspringAnalysis[collected.Value].Value as DataTable;
     136        }
     137
     138        int successfulCount = 0;
     139        foreach (string key in counts.Keys) {
     140          successfulCount += counts[key];
     141        }
     142
     143        foreach (String value in counts.Keys) {
     144          DataRow row;
     145          if (!successProgressAnalysis.Rows.ContainsKey(value)) {
     146            row = new DataRow(value);
     147            int iterations = GenerationsParameter.ActualValue.Value;
     148
     149            //fill up all values seen the first time
     150            for (int i = 1; i < iterations; i++)
     151              row.Values.Add(0);
     152
     153            successProgressAnalysis.Rows.Add(row);
     154          } else {
     155            row = successProgressAnalysis.Rows[value];
    107156          }
    108157
    109           //create a data table containing the collected values
    110           ResultCollection successfulOffspringAnalysis;
     158          row.Values.Add(counts[value] / (double)successfulCount);
     159        }
    111160
    112           if (SuccessfulOffspringAnalysisParameter.ActualValue == null) {
    113             successfulOffspringAnalysis = new ResultCollection();
    114             SuccessfulOffspringAnalysisParameter.ActualValue = successfulOffspringAnalysis;
    115           } else {
    116             successfulOffspringAnalysis = SuccessfulOffspringAnalysisParameter.ActualValue;
    117           }
    118 
    119           string resultKey = "SuccessfulOffspringAnalyzer Results";
    120           if (!results.ContainsKey(resultKey)) {
    121             results.Add(new Result(resultKey, successfulOffspringAnalysis));
    122           } else {
    123             results[resultKey].Value = successfulOffspringAnalysis;
    124           }             
    125 
    126           DataTable successProgressAnalysis;
    127           if (!successfulOffspringAnalysis.ContainsKey(collected.Value)) {
    128             successProgressAnalysis = new DataTable();
    129             successProgressAnalysis.Name = collected.Value;
    130             successfulOffspringAnalysis.Add(new Result(collected.Value, successProgressAnalysis));
    131           } else {
    132             successProgressAnalysis = successfulOffspringAnalysis[collected.Value].Value as DataTable;
    133           }         
    134 
    135           int successfulCount = 0;
    136           foreach (string key in counts.Keys) {
    137             successfulCount += counts[key];
    138           }
    139 
    140           foreach(String value in counts.Keys) {           
    141             DataRow row;
    142             if (!successProgressAnalysis.Rows.ContainsKey(value)) {
    143               row = new DataRow(value);
    144               int iterations = GenerationsParameter.ActualValue.Value;
    145 
    146               //fill up all values seen the first time
    147               for (int i = 1; i < iterations; i++)
    148                 row.Values.Add(0);
    149 
    150               successProgressAnalysis.Rows.Add(row);
    151             } else {
    152               row = successProgressAnalysis.Rows[value];
    153             }
    154 
    155             row.Values.Add(counts[value] / (double)successfulCount);
    156           }
    157 
    158           //fill up all values that are not present in the current generation
    159           foreach (DataRow row in successProgressAnalysis.Rows) {
    160             if (!counts.ContainsKey(row.Name))
    161               row.Values.Add(0);
    162           }
    163         } 
     161        //fill up all values that are not present in the current generation
     162        foreach (DataRow row in successProgressAnalysis.Rows) {
     163          if (!counts.ContainsKey(row.Name))
     164            row.Values.Add(0);
     165        }
     166      }
    164167
    165168      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.