Changeset 15107


Ignore:
Timestamp:
07/01/17 22:36:00 (3 weeks ago)
Author:
abeham
Message:

#2792: also adapted NSGA-II

File:
1 edited

Legend:

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

    r14227 r15107  
    176176      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    177177      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    178       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     178      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    179179      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    180180      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     
    326326      if (!Parameters.ContainsKey("DominateOnEqualQualities"))
    327327        Parameters.Add(new FixedValueParameter<BoolValue>("DominateOnEqualQualities", "Flag which determines wether solutions with equal quality values should be treated as dominated.", new BoolValue(false)));
     328      var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
     329      if (optionalMutatorParameter != null) {
     330        Parameters.Remove(optionalMutatorParameter);
     331        Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     332        foreach (var m in optionalMutatorParameter.ValidValues)
     333          MutatorParameter.ValidValues.Add(m);
     334        if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior
     335        else Mutator = optionalMutatorParameter.Value;
     336        optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
     337      }
    328338      #endregion
    329339
     
    397407      IManipulator oldMutator = MutatorParameter.Value;
    398408      MutatorParameter.ValidValues.Clear();
     409      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
    399410      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    400411        MutatorParameter.ValidValues.Add(mutator);
     
    402413        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    403414        if (mutator != null) MutatorParameter.Value = mutator;
    404       }
     415        else oldMutator = null;
     416      }
     417      if (oldMutator == null && defaultMutator != null)
     418        MutatorParameter.Value = defaultMutator;
    405419    }
    406420    private void UpdateAnalyzers() {
Note: See TracChangeset for help on using the changeset viewer.