1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Data;
|
---|
11 | using HeuristicLab.Common;
|
---|
12 |
|
---|
13 | namespace 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() : base() {
|
---|
42 | Parameters.Add(new ScopeTreeLookupParameter<IParameterConfiguration>("ParameterConfiguration", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
|
---|
43 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
|
---|
44 | Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution."));
|
---|
45 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
|
---|
46 | Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
|
---|
47 | Parameters.Add(new LookupParameter<IParameterConfiguration>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableConstructor]
|
---|
51 | private BestParameterConfigurationAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
52 | private BestParameterConfigurationAnalyzer(BestParameterConfigurationAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
53 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
54 | return new BestParameterConfigurationAnalyzer(this, cloner);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override IOperation Apply() {
|
---|
58 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
59 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
60 | DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
|
---|
61 | ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;
|
---|
62 |
|
---|
63 | int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
64 |
|
---|
65 | if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
|
---|
66 | BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
|
---|
67 | BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();
|
---|
68 | }
|
---|
69 |
|
---|
70 | // todo: more
|
---|
71 |
|
---|
72 | return base.Apply();
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|