Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs @ 4839

Last change on this file since 4839 was 4839, checked in by cneumuel, 13 years ago

#1215 worked on MetaOptimization

  • split configurations into ValueConfigurations and ParameterConfigurations
File size: 4.1 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;
9
10namespace HeuristicLab.Problems.MetaOptimization {
11  /// <summary>
12  /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
13  /// </summary>
14  [Item("BestQualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
15  [StorableClass]
16  public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer {
17    // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen
18
19    public ScopeTreeLookupParameter<IParameterConfiguration> ParameterVectorParameter {
20      get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; }
21    }
22    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
23      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
24    }
25    public LookupParameter<IParameterConfiguration> BestSolutionParameter {
26      get { return (LookupParameter<IParameterConfiguration>)Parameters["BestSolution"]; }
27    }
28    public ValueLookupParameter<ResultCollection> ResultsParameter {
29      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
30    }
31    public LookupParameter<DoubleValue> BestKnownQualityParameter {
32      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
33    }
34    public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter {
35      get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; }
36    }
37
38    public BestParameterConfigurationAnalyzer() : base() {
39      Parameters.Add(new ScopeTreeLookupParameter<IParameterConfiguration>("ParameterConfiguration", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
40      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
41      Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution."));
42      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
43      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
44      Parameters.Add(new LookupParameter<IParameterConfiguration>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
45    }
46
47    [StorableConstructor]
48    private BestParameterConfigurationAnalyzer(bool deserializing) : base(deserializing) { }
49    private BestParameterConfigurationAnalyzer(BestParameterConfigurationAnalyzer original, Cloner cloner) : base(original, cloner) { }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new BestParameterConfigurationAnalyzer(this, cloner);
52    }
53
54    public override IOperation Apply() {
55      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
56      ResultCollection results = ResultsParameter.ActualValue;
57      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
58      ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;
59
60      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
61
62      if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
63        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
64        BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();
65      }
66
67      // todo: more
68
69      return base.Apply();
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.