Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/17 17:46:58 (7 years ago)
Author:
mkommend
Message:

#2792: Merged r15006:r15008, r15047, r15049, r15070, r15107 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r14186 r15238  
    156156      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    157157      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."));
    159159      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    160160      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 });
     
    221221        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 });
    222222      }
     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      }
    223233      #endregion
    224234
     
    387397      IManipulator oldMutator = MutatorParameter.Value;
    388398      MutatorParameter.ValidValues.Clear();
     399      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     400
    389401      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    390402        MutatorParameter.ValidValues.Add(mutator);
     403
    391404      if (oldMutator != null) {
    392405        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    393406        if (mutator != null) MutatorParameter.Value = mutator;
    394       }
     407        else oldMutator = null;
     408      }
     409
     410      if (oldMutator == null && defaultMutator != null)
     411        MutatorParameter.Value = defaultMutator;
    395412    }
    396413    private void UpdateAnalyzers() {
  • stable/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs

    r14186 r15238  
    211211        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 });
    212212      }
     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      }
    213223      #endregion
    214224
     
    240250      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    241251      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."));
    243253      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    244254      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 });
     
    551561      IManipulator oldMutator = MutatorParameter.Value;
    552562      MutatorParameter.ValidValues.Clear();
     563      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     564
    553565      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
    554566        ParameterizeStochasticOperatorForIsland(mutator);
     
    558570        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    559571        if (mutator != null) MutatorParameter.Value = mutator;
    560       }
     572        else oldMutator = null;
     573      }
     574
     575      if (oldMutator == null && defaultMutator != null)
     576        MutatorParameter.Value = defaultMutator;
    561577    }
    562578    private void UpdateAnalyzers() {
Note: See TracChangeset for help on using the changeset viewer.