Changeset 3680
- Timestamp:
- 05/06/10 18:37:59 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r3663 r3680 136 136 get { return (GeneticAlgorithmMainLoop)SolutionsCreator.Successor; } 137 137 } 138 private List<ISelector> selectors; 139 private IEnumerable<ISelector> Selectors { 140 get { return selectors; } 141 } 138 [Storable] 142 139 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 143 140 #endregion … … 181 178 geneticAlgorithmMainLoop.ResultsParameter.ActualName = "Results"; 182 179 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 183 190 Initialize(); 184 191 } … … 188 195 public override IDeepCloneable Clone(Cloner cloner) { 189 196 GeneticAlgorithm clone = (GeneticAlgorithm)base.Clone(cloner); 197 clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer); 190 198 clone.Initialize(); 191 199 return clone; … … 257 265 [StorableHook(HookType.AfterDeserialization)] 258 266 private void Initialize() { 259 InitializeSelectors();260 InitializeAnalyzers();261 UpdateSelectors();262 UpdateAnalyzers();263 267 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 264 268 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); … … 266 270 Elites.ValueChanged += new EventHandler(Elites_ValueChanged); 267 271 if (Problem != null) { 268 UpdateCrossovers();269 UpdateMutators();270 272 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 271 273 } … … 285 287 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 286 288 } 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 }296 289 private void ParameterizeSelectors() { 297 foreach (ISelector selector in Selector s) {290 foreach (ISelector selector in SelectorParameter.ValidValues) { 298 291 selector.CopySelected = new BoolValue(true); 299 292 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)); … … 301 294 } 302 295 if (Problem != null) { 303 foreach (ISingleObjectiveSelector selector in Selector s.OfType<ISingleObjectiveSelector>()) {296 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 304 297 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 305 298 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 314 307 qualityAnalyzer.QualityParameter.Depth = 1; 315 308 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;330 309 } 331 310 }
Note: See TracChangeset
for help on using the changeset viewer.