private void UpdateMutators() { IManipulator oldMutator = MutatorParameter.Value; MutatorParameter.ValidValues.Clear(); foreach (IManipulator mutator in Problem.Operators.OfType <IManipulator>().OrderBy(x => x.Name)) { MutatorParameter.ValidValues.Add(mutator); } if (oldMutator != null) { IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType()); if (mutator != null) { MutatorParameter.Value = mutator; } } else if (MutatorParameter.ValidValues.Count > 0 && Problem.Operators.OfType <ISelfAdaptiveManipulator>().Count() > 0) { ISelfAdaptiveManipulator mutator = Problem.Operators.OfType <ISelfAdaptiveManipulator>().First(); if (mutator != null) { MutatorParameter.Value = mutator; } } }
private void UpdateStrategyParameterOperators() { IStrategyParameterCreator oldStrategyCreator = StrategyParameterCreator; IStrategyParameterCrossover oldStrategyCrossover = StrategyParameterCrossover; IStrategyParameterManipulator oldStrategyManipulator = StrategyParameterManipulator; ClearStrategyParameterOperators(); ISelfAdaptiveManipulator manipulator = (Mutator as ISelfAdaptiveManipulator); if (manipulator != null) { var operators = Problem.Operators.OfType <IOperator>().Where(x => manipulator.StrategyParameterType.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name); foreach (IStrategyParameterCreator strategyCreator in operators.OfType <IStrategyParameterCreator>()) { StrategyParameterCreatorParameter.ValidValues.Add(strategyCreator); } foreach (IStrategyParameterCrossover strategyRecombinator in operators.OfType <IStrategyParameterCrossover>()) { StrategyParameterCrossoverParameter.ValidValues.Add(strategyRecombinator); } foreach (IStrategyParameterManipulator strategyManipulator in operators.OfType <IStrategyParameterManipulator>()) { StrategyParameterManipulatorParameter.ValidValues.Add(strategyManipulator); } if (StrategyParameterCrossoverParameter.ValidValues.Count == 0) { RecombinatorParameter.ValidValues.Clear(); // if there is no strategy parameter crossover, there can be no crossover when the mutation operator needs strategy parameters } if (oldStrategyCreator != null) { IStrategyParameterCreator tmp1 = StrategyParameterCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCreator.GetType()); if (tmp1 != null) { StrategyParameterCreator = tmp1; } } else if (StrategyParameterCreatorParameter.ValidValues.Count > 0) { StrategyParameterCreator = StrategyParameterCreatorParameter.ValidValues.First(); } if (oldStrategyCrossover != null) { IStrategyParameterCrossover tmp2 = StrategyParameterCrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyCrossover.GetType()); if (tmp2 != null) { StrategyParameterCrossover = tmp2; } } else if (StrategyParameterCrossoverParameter.ValidValues.Count > 0) { StrategyParameterCrossover = StrategyParameterCrossoverParameter.ValidValues.First(); } if (oldStrategyManipulator != null) { IStrategyParameterManipulator tmp3 = StrategyParameterManipulatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldStrategyManipulator.GetType()); if (tmp3 != null) { StrategyParameterManipulator = tmp3; } } else if (StrategyParameterManipulatorParameter.ValidValues.Count > 0) { StrategyParameterManipulator = StrategyParameterManipulatorParameter.ValidValues.First(); } } }