Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/10 20:37:36 (13 years ago)
Author:
cneumuel
Message:

#1215 worked on metaoptimization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r4839 r5009  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     9using System.Collections.Generic;
     10using System;
    911
    1012namespace HeuristicLab.Problems.MetaOptimization {
     
    1214  /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
    1315  /// </summary>
    14   [Item("BestQualityAnalyzer", "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.")]
    1517  [StorableClass]
    1618  public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer {
    1719    // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen
    1820
    19     public ScopeTreeLookupParameter<IParameterConfiguration> ParameterVectorParameter {
    20       get { return (ScopeTreeLookupParameter<IParameterConfiguration>)Parameters["ParameterConfiguration"]; }
     21    public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     22      get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    2123    }
    2224    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    2325      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    2426    }
    25     public LookupParameter<IParameterConfiguration> BestSolutionParameter {
    26       get { return (LookupParameter<IParameterConfiguration>)Parameters["BestSolution"]; }
     27    public LookupParameter<IRun> BestSolutionParameter {
     28      get { return (LookupParameter<IRun>)Parameters["BestSolution"]; }
    2729    }
    2830    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    3234      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    3335    }
    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"]; }
    3641    }
    3742
    3843    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."));
    4045      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
    41       Parameters.Add(new LookupParameter<IParameterConfiguration>("BestSolution", "TODO The best TSP solution."));
     46      Parameters.Add(new LookupParameter<IRun>("BestSolution", "TODO The best TSP solution."));
    4247      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
    4348      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."));
    4551    }
    4652
     
    5662      ResultCollection results = ResultsParameter.ActualValue;
    5763      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    58       ItemArray<IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;
     64      ItemArray<ParameterConfigurationTree> parameterConfigurations = ParameterConfigurationParameter.ActualValue;
    5965
    6066      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    6167
     68      EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterConfigurations[i]).ActualValue.Value);
     69      Run bestRun = new Run(bestAlg);
     70
    6271      if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) {
    6372        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    64         BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();
     73        BestKnownSolutionParameter.ActualValue = bestRun;
    6574      }
    6675
    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();
    68101
    69102      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.