Changeset 5009 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers
- Timestamp:
- 12/01/10 20:37:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r4839 r5009 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic; 10 using System; 9 11 10 12 namespace HeuristicLab.Problems.MetaOptimization { … … 12 14 /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 13 15 /// </summary> 14 [Item("Best QualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]16 [Item("BestParameterConfigurationAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")] 15 17 [StorableClass] 16 18 public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer { 17 19 // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen 18 20 19 public ScopeTreeLookupParameter< IParameterConfiguration> ParameterVectorParameter {20 get { return (ScopeTreeLookupParameter< IParameterConfiguration>)Parameters["ParameterConfiguration"]; }21 public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 22 get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 21 23 } 22 24 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 23 25 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 24 26 } 25 public LookupParameter<I ParameterConfiguration> BestSolutionParameter {26 get { return (LookupParameter<I ParameterConfiguration>)Parameters["BestSolution"]; }27 public LookupParameter<IRun> BestSolutionParameter { 28 get { return (LookupParameter<IRun>)Parameters["BestSolution"]; } 27 29 } 28 30 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 32 34 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 33 35 } 34 public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter { 35 get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; } 36 public LookupParameter<IRun> BestKnownSolutionParameter { 37 get { return (LookupParameter<IRun>)Parameters["BestKnownSolution"]; } 38 } 39 public LookupParameter<RunCollection> PopulationParameter { 40 get { return (LookupParameter<RunCollection>)Parameters["Population"]; } 36 41 } 37 42 38 43 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."));44 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed.")); 40 45 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed.")); 41 Parameters.Add(new LookupParameter<I ParameterConfiguration>("BestSolution", "TODO The best TSP solution."));46 Parameters.Add(new LookupParameter<IRun>("BestSolution", "TODO The best TSP solution.")); 42 47 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored.")); 43 48 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.")); 49 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance.")); 50 Parameters.Add(new LookupParameter<RunCollection>("Population", "TODO The best known solution of this TSP instance.")); 45 51 } 46 52 … … 56 62 ResultCollection results = ResultsParameter.ActualValue; 57 63 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 58 ItemArray< IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;64 ItemArray<ParameterConfigurationTree> parameterConfigurations = ParameterConfigurationParameter.ActualValue; 59 65 60 66 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 61 67 68 EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterConfigurations[i]).ActualValue.Value); 69 Run bestRun = new Run(bestAlg); 70 62 71 if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) { 63 72 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 64 BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();73 BestKnownSolutionParameter.ActualValue = bestRun; 65 74 } 66 75 67 // todo: more 76 IRun best = BestSolutionParameter.ActualValue; 77 if (best == null) { 78 BestSolutionParameter.ActualValue = bestRun; 79 results.Add(new Result("Best Parameter Settings", bestRun)); 80 } else { 81 BestSolutionParameter.ActualValue = bestRun; 82 results["Best Parameter Settings"].Value = bestRun; 83 } 84 85 RunCollection rc = new RunCollection(); 86 87 foreach (ParameterConfigurationTree pc in parameterConfigurations.OrderBy(x => x.Quality.Value*-1)) { 88 IAlgorithm alg = (IAlgorithm)pc.ActualValue.Value; 89 alg.StoreAlgorithmInEachRun = false; 90 IRun run = new Run(alg); 91 rc.Add(run); 92 } 93 if (PopulationParameter.ActualValue == null) { 94 PopulationParameter.ActualValue = rc; 95 results.Add(new Result("Population", rc)); 96 } else { 97 PopulationParameter.ActualValue = rc; 98 results["Population"].Value = rc; 99 } 100 GC.Collect(); 68 101 69 102 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.