- Timestamp:
- 05/07/10 02:08:30 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs ¶
r3673 r3689 226 226 set { IslandAnalyzerParameter.Value = value; } 227 227 } 228 private List<ISelector> selectors;229 private IEnumerable<ISelector> Selectors {230 get { return selectors; }231 }232 private List<IDiscreteDoubleValueModifier> comparisonFactorModifiers;233 private List<ISelector> emigrantsSelectors;234 private List<IReplacer> immigrationReplacers;235 private List<IMigrator> migrators;236 228 private RandomCreator RandomCreator { 237 229 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 246 238 get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; } 247 239 } 240 [Storable] 248 241 private BestAverageWorstQualityAnalyzer islandQualityAnalyzer; 242 [Storable] 249 243 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 244 [Storable] 250 245 private ValueAnalyzer islandSelectionPressureAnalyzer; 246 [Storable] 251 247 private ValueAnalyzer selectionPressureAnalyzer; 252 248 #endregion … … 327 323 mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name; 328 324 mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name; 329 330 325 mainLoop.Successor = null; 326 327 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 328 SelectorParameter.ValidValues.Add(selector); 329 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector")); 330 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector; 331 332 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 333 EmigrantsSelectorParameter.ValidValues.Add(selector); 334 335 foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name)) 336 ImmigrationReplacerParameter.ValidValues.Add(replacer); 337 338 ParameterizeSelectors(); 339 340 foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name)) 341 MigratorParameter.ValidValues.Add(migrator); 342 343 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) 344 ComparisonFactorModifierParameter.ValidValues.Add(modifier); 345 IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier")); 346 if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier; 347 ParameterizeComparisonFactorModifiers(); 348 349 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 350 islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 351 selectionPressureAnalyzer = new ValueAnalyzer(); 352 islandSelectionPressureAnalyzer = new ValueAnalyzer(); 353 ParameterizeAnalyzers(); 354 UpdateAnalyzers(); 331 355 332 356 Initialize(); … … 335 359 public override IDeepCloneable Clone(Cloner cloner) { 336 360 IslandOffspringSelectionGeneticAlgorithm clone = (IslandOffspringSelectionGeneticAlgorithm)base.Clone(cloner); 361 clone.islandQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(islandQualityAnalyzer); 362 clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer); 363 clone.islandSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(islandSelectionPressureAnalyzer); 364 clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer); 337 365 clone.Initialize(); 338 366 return clone; … … 425 453 [StorableHook(HookType.AfterDeserialization)] 426 454 private void Initialize() { 427 InitializeSelectors();428 InitializeAnalyzers();429 UpdateSelectors();430 UpdateAnalyzers();431 InitializeComparisonFactorModifiers();432 UpdateComparisonFactorModifiers();433 InitializeMigrators();434 UpdateMigrators();435 455 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 436 456 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); … … 444 464 MaximumGenerations.ValueChanged += new EventHandler(MaximumMigrations_ValueChanged); 445 465 if (Problem != null) { 446 UpdateCrossovers();447 UpdateMutators();448 466 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 449 467 } … … 463 481 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 464 482 } 465 private void InitializeSelectors() {466 selectors = new List<ISelector>();467 selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));468 emigrantsSelectors = new List<ISelector>();469 emigrantsSelectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));470 immigrationReplacers = new List<IReplacer>();471 immigrationReplacers.AddRange(ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name));472 ParameterizeSelectors();473 }474 private void InitializeAnalyzers() {475 islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();476 qualityAnalyzer = new BestAverageWorstQualityAnalyzer();477 islandSelectionPressureAnalyzer = new ValueAnalyzer();478 selectionPressureAnalyzer = new ValueAnalyzer();479 ParameterizeAnalyzers();480 }481 private void InitializeComparisonFactorModifiers() {482 comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();483 comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));484 ParameterizeComparisonFactorModifiers();485 }486 private void InitializeMigrators() {487 migrators = new List<IMigrator>();488 migrators.AddRange(ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name));489 UpdateMigrators();490 }491 483 private void ParameterizeSelectors() { 492 foreach (ISelector selector in Selector s) {484 foreach (ISelector selector in SelectorParameter.ValidValues) { 493 485 selector.CopySelected = new BoolValue(true); 494 486 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value)); 495 487 ParameterizeStochasticOperator(selector); 496 488 } 497 foreach (ISelector selector in emigrantsSelectors) {489 foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) { 498 490 selector.CopySelected = new BoolValue(true); 499 491 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value)); 500 492 ParameterizeStochasticOperator(selector); 501 493 } 502 foreach (IReplacer selector in immigrationReplacers) {494 foreach (IReplacer selector in ImmigrationReplacerParameter.ValidValues) { 503 495 ParameterizeStochasticOperator(selector); 504 496 } 505 497 if (Problem != null) { 506 foreach (ISingleObjectiveSelector selector in Selector s.OfType<ISingleObjectiveSelector>()) {498 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 507 499 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 508 500 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 509 501 } 510 foreach (ISingleObjectiveSelector selector in emigrantsSelectors.OfType<ISingleObjectiveSelector>()) {502 foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 511 503 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 512 504 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 513 505 } 514 foreach (ISingleObjectiveReplacer replacer in immigrationReplacers.OfType<ISingleObjectiveReplacer>()) {506 foreach (ISingleObjectiveReplacer replacer in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) { 515 507 replacer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 516 508 replacer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 547 539 } 548 540 private void ParameterizeComparisonFactorModifiers() { 549 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {541 foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) { 550 542 modifier.IndexParameter.ActualName = "Generations"; 551 543 modifier.EndIndexParameter.Value = new IntValue(MigrationInterval.Value * MaximumGenerations.Value); … … 555 547 modifier.ValueParameter.ActualName = "ComparisonFactor"; 556 548 } 557 }558 private void UpdateSelectors() {559 ISelector oldSelector = SelectorParameter.Value;560 SelectorParameter.ValidValues.Clear();561 foreach (ISelector selector in Selectors.OrderBy(x => x.Name))562 SelectorParameter.ValidValues.Add(selector);563 564 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));565 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;566 567 if (oldSelector != null) {568 ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());569 if (selector != null) SelectorParameter.Value = selector;570 }571 572 oldSelector = EmigrantsSelector;573 EmigrantsSelectorParameter.ValidValues.Clear();574 foreach (ISelector selector in emigrantsSelectors)575 EmigrantsSelectorParameter.ValidValues.Add(selector);576 if (oldSelector != null) {577 ISelector selector = EmigrantsSelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());578 if (selector != null) EmigrantsSelectorParameter.Value = selector;579 }580 581 IReplacer oldReplacer = ImmigrationReplacerParameter.Value;582 ImmigrationReplacerParameter.ValidValues.Clear();583 foreach (IReplacer replacer in immigrationReplacers)584 ImmigrationReplacerParameter.ValidValues.Add(replacer);585 if (oldSelector != null) {586 IReplacer replacer = ImmigrationReplacerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());587 if (replacer != null) ImmigrationReplacerParameter.Value = replacer;588 }589 }590 private void UpdateComparisonFactorModifiers() {591 IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;592 593 ComparisonFactorModifierParameter.ValidValues.Clear();594 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)595 ComparisonFactorModifierParameter.ValidValues.Add(modifier);596 597 if (oldModifier != null) {598 IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());599 if (mod != null) ComparisonFactorModifierParameter.Value = mod;600 }601 }602 private void UpdateMigrators() {603 IMigrator oldMigrator = Migrator;604 MigratorParameter.ValidValues.Clear();605 foreach (IMigrator migrator in migrators)606 MigratorParameter.ValidValues.Add(migrator);607 if (oldMigrator != null) {608 IMigrator migrator = MigratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMigrator.GetType());609 if (migrator != null) MigratorParameter.Value = migrator;610 } else if (MigratorParameter.ValidValues.Count > 0) MigratorParameter.Value = MigratorParameter.ValidValues.First();611 549 } 612 550 private void UpdateCrossovers() { -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs ¶
r3672 r3689 184 184 get { return (OffspringSelectionGeneticAlgorithmMainLoop)SolutionsCreator.Successor; } 185 185 } 186 private List<ISelector> selectors; 187 private IEnumerable<ISelector> Selectors { 188 get { return selectors; } 189 } 190 private List<IDiscreteDoubleValueModifier> comparisonFactorModifiers; 186 [Storable] 191 187 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 188 [Storable] 192 189 private ValueAnalyzer selectionPressureAnalyzer; 193 190 #endregion … … 239 236 mainLoop.ResultsParameter.ActualName = "Results"; 240 237 238 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 239 SelectorParameter.ValidValues.Add(selector); 240 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector")); 241 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector; 242 ParameterizeSelectors(); 243 244 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) 245 ComparisonFactorModifierParameter.ValidValues.Add(modifier); 246 IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier")); 247 if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier; 248 ParameterizeComparisonFactorModifiers(); 249 250 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 251 selectionPressureAnalyzer = new ValueAnalyzer(); 252 ParameterizeAnalyzers(); 253 UpdateAnalyzers(); 254 241 255 Initialize(); 242 256 } … … 244 258 public override IDeepCloneable Clone(Cloner cloner) { 245 259 OffspringSelectionGeneticAlgorithm clone = (OffspringSelectionGeneticAlgorithm)base.Clone(cloner); 260 clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer); 261 clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer); 246 262 clone.Initialize(); 247 263 return clone; … … 313 329 [StorableHook(HookType.AfterDeserialization)] 314 330 private void Initialize() { 315 InitializeSelectors();316 InitializeAnalyzers();317 UpdateSelectors();318 UpdateAnalyzers();319 InitializeComparisonFactorModifiers();320 UpdateComparisonFactorModifiers();321 331 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 322 332 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); … … 324 334 Elites.ValueChanged += new EventHandler(Elites_ValueChanged); 325 335 if (Problem != null) { 326 UpdateCrossovers();327 UpdateMutators();328 336 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 329 337 } … … 342 350 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 343 351 } 344 private void InitializeSelectors() {345 selectors = new List<ISelector>();346 selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));347 ParameterizeSelectors();348 }349 private void InitializeAnalyzers() {350 qualityAnalyzer = new BestAverageWorstQualityAnalyzer();351 selectionPressureAnalyzer = new ValueAnalyzer();352 ParameterizeAnalyzers();353 }354 private void InitializeComparisonFactorModifiers() {355 comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();356 comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));357 ParameterizeComparisonFactorModifiers();358 }359 352 private void ParameterizeSelectors() { 360 foreach (ISelector selector in Selector s) {353 foreach (ISelector selector in SelectorParameter.ValidValues) { 361 354 selector.CopySelected = new BoolValue(true); 362 355 selector.NumberOfSelectedSubScopesParameter.Value = null; … … 365 358 } 366 359 if (Problem != null) { 367 foreach (ISingleObjectiveSelector selector in Selector s.OfType<ISingleObjectiveSelector>()) {360 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 368 361 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 369 362 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 385 378 } 386 379 private void ParameterizeComparisonFactorModifiers() { 387 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {380 foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) { 388 381 modifier.IndexParameter.ActualName = "Generations"; 389 382 modifier.EndIndexParameter.ActualName = MaximumGenerationsParameter.Name; … … 392 385 modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name; 393 386 modifier.ValueParameter.ActualName = "ComparisonFactor"; 394 }395 }396 private void UpdateSelectors() {397 ISelector oldSelector = SelectorParameter.Value;398 SelectorParameter.ValidValues.Clear();399 foreach (ISelector selector in Selectors.OrderBy(x => x.Name))400 SelectorParameter.ValidValues.Add(selector);401 402 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));403 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;404 405 if (oldSelector != null) {406 ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());407 if (selector != null) SelectorParameter.Value = selector;408 }409 }410 private void UpdateComparisonFactorModifiers() {411 IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;412 413 ComparisonFactorModifierParameter.ValidValues.Clear();414 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)415 ComparisonFactorModifierParameter.ValidValues.Add(modifier);416 417 if (oldModifier != null) {418 IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());419 if (mod != null) ComparisonFactorModifierParameter.Value = mod;420 387 } 421 388 } -
TabularUnified trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASA.cs ¶
r3673 r3689 206 206 set { VillageAnalyzerParameter.Value = value; } 207 207 } 208 private List<ISelector> selectors;209 private IEnumerable<ISelector> Selectors {210 get { return selectors; }211 }212 private List<IDiscreteDoubleValueModifier> comparisonFactorModifiers;213 208 private RandomCreator RandomCreator { 214 209 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 223 218 get { return (SASEGASAMainLoop)VillageProcessor.Successor; } 224 219 } 220 [Storable] 225 221 private BestAverageWorstQualityAnalyzer villageQualityAnalyzer; 222 [Storable] 226 223 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 224 [Storable] 227 225 private ValueAnalyzer villageSelectionPressureAnalyzer; 226 [Storable] 228 227 private ValueAnalyzer selectionPressureAnalyzer; 229 228 #endregion … … 280 279 solutionsCreator.Successor = null; 281 280 282 283 281 mainLoop.NumberOfVillagesParameter.ActualName = NumberOfVillagesParameter.Name; 284 282 mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; … … 299 297 mainLoop.Successor = null; 300 298 299 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 300 SelectorParameter.ValidValues.Add(selector); 301 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector")); 302 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector; 303 304 ParameterizeSelectors(); 305 306 foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) 307 ComparisonFactorModifierParameter.ValidValues.Add(modifier); 308 IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier")); 309 if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier; 310 ParameterizeComparisonFactorModifiers(); 311 312 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 313 villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 314 selectionPressureAnalyzer = new ValueAnalyzer(); 315 villageSelectionPressureAnalyzer = new ValueAnalyzer(); 316 ParameterizeAnalyzers(); 317 UpdateAnalyzers(); 318 301 319 Initialize(); 302 320 } … … 304 322 public override IDeepCloneable Clone(Cloner cloner) { 305 323 SASEGASA clone = (SASEGASA)base.Clone(cloner); 324 clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer); 325 clone.villageQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(villageQualityAnalyzer); 326 clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer); 327 clone.villageSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(villageSelectionPressureAnalyzer); 306 328 clone.Initialize(); 307 329 return clone; … … 390 412 [StorableHook(HookType.AfterDeserialization)] 391 413 private void Initialize() { 392 InitializeSelectors();393 InitializeAnalyzers();394 UpdateSelectors();395 UpdateAnalyzers();396 InitializeComparisonFactorModifiers();397 UpdateComparisonFactorModifiers();398 414 NumberOfVillagesParameter.ValueChanged += new EventHandler(NumberOfVillagesParameter_ValueChanged); 399 415 NumberOfVillages.ValueChanged += new EventHandler(NumberOfVillages_ValueChanged); … … 405 421 MaximumGenerations.ValueChanged += new EventHandler(MaximumGenerations_ValueChanged); 406 422 if (Problem != null) { 407 UpdateCrossovers();408 UpdateMutators();409 423 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 410 424 } … … 425 439 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 426 440 } 427 private void InitializeSelectors() {428 selectors = new List<ISelector>();429 selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));430 ParameterizeSelectors();431 }432 private void InitializeAnalyzers() {433 villageQualityAnalyzer = new BestAverageWorstQualityAnalyzer();434 qualityAnalyzer = new BestAverageWorstQualityAnalyzer();435 villageSelectionPressureAnalyzer = new ValueAnalyzer();436 selectionPressureAnalyzer = new ValueAnalyzer();437 ParameterizeAnalyzers();438 }439 private void InitializeComparisonFactorModifiers() {440 comparisonFactorModifiers = new List<IDiscreteDoubleValueModifier>();441 comparisonFactorModifiers.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));442 ParameterizeComparisonFactorModifiers();443 }444 441 private void ParameterizeSelectors() { 445 foreach (ISelector selector in Selector s) {442 foreach (ISelector selector in SelectorParameter.ValidValues) { 446 443 selector.CopySelected = new BoolValue(true); 447 444 selector.NumberOfSelectedSubScopesParameter.Value = null; … … 450 447 } 451 448 if (Problem != null) { 452 foreach (ISingleObjectiveSelector selector in Selector s.OfType<ISingleObjectiveSelector>()) {449 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 453 450 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 454 451 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 485 482 } 486 483 private void ParameterizeComparisonFactorModifiers() { 487 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers) {484 foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) { 488 485 modifier.IndexParameter.ActualName = "Reunifications"; 489 486 modifier.StartIndexParameter.Value = new IntValue(0); … … 492 489 modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name; 493 490 modifier.ValueParameter.ActualName = "ComparisonFactor"; 494 }495 }496 private void UpdateSelectors() {497 ISelector oldSelector = SelectorParameter.Value;498 SelectorParameter.ValidValues.Clear();499 foreach (ISelector selector in Selectors.OrderBy(x => x.Name))500 SelectorParameter.ValidValues.Add(selector);501 502 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));503 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;504 505 if (oldSelector != null) {506 ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());507 if (selector != null) SelectorParameter.Value = selector;508 }509 }510 private void UpdateComparisonFactorModifiers() {511 IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;512 513 ComparisonFactorModifierParameter.ValidValues.Clear();514 foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)515 ComparisonFactorModifierParameter.ValidValues.Add(modifier);516 517 if (oldModifier != null) {518 IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());519 if (mod != null) ComparisonFactorModifierParameter.Value = mod;520 491 } 521 492 }
Note: See TracChangeset
for help on using the changeset viewer.