Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/23/17 15:39:35 (7 years ago)
Author:
abeham
Message:

#2792: adapted OSGA, Island-GA, Island-OSGA, and SASEGASA as well

  • added default crossover logic to SASEGASA
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r14185 r15049  
    228228      if (!Parameters.ContainsKey("FillPopulationWithParents"))
    229229        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 });
     230
     231      var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
     232      if (optionalMutatorParameter != null) {
     233        Parameters.Remove(optionalMutatorParameter);
     234        Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     235        foreach (var m in optionalMutatorParameter.ValidValues)
     236          MutatorParameter.ValidValues.Add(m);
     237        if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior
     238        else Mutator = optionalMutatorParameter.Value;
     239        optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
     240      }
    230241      #endregion
    231242
     
    250261      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    251262      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    252       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     263      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    253264      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    254265      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 });
     
    487498      IManipulator oldMutator = MutatorParameter.Value;
    488499      MutatorParameter.ValidValues.Clear();
     500      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     501
    489502      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    490503        MutatorParameter.ValidValues.Add(mutator);
     504
    491505      if (oldMutator != null) {
    492506        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    493507        if (mutator != null) MutatorParameter.Value = mutator;
    494       }
     508        else oldMutator = null;
     509      }
     510
     511      if (oldMutator == null && defaultMutator != null)
     512        MutatorParameter.Value = defaultMutator;
    495513    }
    496514    private void UpdateAnalyzers() {
Note: See TracChangeset for help on using the changeset viewer.