Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11796 for branches


Ignore:
Timestamp:
01/19/15 12:35:24 (10 years ago)
Author:
ascheibe
Message:

#2267 added analysis functionality to diversity comparer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/WeightedParentsDiversityComparator.cs

    r11729 r11796  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Analysis;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    6566      get { return (IConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
    6667    }
     68    public ValueLookupParameter<ResultCollection> ResultsParameter {
     69      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     70    }
     71    public ILookupParameter<IntValue> GenerationsParameter {
     72      get { return (LookupParameter<IntValue>)Parameters["Generations"]; }
     73    }
     74
     75    private const string spDetailsParameterName = "SPDetails";
     76    private const string divDataRowName = "DiversitySuccessCount";
     77    private const string qualityDataRowName = "QualitySuccessCount";
     78    private const string overallCountDataRowName = "OverallCount";
     79    private const string successCountDataRowName = "SuccessCount";
     80
     81    [Storable]
     82    private int currentGeneration;
     83    [Storable]
     84    private int divCount;
     85    [Storable]
     86    private int qualityCount;
     87    [Storable]
     88    private int overallCount;
     89    [Storable]
     90    private int successCount;
    6791
    6892    [StorableConstructor]
     
    7195      : base(original, cloner) {
    7296      SimilarityCalculator = cloner.Clone(original.SimilarityCalculator);
     97      currentGeneration = original.currentGeneration;
     98      divCount = original.divCount;
     99      qualityCount = original.qualityCount;
     100      overallCount = original.overallCount;
     101      successCount = original.successCount;
    73102    }
    74103    public WeightedParentsDiversityComparator()
     
    83112      Parameters.Add(new ValueLookupParameter<DoubleValue>("DiversityComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1.0)));
    84113      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
     114      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the population diversity analysis results should be stored."));
     115      Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
    85116
    86117      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     
    93124    public override IDeepCloneable Clone(Cloner cloner) {
    94125      return new WeightedParentsDiversityComparator(this, cloner);
     126    }
     127
     128    [StorableHook(HookType.AfterDeserialization)]
     129    private void AfterDeserialization() {
     130      if (!Parameters.ContainsKey("Generations"))
     131        Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
     132      if (!Parameters.ContainsKey("Results"))
     133        Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the population diversity analysis results should be stored."));
    95134    }
    96135
     
    115154      double leftQuality = LeftSideParameter.ActualValue.Value;
    116155      bool resultDiversity;
    117 
    118156      double threshold = 0;
     157
     158      DataTable spDetailsTable;
     159      if (ResultsParameter.ActualValue.ContainsKey(spDetailsParameterName)) {
     160        spDetailsTable = (DataTable)ResultsParameter.ActualValue[spDetailsParameterName].Value;
     161      } else {
     162        spDetailsTable = new DataTable(spDetailsParameterName);
     163        spDetailsTable.Rows.Add(new DataRow(divDataRowName));
     164        spDetailsTable.Rows.Add(new DataRow(qualityDataRowName));
     165        spDetailsTable.Rows.Add(new DataRow(overallCountDataRowName));
     166        spDetailsTable.Rows.Add(new DataRow(successCountDataRowName));
     167        ResultsParameter.ActualValue.Add(new Result(spDetailsParameterName, spDetailsTable));
     168      }
     169
     170      if (GenerationsParameter.ActualValue.Value != currentGeneration) {
     171        spDetailsTable.Rows[divDataRowName].Values.Add(divCount);
     172        divCount = 0;
     173        spDetailsTable.Rows[qualityDataRowName].Values.Add(qualityCount);
     174        qualityCount = 0;
     175        spDetailsTable.Rows[overallCountDataRowName].Values.Add(overallCount);
     176        overallCount = 0;
     177        spDetailsTable.Rows[successCountDataRowName].Values.Add(successCount);
     178        successCount = 0;
     179        currentGeneration = GenerationsParameter.ActualValue.Value;
     180      }
    119181
    120182      #region Calculate threshold
     
    140202
    141203      bool result = maximization && leftQuality > threshold || !maximization && leftQuality < threshold;
     204
     205      if (result) {
     206        qualityCount++;
     207      }
     208
    142209      result = result && resultDiversity;
     210
     211      if (resultDiversity) {
     212        divCount++;
     213      }
     214      if (result) {
     215        successCount++;
     216      }
     217      overallCount++;
     218
    143219      BoolValue resultValue = ResultParameter.ActualValue;
    144220      if (resultValue == null) {
Note: See TracChangeset for help on using the changeset viewer.