Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15070


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

#2792: adapted ALPS and ALPS-OS

Location:
trunk/sources/HeuristicLab.Algorithms.ALPS/3.3
Files:
2 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() {
  • trunk/sources/HeuristicLab.Algorithms.ALPS/3.3/AlpsOffspringSelectionGeneticAlgorithm.cs

    r14185 r15070  
    298298    [StorableHook(HookType.AfterDeserialization)]
    299299    private void AfterDeserialization() {
     300      // BackwardsCompatibility3.3
     301      #region Backwards compatible code, remove with 3.4
     302      var optionalMutatorParameter = MutatorParameter as OptionalConstrainedValueParameter<IManipulator>;
     303      if (optionalMutatorParameter != null) {
     304        Parameters.Remove(optionalMutatorParameter);
     305        Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     306        foreach (var m in optionalMutatorParameter.ValidValues)
     307          MutatorParameter.ValidValues.Add(m);
     308        if (optionalMutatorParameter.Value == null) MutationProbability = 0; // to guarantee that the old configuration results in the same behavior
     309        else Mutator = optionalMutatorParameter.Value;
     310        optionalMutatorParameter.ValidValues.Clear(); // to avoid dangling references to the old parameter its valid values are cleared
     311      }
     312      #endregion
    300313      Initialize();
    301314    }
     
    334347      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    335348      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    336       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     349      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    337350      Parameters.Add(new FixedValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    338351      Parameters.Add(new FixedValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
     
    755768    }
    756769    private void UpdateMutators() {
    757       var oldMutator = MutatorParameter.Value;
     770      IManipulator oldMutator = MutatorParameter.Value;
    758771      MutatorParameter.ValidValues.Clear();
    759       foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
     772      IManipulator defaultMutator = Problem.Operators.OfType<IManipulator>().FirstOrDefault();
     773
     774      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
    760775        ParameterizeStochasticOperatorForLayer(mutator);
    761776        MutatorParameter.ValidValues.Add(mutator);
    762777      }
     778
    763779      if (oldMutator != null) {
    764         var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
    765         if (mutator != null)
    766           MutatorParameter.Value = mutator;
    767       }
     780        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
     781        if (mutator != null) MutatorParameter.Value = mutator;
     782        else oldMutator = null;
     783      }
     784
     785      if (oldMutator == null && defaultMutator != null)
     786        MutatorParameter.Value = defaultMutator;
    768787    }
    769788    private void UpdateTerminators() {
Note: See TracChangeset for help on using the changeset viewer.