Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 22:08:17 (14 years ago)
Author:
abeham
Message:

#999

  • updated Island OSGA to soon to be changed analyzers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs

    r3616 r3654  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Analysis;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    3334using HeuristicLab.PluginInfrastructure;
    3435using HeuristicLab.Random;
    35 using HeuristicLab.Selection;
    3636
    3737namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
     
    121121      get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
    122122    }
     123    private ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>> AnalyzerParameter {
     124      get { return (ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>>)Parameters["Analyzer"]; }
     125    }
     126    private ValueParameter<MultiAnalyzer<IPopulationAnalyzer>> IslandAnalyzerParameter {
     127      get { return (ValueParameter<MultiAnalyzer<IPopulationAnalyzer>>)Parameters["IslandAnalyzer"]; }
     128    }
    123129    #endregion
    124130
     
    211217      get { return OffspringSelectionBeforeMutationParameter.Value; }
    212218      set { OffspringSelectionBeforeMutationParameter.Value = value; }
     219    }
     220    public MultiAnalyzer<IMultiPopulationAnalyzer> Analyzer {
     221      get { return AnalyzerParameter.Value; }
     222      set { AnalyzerParameter.Value = value; }
     223    }
     224    public MultiAnalyzer<IPopulationAnalyzer> IslandAnalyzer {
     225      get { return IslandAnalyzerParameter.Value; }
     226      set { IslandAnalyzerParameter.Value = value; }
    213227    }
    214228    private List<ISelector> selectors;
     
    232246      get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
    233247    }
     248    private PopulationBestAverageWorstQualityAnalyzer islandQualityAnalyzer;
     249    //private MultipopulationBestAverageWorstQualityAnalyzer qualityAnalyzer;
    234250    #endregion
    235251
     
    260276      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
    261277      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
    262 
     278      Parameters.Add(new ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer<IMultiPopulationAnalyzer>()));
     279      Parameters.Add(new ValueParameter<MultiAnalyzer<IPopulationAnalyzer>>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer<IPopulationAnalyzer>()));
     280     
    263281      RandomCreator randomCreator = new RandomCreator();
    264282      SubScopesCreator populationCreator = new SubScopesCreator();
     
    331349      ParameterizeMainLoop();
    332350      ParameterizeSelectors();
     351      ParameterizeAnalyzers();
    333352      UpdateCrossovers();
    334353      UpdateMutators();
     354      UpdateAnalyzers();
    335355      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    336356      base.OnProblemChanged();
     
    347367      ParameterizeMainLoop();
    348368      ParameterizeSelectors();
     369      ParameterizeAnalyzers();
    349370      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    350371      base.Problem_EvaluatorChanged(sender, e);
     
    354375      UpdateCrossovers();
    355376      UpdateMutators();
     377      UpdateAnalyzers();
    356378      base.Problem_OperatorsChanged(sender, e);
    357379    }
     
    373395      ParameterizeMainLoop();
    374396      ParameterizeSelectors();
     397      ParameterizeAnalyzers();
    375398    }
    376399    private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
     
    401424    private void Initialize() {
    402425      InitializeSelectors();
     426      InitializeAnalyzers();
    403427      UpdateSelectors();
     428      UpdateAnalyzers();
    404429      InitializeComparisonFactorModifiers();
    405430      UpdateComparisonFactorModifiers();
     
    445470      ParameterizeSelectors();
    446471    }
     472    private void InitializeAnalyzers() {
     473      islandQualityAnalyzer = new PopulationBestAverageWorstQualityAnalyzer();
     474      //qualityAnalyzer = new MultipopulationBestAverageWorstQualityAnalyzer();
     475      ParameterizeAnalyzers();
     476    }
    447477    private void InitializeComparisonFactorModifiers() {
    448478      comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();
     
    484514      }
    485515    }
     516    private void ParameterizeAnalyzers() {
     517      islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
     518      //qualityAnalyzer.ResultsParameter.ActualName = "Results";
     519      if (Problem != null) {
     520        islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     521        islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     522        islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     523      }
     524    }
    486525    private void ParameterizeComparisonFactorModifiers() {
    487526      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {
     
    568607      }
    569608    }
     609    private void UpdateAnalyzers() {
     610      IslandAnalyzer.Operators.Clear();
     611      Analyzer.Operators.Clear();
     612      IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
     613      //Analyzer.Operators.Add(qualityAnalyzer);
     614      if (Problem != null) {
     615        foreach (IPopulationAnalyzer analyzer in Problem.Operators.OfType<IPopulationAnalyzer>().OrderBy(x => x.Name)) {
     616          IslandAnalyzer.Operators.Add(analyzer);
     617        }
     618        foreach (IMultiPopulationAnalyzer analyzer in Problem.Operators.OfType<IMultiPopulationAnalyzer>().OrderBy(x => x.Name))
     619          Analyzer.Operators.Add(analyzer);
     620      }
     621    }
    570622    #endregion
    571623  }
Note: See TracChangeset for help on using the changeset viewer.