- Timestamp:
- 06/27/17 13:54:55 (7 years ago)
- File:
-
- 1 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() {
Note: See TracChangeset
for help on using the changeset viewer.