Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3680


Ignore:
Timestamp:
05/06/10 18:37:59 (15 years ago)
Author:
swagner
Message:

Fixed bug in GA wiring (#893)

File:
1 edited

Legend:

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

    r3663 r3680  
    136136      get { return (GeneticAlgorithmMainLoop)SolutionsCreator.Successor; }
    137137    }
    138     private List<ISelector> selectors;
    139     private IEnumerable<ISelector> Selectors {
    140       get { return selectors; }
    141     }
     138    [Storable]
    142139    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    143140    #endregion
     
    181178      geneticAlgorithmMainLoop.ResultsParameter.ActualName = "Results";
    182179
     180      foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
     181        SelectorParameter.ValidValues.Add(selector);
     182      ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
     183      if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
     184      ParameterizeSelectors();
     185
     186      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     187      ParameterizeAnalyzers();
     188      UpdateAnalyzers();
     189
    183190      Initialize();
    184191    }
     
    188195    public override IDeepCloneable Clone(Cloner cloner) {
    189196      GeneticAlgorithm clone = (GeneticAlgorithm)base.Clone(cloner);
     197      clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
    190198      clone.Initialize();
    191199      return clone;
     
    257265    [StorableHook(HookType.AfterDeserialization)]
    258266    private void Initialize() {
    259       InitializeSelectors();
    260       InitializeAnalyzers();
    261       UpdateSelectors();
    262       UpdateAnalyzers();
    263267      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
    264268      PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
     
    266270      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    267271      if (Problem != null) {
    268         UpdateCrossovers();
    269         UpdateMutators();
    270272        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    271273      }
     
    285287        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    286288    }
    287     private void InitializeSelectors() {
    288       selectors = new List<ISelector>();
    289       selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
    290       ParameterizeSelectors();
    291     }
    292     private void InitializeAnalyzers() {
    293       qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    294       ParameterizeAnalyzers();
    295     }
    296289    private void ParameterizeSelectors() {
    297       foreach (ISelector selector in Selectors) {
     290      foreach (ISelector selector in SelectorParameter.ValidValues) {
    298291        selector.CopySelected = new BoolValue(true);
    299292        selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
     
    301294      }
    302295      if (Problem != null) {
    303         foreach (ISingleObjectiveSelector selector in Selectors.OfType<ISingleObjectiveSelector>()) {
     296        foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
    304297          selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    305298          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     
    314307        qualityAnalyzer.QualityParameter.Depth = 1;
    315308        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    316       }
    317     }
    318     private void UpdateSelectors() {
    319       ISelector oldSelector = SelectorParameter.Value;
    320       SelectorParameter.ValidValues.Clear();
    321       foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
    322         SelectorParameter.ValidValues.Add(selector);
    323 
    324       ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
    325       if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
    326 
    327       if (oldSelector != null) {
    328         ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
    329         if (selector != null) SelectorParameter.Value = selector;
    330309      }
    331310    }
Note: See TracChangeset for help on using the changeset viewer.