Changeset 3689
- Timestamp:
- 05/07/10 02:08:30 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs
r3673 r3689 185 185 set { IslandAnalyzerParameter.Value = value; } 186 186 } 187 private List<ISelector> selectors;188 private IEnumerable<ISelector> Selectors {189 get { return selectors; }190 }191 private List<ISelector> emigrantsSelectors;192 private List<IReplacer> immigrationReplacers;193 private List<IMigrator> migrators;194 187 private RandomCreator RandomCreator { 195 188 get { return (RandomCreator)OperatorGraph.InitialOperator; } … … 204 197 get { return (IslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; } 205 198 } 199 [Storable] 206 200 private BestAverageWorstQualityAnalyzer islandQualityAnalyzer; 201 [Storable] 207 202 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 208 203 #endregion … … 272 267 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 273 268 mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name; 274 275 269 mainLoop.Successor = null; 270 271 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 272 SelectorParameter.ValidValues.Add(selector); 273 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector")); 274 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector; 275 276 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) 277 EmigrantsSelectorParameter.ValidValues.Add(selector); 278 279 foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name)) 280 ImmigrationReplacerParameter.ValidValues.Add(replacer); 281 282 ParameterizeSelectors(); 283 284 foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name)) 285 MigratorParameter.ValidValues.Add(migrator); 286 287 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 288 islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 289 ParameterizeAnalyzers(); 290 UpdateAnalyzers(); 276 291 277 292 Initialize(); … … 280 295 public override IDeepCloneable Clone(Cloner cloner) { 281 296 IslandGeneticAlgorithm clone = (IslandGeneticAlgorithm)base.Clone(cloner); 297 clone.islandQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(islandQualityAnalyzer); 298 clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer); 282 299 clone.Initialize(); 283 300 return clone; … … 356 373 [StorableHook(HookType.AfterDeserialization)] 357 374 private void Initialize() { 358 InitializeSelectors();359 InitializeAnalyzers();360 UpdateSelectors();361 UpdateAnalyzers();362 InitializeMigrators();363 UpdateMigrators();364 375 PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged); 365 376 PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged); … … 369 380 Elites.ValueChanged += new EventHandler(Elites_ValueChanged); 370 381 if (Problem != null) { 371 UpdateCrossovers();372 UpdateMutators();373 382 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 374 383 } … … 388 397 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 389 398 } 390 private void InitializeSelectors() {391 selectors = new List<ISelector>();392 selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));393 emigrantsSelectors = new List<ISelector>();394 emigrantsSelectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));395 immigrationReplacers = new List<IReplacer>();396 immigrationReplacers.AddRange(ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name));397 ParameterizeSelectors();398 }399 private void InitializeAnalyzers() {400 islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();401 qualityAnalyzer = new BestAverageWorstQualityAnalyzer();402 ParameterizeAnalyzers();403 }404 private void InitializeMigrators() {405 migrators = new List<IMigrator>();406 migrators.AddRange(ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name));407 UpdateMigrators();408 }409 399 private void ParameterizeSelectors() { 410 foreach (ISelector selector in Selector s) {400 foreach (ISelector selector in SelectorParameter.ValidValues) { 411 401 selector.CopySelected = new BoolValue(true); 412 402 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value)); 413 403 ParameterizeStochasticOperator(selector); 414 404 } 415 foreach (ISelector selector in emigrantsSelectors) {405 foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) { 416 406 selector.CopySelected = new BoolValue(true); 417 407 selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value)); 418 408 ParameterizeStochasticOperator(selector); 419 409 } 420 foreach (IReplacer replacer in immigrationReplacers) {410 foreach (IReplacer replacer in ImmigrationReplacerParameter.ValidValues) { 421 411 ParameterizeStochasticOperator(replacer); 422 412 } 423 413 if (Problem != null) { 424 foreach (ISingleObjectiveSelector selector in Selector s.OfType<ISingleObjectiveSelector>()) {414 foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 425 415 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 426 416 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 427 417 } 428 foreach (ISingleObjectiveSelector selector in emigrantsSelectors.OfType<ISingleObjectiveSelector>()) {418 foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) { 429 419 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 430 420 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 431 421 } 432 foreach (ISingleObjectiveReplacer selector in immigrationReplacers.OfType<ISingleObjectiveReplacer>()) {422 foreach (ISingleObjectiveReplacer selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) { 433 423 selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 434 424 selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; … … 450 440 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 451 441 } 452 }453 private void UpdateSelectors() {454 ISelector oldSelector = SelectorParameter.Value;455 SelectorParameter.ValidValues.Clear();456 foreach (ISelector selector in Selectors.OrderBy(x => x.Name))457 SelectorParameter.ValidValues.Add(selector);458 459 ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));460 if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;461 462 if (oldSelector != null) {463 ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());464 if (selector != null) SelectorParameter.Value = selector;465 }466 467 oldSelector = EmigrantsSelector;468 EmigrantsSelectorParameter.ValidValues.Clear();469 foreach (ISelector selector in emigrantsSelectors)470 EmigrantsSelectorParameter.ValidValues.Add(selector);471 if (oldSelector != null) {472 ISelector selector = EmigrantsSelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());473 if (selector != null) EmigrantsSelectorParameter.Value = selector;474 }475 476 IReplacer oldReplacer = ImmigrationReplacerParameter.Value;477 ImmigrationReplacerParameter.ValidValues.Clear();478 foreach (IReplacer replacer in immigrationReplacers)479 ImmigrationReplacerParameter.ValidValues.Add(replacer);480 if (oldReplacer != null) {481 IReplacer replacer = ImmigrationReplacerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());482 if (replacer != null) ImmigrationReplacerParameter.Value = replacer;483 }484 }485 private void UpdateMigrators() {486 IMigrator oldMigrator = Migrator;487 MigratorParameter.ValidValues.Clear();488 foreach (IMigrator migrator in migrators)489 MigratorParameter.ValidValues.Add(migrator);490 if (oldMigrator != null) {491 IMigrator migrator = MigratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMigrator.GetType());492 if (migrator != null) MigratorParameter.Value = migrator;493 } else if (MigratorParameter.ValidValues.Count > 0) MigratorParameter.Value = MigratorParameter.ValidValues.First();494 442 } 495 443 private void UpdateCrossovers() { … … 519 467 Analyzer.Operators.Add(qualityAnalyzer); 520 468 if (Problem != null) { 521 /*foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {522 foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())523 param.Depth = 1;524 IslandAnalyzer.Operators.Add(analyzer);525 }*/526 469 foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) { 527 470 foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>()) -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r3669 r3689 126 126 get { return (LocalSearchMainLoop)SolutionsCreator.Successor; } 127 127 } 128 [Storable] 128 129 private BestAverageWorstQualityAnalyzer moveQualityAnalyzer; 129 130 #endregion … … 167 168 lsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 168 169 170 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 171 ParameterizeAnalyzers(); 172 UpdateAnalyzers(); 173 169 174 Initialize(); 170 175 } … … 172 177 public override IDeepCloneable Clone(Cloner cloner) { 173 178 LocalSearch clone = (LocalSearch)base.Clone(cloner); 179 clone.moveQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(moveQualityAnalyzer); 174 180 clone.Initialize(); 175 181 return clone; … … 257 263 [StorableHook(HookType.AfterDeserialization)] 258 264 private void Initialize() { 259 InitializeAnalyzers();260 UpdateAnalyzers();261 265 if (Problem != null) { 262 266 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 267 271 MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged); 268 272 MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged); 269 }270 private void InitializeAnalyzers() {271 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();272 ParameterizeAnalyzers();273 273 } 274 274 private void UpdateMoveGenerator() { -
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() { -
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 } -
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 } -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3671 r3689 136 136 get { return (SimulatedAnnealingMainLoop)SolutionsCreator.Successor; } 137 137 } 138 139 private List<IDiscreteDoubleValueModifier> annealingOperators; 140 private IEnumerable<IDiscreteDoubleValueModifier> AnnealingOperators { 141 get { return annealingOperators; } 142 } 138 [Storable] 143 139 private QualityAnalyzer qualityAnalyzer; 144 140 #endregion … … 186 182 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 187 183 184 foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) 185 AnnealingOperatorParameter.ValidValues.Add(op); 186 ParameterizeAnnealingOperators(); 187 188 qualityAnalyzer = new QualityAnalyzer(); 189 ParameterizeAnalyzers(); 190 UpdateAnalyzers(); 191 188 192 Initialize(); 189 193 } … … 191 195 public override IDeepCloneable Clone(Cloner cloner) { 192 196 SimulatedAnnealing clone = (SimulatedAnnealing)base.Clone(cloner); 197 clone.qualityAnalyzer = (QualityAnalyzer)cloner.Clone(qualityAnalyzer); 193 198 clone.Initialize(); 194 199 return clone; … … 276 281 [StorableHook(HookType.AfterDeserialization)] 277 282 private void Initialize() { 278 InitializeAnalyzers();279 UpdateAnalyzers();280 283 if (Problem != null) { 281 284 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 286 289 MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged); 287 290 MoveEvaluatorParameter.ValueChanged += new EventHandler(MoveEvaluatorParameter_ValueChanged); 288 InitializeAnnealingOperators();289 }290 private void InitializeAnnealingOperators() {291 annealingOperators = new List<IDiscreteDoubleValueModifier>();292 annealingOperators.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));293 ParameterizeAnnealingOperators();294 AnnealingOperatorParameter.ValidValues.Clear();295 foreach (IDiscreteDoubleValueModifier op in annealingOperators)296 AnnealingOperatorParameter.ValidValues.Add(op);297 }298 private void InitializeAnalyzers() {299 qualityAnalyzer = new QualityAnalyzer();300 ParameterizeAnalyzers();301 291 } 302 292 private void UpdateMoveGenerator() { … … 383 373 } 384 374 private void ParameterizeAnnealingOperators() { 385 foreach (IDiscreteDoubleValueModifier op in annealingOperators) {375 foreach (IDiscreteDoubleValueModifier op in AnnealingOperatorParameter.ValidValues) { 386 376 op.IndexParameter.ActualName = "Iterations"; 387 377 op.StartIndexParameter.Value = new IntValue(0); -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r3671 r3689 143 143 get { return (TabuSearchMainLoop)SolutionsCreator.Successor; } 144 144 } 145 [Storable] 145 146 private BestAverageWorstQualityAnalyzer moveQualityAnalyzer; 147 [Storable] 146 148 private TabuNeighborhoodAnalyzer tabuNeighborhoodAnalyzer; 147 149 #endregion … … 188 190 tsMainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 189 191 192 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 193 tabuNeighborhoodAnalyzer = new TabuNeighborhoodAnalyzer(); 194 ParameterizeAnalyzers(); 195 UpdateAnalyzers(); 196 190 197 Initialize(); 191 198 } … … 195 202 public override IDeepCloneable Clone(Cloner cloner) { 196 203 TabuSearch clone = (TabuSearch)base.Clone(cloner); 204 clone.moveQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(moveQualityAnalyzer); 205 clone.tabuNeighborhoodAnalyzer = (TabuNeighborhoodAnalyzer)cloner.Clone(tabuNeighborhoodAnalyzer); 197 206 clone.Initialize(); 198 207 return clone; … … 313 322 [StorableHook(HookType.AfterDeserialization)] 314 323 private void Initialize() { 315 InitializeAnalyzers();316 UpdateAnalyzers();317 324 if (Problem != null) { 318 325 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 325 332 TabuCheckerParameter.ValueChanged += new EventHandler(TabuCheckerParameter_ValueChanged); 326 333 SampleSizeParameter.NameChanged += new EventHandler(SampleSizeParameter_NameChanged); 327 }328 private void InitializeAnalyzers() {329 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();330 tabuNeighborhoodAnalyzer = new TabuNeighborhoodAnalyzer();331 ParameterizeAnalyzers();332 334 } 333 335 private void UpdateMoveGenerator() {
Note: See TracChangeset
for help on using the changeset viewer.