Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/ReferenceQualityAnalyzer.cs @ 5653

Last change on this file since 5653 was 5653, checked in by cneumuel, 12 years ago

#1215

  • evaluation operator returns operatorgraph which creates a scope and an operation for each algorithm execution (each repetition and problem)
  • split ValueConfiguration into ParameterizedValueConfiguration and RangeValueConfiguration
File size: 3.9 KB
Line 
1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using System.Collections.Generic;
10using System;
11
12namespace HeuristicLab.Problems.MetaOptimization {
13  /// <summary>
14  /// TODO
15  /// </summary>
16  [Item("ReferenceQualityAnalyzer", "")]
17  [StorableClass]
18  public sealed class ReferenceQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
19   
20    public ValueLookupParameter<ResultCollection> ResultsParameter {
21      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
22    }
23    public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
24      get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
25    }
26    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
27      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
28    }
29    public LookupParameter<DoubleArray> ProblemQualityReferenceParameter {
30      get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
31    }
32    public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
33      get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
34    }
35
36    public ReferenceQualityAnalyzer()
37      : base() {
38      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
39      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
40      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
41      Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
42      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
43    }
44
45    [StorableConstructor]
46    private ReferenceQualityAnalyzer(bool deserializing) : base(deserializing) { }
47    private ReferenceQualityAnalyzer(ReferenceQualityAnalyzer original, Cloner cloner) : base(original, cloner) { }
48    public override IDeepCloneable Clone(Cloner cloner) {
49      return new ReferenceQualityAnalyzer(this, cloner);
50    }
51
52    public override IOperation Apply() {
53      ResultCollection results = ResultsParameter.ActualValue;
54      ItemArray<ParameterConfigurationTree> solutions = ParameterConfigurationParameter.ActualValue;
55      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
56
57      if (ProblemQualityReferenceParameter.ActualValue == null) {
58        DoubleArray referenceQualities = CalculateReferenceQualities(solutions);
59        ProblemQualityReferenceParameter.ActualValue = referenceQualities;
60        NormalizePopulation(solutions, qualities, referenceQualities);
61        results.Add(new Result("QualityReferences", referenceQualities));
62      }
63
64      return base.Apply();
65    }
66
67    private DoubleArray CalculateReferenceQualities(ItemArray<ParameterConfigurationTree> solutions) {
68      DoubleArray referenceQualities = new DoubleArray(ProblemsParameter.ActualValue.Count);
69      for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) {
70        referenceQualities[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Min(); // todo: respect minimization / maximization
71      }
72      return referenceQualities;
73    }
74
75    private void NormalizePopulation(ItemArray<ParameterConfigurationTree> solutions, ItemArray<DoubleValue> qualities, DoubleArray referenceQualities) {
76      for (int i = 0; i < solutions.Length; i++) {
77        qualities[i].Value = MetaOptimizationUtil.NormalizeQualities(solutions[i], referenceQualities.ToArray());
78      }
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.