Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12040


Ignore:
Timestamp:
02/19/15 13:20:59 (9 years ago)
Author:
pfleck
Message:

#2269
Introduced a parameter to adjust the range of layers used for creating a mating pool.

Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
2 edited

Legend:

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

    r12035 r12040  
    8787      get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; }
    8888    }
     89    private IValueParameter<IntValue> MatingPoolRangeParameter {
     90      get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
     91    }
    8992    public IConstrainedValueParameter<ISelector> SelectorParameter {
    9093      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
     
    152155      get { return AgeInheritanceParameter.Value; }
    153156      set { AgeInheritanceParameter.Value = value; }
     157    }
     158    public IntValue MatingPoolRange {
     159      get { return MatingPoolRangeParameter.Value; }
     160      set { MatingPoolRangeParameter.Value = value; }
    154161    }
    155162    public ISelector Selector {
     
    222229      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 5, 20, 45, 80, 125 })) { Hidden = true });
    223230      Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true });
     231      Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true });
    224232      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    225233      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs

    r12018 r12040  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     25using HeuristicLab.Data;
    2426using HeuristicLab.Operators;
     27using HeuristicLab.Parameters;
    2528using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2629
     
    2932  [StorableClass]
    3033  public sealed class MatingPoolCreator : SingleSuccessorOperator {
     34
     35    private ILookupParameter<IntValue> MatingPoolRangeParameter {
     36      get { return (ILookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
     37    }
    3138
    3239    [StorableConstructor]
     
    4047    public MatingPoolCreator()
    4148      : base() {
     49      Parameters.Add(new LookupParameter<IntValue>("MatingPoolRange"));
    4250    }
    4351
    4452    public override IOperation Apply() {
    45       var subPopulations = ExecutionContext.Scope.SubScopes;
     53      var layers = ExecutionContext.Scope.SubScopes;
     54      int range = MatingPoolRangeParameter.ActualValue.Value;
    4655
    47       for (int i = subPopulations.Count - 1; i > 0; i--) {
    48         var currentSubPopulation = subPopulations[i].SubScopes;
    49         var prevSubPopulation = subPopulations[i - 1].SubScopes;
    50 
    51         foreach (var individual in prevSubPopulation)
    52           currentSubPopulation.Add((IScope)individual.Clone(new Cloner()));
     56      for (int layer = layers.Count - 1; layer > 0; layer--) {
     57        var layerScope = layers[layer];
     58        for (int n = 1; (n <= range) && (layer - n >= 0); n++) {
     59          var prevLayerScope = layers[layer - n];
     60          foreach (var individual in prevLayerScope.SubScopes) {
     61            layerScope.SubScopes.Add((IScope)individual.Clone(new Cloner()));
     62          }
     63        }
    5364      }
    5465
Note: See TracChangeset for help on using the changeset viewer.