Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestQualityAnalyzer.cs @ 4830

Last change on this file since 4830 was 4830, checked in by cneumuel, 14 years ago

#1215 worked on metaoptimization

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