Changeset 12040
- Timestamp:
- 02/19/15 13:20:59 (10 years ago)
- 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 87 87 get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; } 88 88 } 89 private IValueParameter<IntValue> MatingPoolRangeParameter { 90 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 91 } 89 92 public IConstrainedValueParameter<ISelector> SelectorParameter { 90 93 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } … … 152 155 get { return AgeInheritanceParameter.Value; } 153 156 set { AgeInheritanceParameter.Value = value; } 157 } 158 public IntValue MatingPoolRange { 159 get { return MatingPoolRangeParameter.Value; } 160 set { MatingPoolRangeParameter.Value = value; } 154 161 } 155 162 public ISelector Selector { … … 222 229 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 5, 20, 45, 80, 125 })) { Hidden = true }); 223 230 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 }); 224 232 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 225 233 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs
r12018 r12040 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 24 26 using HeuristicLab.Operators; 27 using HeuristicLab.Parameters; 25 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 29 … … 29 32 [StorableClass] 30 33 public sealed class MatingPoolCreator : SingleSuccessorOperator { 34 35 private ILookupParameter<IntValue> MatingPoolRangeParameter { 36 get { return (ILookupParameter<IntValue>)Parameters["MatingPoolRange"]; } 37 } 31 38 32 39 [StorableConstructor] … … 40 47 public MatingPoolCreator() 41 48 : base() { 49 Parameters.Add(new LookupParameter<IntValue>("MatingPoolRange")); 42 50 } 43 51 44 52 public override IOperation Apply() { 45 var subPopulations = ExecutionContext.Scope.SubScopes; 53 var layers = ExecutionContext.Scope.SubScopes; 54 int range = MatingPoolRangeParameter.ActualValue.Value; 46 55 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 } 53 64 } 54 65
Note: See TracChangeset
for help on using the changeset viewer.