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:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs

    r14186 r15238  
    280280      if (!Parameters.ContainsKey("FillPopulationWithParents"))
    281281        Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true });
     282
     283      var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
     284      if (optionalMutatorParameter != null) {
     285        Parameters.Remove(optionalMutatorParameter);
     286        Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     287        foreach (var m in optionalMutatorParameter.ValidValues)
     288          MutatorParameter.ValidValues.Add(m);
     289        if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior
     290        else Mutator = optionalMutatorParameter.Value;
     291        optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
     292      }
    282293      #endregion
    283294
     
    311322      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    312323      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    313       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     324      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    314325      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    315326      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 });
     
    642653      IManipulator oldMutator = MutatorParameter.Value;
    643654      MutatorParameter.ValidValues.Clear();
     655      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     656
    644657      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    645658        MutatorParameter.ValidValues.Add(mutator);
     659
    646660      if (oldMutator != null) {
    647661        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    648662        if (mutator != null) MutatorParameter.Value = mutator;
    649       }
     663        else oldMutator = null;
     664      }
     665
     666      if (oldMutator == null && defaultMutator != null)
     667        MutatorParameter.Value = defaultMutator;
    650668    }
    651669    private void UpdateAnalyzers() {
Note: See TracChangeset for help on using the changeset viewer.