Ignore:
Timestamp:
06/27/17 13:54:55 (2 years ago)
Author:
abeham
Message:

#2792: adapted ALPS and ALPS-OS

File:
1 edited

Legend:

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

    r14774 r15070  
    251251    [StorableHook(HookType.AfterDeserialization)]
    252252    private void AfterDeserialization() {
     253      // BackwardsCompatibility3.3
     254      #region Backwards compatible code, remove with 3.4
     255      var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
     256      if (optionalMutatorParameter != null) {
     257        Parameters.Remove(optionalMutatorParameter);
     258        Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     259        foreach (var m in optionalMutatorParameter.ValidValues)
     260          MutatorParameter.ValidValues.Add(m);
     261        if (optionalMutatorParameter.Value == null) MutationProbability.Value = 0; // to guarantee that the old configuration results in the same behavior
     262        else Mutator = optionalMutatorParameter.Value;
     263        optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
     264      }
     265      #endregion
    253266      Initialize();
    254267    }
     
    284297      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    285298      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    286       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     299      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    287300      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    288301      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
     
    690703    }
    691704    private void UpdateMutators() {
    692       var oldMutator = MutatorParameter.Value;
     705      IManipulator oldMutator = MutatorParameter.Value;
    693706      MutatorParameter.ValidValues.Clear();
    694       foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
     707      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     708
     709      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
    695710        ParameterizeStochasticOperatorForLayer(mutator);
    696711        MutatorParameter.ValidValues.Add(mutator);
    697712      }
     713
    698714      if (oldMutator != null) {
    699         var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
    700         if (mutator != null)
    701           MutatorParameter.Value = mutator;
    702       }
     715        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
     716        if (mutator != null) MutatorParameter.Value = mutator;
     717        else oldMutator = null;
     718      }
     719
     720      if (oldMutator == null && defaultMutator != null)
     721        MutatorParameter.Value = defaultMutator;
    703722    }
    704723    private void UpdateTerminators() {
Note: See TracChangeset for help on using the changeset viewer.