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 |
|
---|
12 | namespace 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 | }
|
---|