Changeset 15070
- Timestamp:
- 06/27/17 13:54:55 (7 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r14774 r15070 251 251 [StorableHook(HookType.AfterDeserialization)] 252 252 private void AfterDeserialization() { 253 // BackwardsCompatibility3.3 254 #region Backwards compatible code, remove with 3.4 255 var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>; 256 if (optionalMutatorParameter != null) { 257 Parameters.Remove(optionalMutatorParameter); 258 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 259 foreach (var m in optionalMutatorParameter.ValidValues) 260 MutatorParameter.ValidValues.Add(m); 261 if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior 262 else Mutator = optionalMutatorParameter.Value; 263 optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared 264 } 265 #endregion 253 266 Initialize(); 254 267 } … … 284 297 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 285 298 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 286 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));299 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 287 300 Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 288 301 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); … … 690 703 } 691 704 private void UpdateMutators() { 692 var oldMutator = MutatorParameter.Value;705 IManipulator oldMutator = MutatorParameter.Value; 693 706 MutatorParameter.ValidValues.Clear(); 694 foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) { 707 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 708 709 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) { 695 710 ParameterizeStochasticOperatorForLayer(mutator); 696 711 MutatorParameter.ValidValues.Add(mutator); 697 712 } 713 698 714 if (oldMutator != null) { 699 var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType()); 700 if (mutator != null) 701 MutatorParameter.Value = mutator; 702 } 715 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 716 if (mutator != null) MutatorParameter.Value = mutator; 717 else oldMutator = null; 718 } 719 720 if (oldMutator == null && defaultMutator != null) 721 MutatorParameter.Value = defaultMutator; 703 722 } 704 723 private void UpdateTerminators() { -
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithm.cs
r14185 r15070 298 298 [StorableHook(HookType.AfterDeserialization)] 299 299 private void AfterDeserialization() { 300 // BackwardsCompatibility3.3 301 #region Backwards compatible code, remove with 3.4 302 var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>; 303 if (optionalMutatorParameter != null) { 304 Parameters.Remove(optionalMutatorParameter); 305 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 306 foreach (var m in optionalMutatorParameter.ValidValues) 307 MutatorParameter.ValidValues.Add(m); 308 if (optionalMutatorParameter.Value == null) MutationProbability = 0; // to guarantee that the old configuration results in the same behavior 309 else Mutator = optionalMutatorParameter.Value; 310 optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared 311 } 312 #endregion 300 313 Initialize(); 301 314 } … … 334 347 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 335 348 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 336 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));349 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 337 350 Parameters.Add(new FixedValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 338 351 Parameters.Add(new FixedValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); … … 755 768 } 756 769 private void UpdateMutators() { 757 var oldMutator = MutatorParameter.Value;770 IManipulator oldMutator = MutatorParameter.Value; 758 771 MutatorParameter.ValidValues.Clear(); 759 foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) { 772 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 773 774 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) { 760 775 ParameterizeStochasticOperatorForLayer(mutator); 761 776 MutatorParameter.ValidValues.Add(mutator); 762 777 } 778 763 779 if (oldMutator != null) { 764 var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType()); 765 if (mutator != null) 766 MutatorParameter.Value = mutator; 767 } 780 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 781 if (mutator != null) MutatorParameter.Value = mutator; 782 else oldMutator = null; 783 } 784 785 if (oldMutator == null && defaultMutator != null) 786 MutatorParameter.Value = defaultMutator; 768 787 } 769 788 private void UpdateTerminators() {
Note: See TracChangeset
for help on using the changeset viewer.