Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 18:54:00 (14 years ago)
Author:
abeham
Message:

#999

  • ported Island GA to Analyzers
  • ported OSGA to Analyzers
  • changed OSGA to use OSGA's main operator
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs

    r3616 r3650  
    3434using HeuristicLab.Random;
    3535using HeuristicLab.Selection;
     36using HeuristicLab.Analysis;
    3637
    3738namespace HeuristicLab.Algorithms.GeneticAlgorithm {
     
    103104      get { return (ValueParameter<BoolValue>)Parameters["Parallel"]; }
    104105    }
     106    private ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>> AnalyzerParameter {
     107      get { return (ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>>)Parameters["Analyzer"]; }
     108    }
     109    private ValueParameter<MultiAnalyzer<IPopulationAnalyzer>> IslandAnalyzerParameter {
     110      get { return (ValueParameter<MultiAnalyzer<IPopulationAnalyzer>>)Parameters["IslandAnalyzer"]; }
     111    }
    105112    #endregion
    106113
     
    169176      get { return ParallelParameter.Value; }
    170177      set { ParallelParameter.Value = value; }
     178    }
     179    public MultiAnalyzer<IMultiPopulationAnalyzer> Analyzer {
     180      get { return AnalyzerParameter.Value; }
     181      set { AnalyzerParameter.Value = value; }
     182    }
     183    public MultiAnalyzer<IPopulationAnalyzer> IslandAnalyzer {
     184      get { return IslandAnalyzerParameter.Value; }
     185      set { IslandAnalyzerParameter.Value = value; }
    171186    }
    172187    private List<ISelector> selectors;
     
    189204      get { return (IslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
    190205    }
     206    private PopulationBestAverageWorstQualityAnalyzer islandQualityAnalyzer;
     207    //private MultipopulationBestAverageWorstQualityAnalyzer qualityAnalyzer;
    191208    #endregion
    192209
     
    211228      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    212229      Parameters.Add(new ValueParameter<BoolValue>("Parallel", "True if the islands should be run in parallel (also requires a parallel engine)", new BoolValue(false)));
    213 
     230      Parameters.Add(new ValueParameter<MultiAnalyzer<IMultiPopulationAnalyzer>>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer<IMultiPopulationAnalyzer>()));
     231      Parameters.Add(new ValueParameter<MultiAnalyzer<IPopulationAnalyzer>>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer<IPopulationAnalyzer>()));
     232     
    214233      RandomCreator randomCreator = new RandomCreator();
    215234      SubScopesCreator populationCreator = new SubScopesCreator();
     
    251270      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
    252271      mainLoop.ResultsParameter.ActualName = "Results";
     272      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     273      mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
    253274
    254275      mainLoop.Successor = null;
     
    275296      ParameterizeMainLoop();
    276297      ParameterizeSelectors();
     298      ParameterizeAnalyzers();
    277299      UpdateCrossovers();
    278300      UpdateMutators();
     301      UpdateAnalyzers();
    279302      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    280303      base.OnProblemChanged();
     
    291314      ParameterizeMainLoop();
    292315      ParameterizeSelectors();
     316      ParameterizeAnalyzers();
    293317      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    294318      base.Problem_EvaluatorChanged(sender, e);
     
    298322      UpdateCrossovers();
    299323      UpdateMutators();
     324      UpdateAnalyzers();
    300325      base.Problem_OperatorsChanged(sender, e);
    301326    }
     
    317342      ParameterizeMainLoop();
    318343      ParameterizeSelectors();
     344      ParameterizeAnalyzers();
    319345    }
    320346    private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
     
    331357    private void Initialize() {
    332358      InitializeSelectors();
     359      InitializeAnalyzers();
    333360      UpdateSelectors();
     361      UpdateAnalyzers();
    334362      InitializeMigrators();
    335363      UpdateMigrators();
     
    368396      immigrationReplacers.AddRange(ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name));
    369397      ParameterizeSelectors();
     398    }
     399    private void InitializeAnalyzers() {
     400      islandQualityAnalyzer = new PopulationBestAverageWorstQualityAnalyzer();
     401      //qualityAnalyzer = new MultipopulationBestAverageWorstQualityAnalyzer();
     402      ParameterizeAnalyzers();
    370403    }
    371404    private void InitializeMigrators() {
     
    403436      }
    404437    }
     438    private void ParameterizeAnalyzers() {
     439      islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
     440      //qualityAnalyzer.ResultsParameter.ActualName = "Results";
     441      if (Problem != null) {
     442        islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     443        islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     444        islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     445      }
     446    }
    405447    private void UpdateSelectors() {
    406448      ISelector oldSelector = SelectorParameter.Value;
     
    465507      }
    466508    }
     509    private void UpdateAnalyzers() {
     510      IslandAnalyzer.Operators.Clear();
     511      Analyzer.Operators.Clear();
     512      IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
     513      //Analyzer.Operators.Add(qualityAnalyzer);
     514      if (Problem != null) {
     515        foreach (IPopulationAnalyzer analyzer in Problem.Operators.OfType<IPopulationAnalyzer>().OrderBy(x => x.Name)) {
     516          IslandAnalyzer.Operators.Add(analyzer);
     517        }
     518        foreach (IMultiPopulationAnalyzer analyzer in Problem.Operators.OfType<IMultiPopulationAnalyzer>().OrderBy(x => x.Name))
     519          Analyzer.Operators.Add(analyzer);
     520      }
     521    }
    467522    #endregion
    468523  }
Note: See TracChangeset for help on using the changeset viewer.