Changeset 15238 for stable/HeuristicLab.Algorithms.GeneticAlgorithm
- Timestamp:
- 07/13/17 17:46:58 (7 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15006-15008,15047,15049,15070,15107
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r14186 r15238 156 156 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 157 157 Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 158 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));158 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 159 159 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 160 160 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); … … 221 221 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true }); 222 222 } 223 var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>; 224 if (optionalMutatorParameter != null) { 225 Parameters.Remove(optionalMutatorParameter); 226 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 227 foreach (var m in optionalMutatorParameter.ValidValues) 228 MutatorParameter.ValidValues.Add(m); 229 if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior 230 else Mutator = optionalMutatorParameter.Value; 231 optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared 232 } 223 233 #endregion 224 234 … … 387 397 IManipulator oldMutator = MutatorParameter.Value; 388 398 MutatorParameter.ValidValues.Clear(); 399 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 400 389 401 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) 390 402 MutatorParameter.ValidValues.Add(mutator); 403 391 404 if (oldMutator != null) { 392 405 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 393 406 if (mutator != null) MutatorParameter.Value = mutator; 394 } 407 else oldMutator = null; 408 } 409 410 if (oldMutator == null && defaultMutator != null) 411 MutatorParameter.Value = defaultMutator; 395 412 } 396 413 private void UpdateAnalyzers() { -
stable/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs
r14186 r15238 211 211 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true }); 212 212 } 213 var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>; 214 if (optionalMutatorParameter != null) { 215 Parameters.Remove(optionalMutatorParameter); 216 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 217 foreach (var m in optionalMutatorParameter.ValidValues) 218 MutatorParameter.ValidValues.Add(m); 219 if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior 220 else Mutator = optionalMutatorParameter.Value; 221 optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared 222 } 213 223 #endregion 214 224 … … 240 250 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); 241 251 Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05))); 242 Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));252 Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions.")); 243 253 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 244 254 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); … … 551 561 IManipulator oldMutator = MutatorParameter.Value; 552 562 MutatorParameter.ValidValues.Clear(); 563 IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault(); 564 553 565 foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) { 554 566 ParameterizeStochasticOperatorForIsland(mutator); … … 558 570 IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); 559 571 if (mutator != null) MutatorParameter.Value = mutator; 560 } 572 else oldMutator = null; 573 } 574 575 if (oldMutator == null && defaultMutator != null) 576 MutatorParameter.Value = defaultMutator; 561 577 } 562 578 private void UpdateAnalyzers() {
Note: See TracChangeset
for help on using the changeset viewer.