Free cookie consent management tool by TermsFeed Policy Generator

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

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

initial prototype for Meta Optimization Problem (#1215)

File size: 3.4 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;
11
12namespace HeuristicLab.Problems.MetaOptimization {
13  /// <summary>
14  /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
15  /// </summary>
16  [Item("BestQualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
17  [StorableClass]
18  public sealed class BestQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
19
20    public ScopeTreeLookupParameter<IParameterSet> ParameterSetParameter {
21      get { return (ScopeTreeLookupParameter<IParameterSet>)Parameters["ParameterSet"]; }
22    }
23    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
24      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
25    }
26    public LookupParameter<IParameterSet> BestSolutionParameter {
27      get { return (LookupParameter<IParameterSet>)Parameters["BestSolution"]; }
28    }
29    public ValueLookupParameter<ResultCollection> ResultsParameter {
30      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
31    }
32    public LookupParameter<DoubleValue> BestKnownQualityParameter {
33      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
34    }
35    public LookupParameter<IParameterSet> BestKnownSolutionParameter {
36      get { return (LookupParameter<IParameterSet>)Parameters["BestKnownSolution"]; }
37    }
38
39    public BestQualityAnalyzer()
40      : base() {
41      Parameters.Add(new ScopeTreeLookupParameter<IParameterSet>("ParameterSet", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
42      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
43      Parameters.Add(new LookupParameter<IParameterSet>("BestSolution", "TODO The best TSP solution."));
44      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
45      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
46      Parameters.Add(new LookupParameter<IParameterSet>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
47    }
48
49    public override IOperation Apply() {
50      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
51      ResultCollection results = ResultsParameter.ActualValue;
52      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
53      ItemArray<IParameterSet> parameterSets = ParameterSetParameter.ActualValue;
54
55      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
56
57      if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
58        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
59        BestKnownSolutionParameter.ActualValue = (IParameterSet)parameterSets[i].Clone();
60      }
61
62      // todo: more
63
64      return base.Apply();
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.