Changeset 12271
- Timestamp:
- 03/31/15 13:18:59 (10 years ago)
- Location:
- branches/ALPS
- Files:
-
- 1 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithm.cs
r12270 r12271 131 131 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); 132 132 Parameters.Add(new ValueParameter<IntValue>("BatchSize", "Number of inner iterations before updates and analyzers are fired.", new IntValue(100)) { Hidden = true }); 133 AgeInheritance = new ReductionOperation(ReductionOperations.Min);134 133 135 134 var randomCreator = new RandomCreator(); … … 282 281 } 283 282 283 protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) { 284 switch (ageInheritance) { 285 case ALPS.AgeInheritance.Older: return ReductionOperations.Min; 286 case ALPS.AgeInheritance.Agerage: return ReductionOperations.Avg; 287 case ALPS.AgeInheritance.Younger: return ReductionOperations.Max; 288 default: throw new NotSupportedException("AgeInheritance " + ageInheritance + " is not supported."); 289 } 290 } 291 284 292 protected override void ParameterizeStochasticOperator(IOperator @operator) { 285 293 var stochasticOperator = @operator as IStochasticOperator; -
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithmMainOperator.cs
r12259 r12271 48 48 var mutator = new Placeholder() { Name = "Mutator (Placeholder)" }; 49 49 var ageReducer = new DataReducer() { Name = "Calculate EvalsCreated" }; 50 var lastMove Reducer = new DataReducer() { Name = "CalculateLastMove" };50 var lastMoveAssigner = new Assigner() { Name = "Set LastMove" }; 51 51 var subScopesRemover = new SubScopesRemover(); 52 52 var evaluator = new Placeholder() { Name = "Evaluator (Placeholder)" }; … … 71 71 72 72 ageReducer.ParameterToReduce.ActualName = "EvalsCreated"; 73 ageReducer.ReductionOperation.ActualName = "AgeInheritance ";73 ageReducer.ReductionOperation.ActualName = "AgeInheritanceReduction"; 74 74 ageReducer.ReductionOperation.Value = null; 75 75 ageReducer.TargetParameter.ActualName = "EvalsCreated"; 76 76 ageReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 77 ageReducer.Successor = lastMove Reducer;77 ageReducer.Successor = lastMoveAssigner; 78 78 79 lastMoveReducer.ParameterToReduce.ActualName = "LastMove"; 80 lastMoveReducer.ReductionOperation.ActualName = "AgeInheritance"; 81 lastMoveReducer.ReductionOperation.Value = null; 82 lastMoveReducer.TargetParameter.ActualName = "LastMove"; 83 lastMoveReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 84 lastMoveReducer.Successor = subScopesRemover; 79 lastMoveAssigner.LeftSideParameter.ActualName = "LastMove"; 80 lastMoveAssigner.RightSideParameter.ActualName = "EvaluatedSolutions"; 81 lastMoveAssigner.Successor = subScopesRemover; 85 82 86 83 subScopesRemover.Successor = evaluator; -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AgingScheme.cs
r12149 r12271 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using HeuristicLab.Data; 26 22 27 namespace HeuristicLab.Algorithms.ALPS { 28 /// <summary> 29 /// Defines the growth of age limits for the layers. 30 /// </summary> 23 31 public enum AgingScheme { 24 32 Linear, … … 27 35 Exponential 28 36 } 37 38 /// <summary> 39 /// Helper for calculating the age limits for a AgingScheme and a given AgeGap. 40 /// </summary> 41 public static class AgingSchemeCalculator { 42 public static IntArray CalculateAgeLimits(this AgingScheme scheme, int ageGap, int numberOfLayers) { 43 IEnumerable<int> schemeGenerator; 44 switch (scheme) { 45 case AgingScheme.Linear: schemeGenerator = LinearAgingScheme(); break; 46 case AgingScheme.Fibonacci: schemeGenerator = FibonacciAgingScheme(); break; 47 case AgingScheme.Polynomial: schemeGenerator = PolynomialAgingScheme(2); break; 48 case AgingScheme.Exponential: schemeGenerator = ExponentialAgingScheme(2); break; 49 default: throw new NotSupportedException("Aging Scheme " + scheme + " is not supported."); 50 } 51 52 return new IntArray(schemeGenerator.Select(a => a * ageGap).Take(numberOfLayers).ToArray()); 53 } 54 55 #region Scheme definitions 56 // 1 2 3 4 5 6 7 ... 57 private static IEnumerable<int> LinearAgingScheme() { 58 for (int i = 0; ; i++) 59 yield return i + 1; 60 } 61 // 1 2 3 5 8 13 21 ... 62 private static IEnumerable<int> FibonacciAgingScheme() { 63 for (int i = 1, next = 2, temp; ; temp = next, next = i + next, i = temp) 64 yield return i; 65 } 66 // (n^2): 1 2 4 9 16 25 36 ... 67 private static IEnumerable<int> PolynomialAgingScheme(double exp) { 68 yield return 1; 69 yield return 2; 70 for (int i = 2; ; i++) 71 yield return (int)Math.Pow(i, exp); 72 } 73 // 1 2 4 8 16 32 64 ... 74 private static IEnumerable<int> ExponentialAgingScheme(double @base) { 75 for (int i = 0; ; i++) 76 yield return (int)Math.Pow(@base, i); 77 } 78 #endregion 79 } 29 80 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Alps.cs
r12260 r12271 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Analysis; … … 36 35 37 36 namespace HeuristicLab.Algorithms.ALPS { 38 [Item("ALPS", " A base class for all ALPS-based algorithms.")]37 [Item("ALPS", "Base class for all ALPS-based algorithms.")] 39 38 [StorableClass] 40 39 public abstract class Alps : HeuristicOptimizationEngineAlgorithm, IStorableContent { … … 76 75 get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; } 77 76 } 78 private IValueParameter<ReductionOperation> AgeInheritanceParameter { 79 get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; } 77 private IValueParameter<EnumValue<AgeInheritance>> AgeInheritanceParameter { 78 get { return (IValueParameter<EnumValue<AgeInheritance>>)Parameters["AgeInheritance"]; } 79 } 80 private IValueParameter<ReductionOperation> AgeInheritanceReductionParameter { 81 get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritanceReduction"]; } 80 82 } 81 83 private IValueParameter<IntValue> MatingPoolRangeParameter { … … 118 120 set { AgeLimitsParameter.Value = value; } 119 121 } 120 public ReductionOperationAgeInheritance {122 public EnumValue<AgeInheritance> AgeInheritance { 121 123 get { return AgeInheritanceParameter.Value; } 122 124 set { AgeInheritanceParameter.Value = value; } 125 } 126 private ReductionOperation AgeInheritanceReduction { 127 get { return AgeInheritanceReductionParameter.Value; } 128 set { AgeInheritanceReductionParameter.Value = value; } 123 129 } 124 130 public IntValue MatingPoolRange { … … 168 174 Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(20))); 169 175 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new int[0])) { Hidden = true }); 170 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 }); 176 Parameters.Add(new ValueParameter<EnumValue<AgeInheritance>>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new EnumValue<AgeInheritance>(ALPS.AgeInheritance.Older))); 177 Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritanceReduction") { Hidden = true }); 171 178 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 }); 172 179 Parameters.Add(new ValueParameter<PercentValue>("MatingPoolSelectionPercentage", "Percentage of the previous layers used for creating a mating pool.", new PercentValue(1.0, restrictToUnitInterval: true)) { Hidden = true }); … … 175 182 layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 176 183 177 // Create Operator Graph 178 179 RecalculateAgeLimits(); 184 ParameterizeAgeLimits(); 185 ParameterizeAgeInheritanceReduction(); 180 186 181 187 ParameterizeAnalyzers(); … … 185 191 } 186 192 193 194 #region Events 187 195 public override void Prepare() { 188 196 if (Problem != null) … … 190 198 } 191 199 192 #region Events193 200 protected override void OnProblemChanged() { 194 201 base.OnProblemChanged(); … … 227 234 private void AgeGapParameter_ValueChanged(object sender, EventArgs e) { 228 235 AgeGap.ValueChanged += AgeGap_ValueChanged; 229 RecalculateAgeLimits();236 ParameterizeAgeLimits(); 230 237 } 231 238 private void AgeGap_ValueChanged(object sender, EventArgs e) { 232 RecalculateAgeLimits();239 ParameterizeAgeLimits(); 233 240 } 234 241 private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) { 235 242 AgingScheme.ValueChanged += AgingScheme_ValueChanged; 236 RecalculateAgeLimits();243 ParameterizeAgeLimits(); 237 244 } 238 245 private void AgingScheme_ValueChanged(object sender, EventArgs e) { 239 RecalculateAgeLimits();246 ParameterizeAgeLimits(); 240 247 } 241 248 private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) { 242 249 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 243 RecalculateAgeLimits();250 ParameterizeAgeLimits(); 244 251 } 245 252 private void NumberOfLayers_ValueChanged(object sender, EventArgs e) { 246 RecalculateAgeLimits(); 253 ParameterizeAgeLimits(); 254 } 255 private void AgeInheritanceParameter_ValueChanged(object sender, EventArgs e) { 256 AgeInheritance.ValueChanged += AgeInheritance_ValueChanged; 257 ParameterizeAgeInheritanceReduction(); 258 } 259 private void AgeInheritance_ValueChanged(object sender, EventArgs e) { 260 ParameterizeAgeInheritanceReduction(); 247 261 } 248 262 private void AnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) { … … 278 292 NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged; 279 293 NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged; 294 AgeInheritanceParameter.ValueChanged += AgeInheritanceParameter_ValueChanged; 295 AgeInheritance.ValueChanged += AgeInheritance_ValueChanged; 280 296 Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded; 281 297 LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded; … … 307 323 } 308 324 } 325 326 private void ParameterizeAgeInheritanceReduction() { 327 AgeInheritanceReduction.Value = GetAgeInheritanceReduction(AgeInheritance.Value); 328 } 329 protected abstract ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance); 330 private void ParameterizeAgeLimits() { 331 var scheme = AgingScheme.Value; 332 int ageGap = AgeGap.Value; 333 int numberOfLayers = NumberOfLayers.Value; 334 AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers); 335 } 309 336 protected virtual void ParameterizeStochasticOperator(IOperator @operator) { 310 337 var stochasticOperator = @operator as IStochasticOperator; … … 338 365 } 339 366 #endregion 340 341 private void RecalculateAgeLimits() {342 var scheme = AgingScheme.Value;343 int ageGap = AgeGap.Value;344 int numberOfLayers = NumberOfLayers.Value;345 AgeLimits = AgingSchemeCalculator.CalculateAgeLimits(scheme, ageGap, numberOfLayers);346 }347 367 } 348 368 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r12260 r12271 279 279 } 280 280 } 281 282 protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) { 283 switch (ageInheritance) { 284 case ALPS.AgeInheritance.Older: return ReductionOperations.Max; 285 case ALPS.AgeInheritance.Agerage: return ReductionOperations.Avg; 286 case ALPS.AgeInheritance.Younger: return ReductionOperations.Min; 287 default: throw new NotSupportedException("AgeInheritance " + ageInheritance + " is not supported."); 288 } 289 } 281 290 #endregion 282 291 -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r12197 r12271 246 246 ageCalculator.TargetParameter.ActualName = "Age"; 247 247 ageCalculator.ReductionOperation.Value = null; 248 ageCalculator.ReductionOperation.ActualName = "AgeInheritance ";248 ageCalculator.ReductionOperation.ActualName = "AgeInheritanceReduction"; 249 249 ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 250 250 ageCalculator.Successor = crossoverSuccessor; -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r12119 r12271 132 132 </ItemGroup> 133 133 <ItemGroup> 134 <Compile Include="Ag ingSchemeCalculator.cs" />134 <Compile Include="AgeInheritance.cs" /> 135 135 <Compile Include="Alps.cs" /> 136 136 <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
Note: See TracChangeset
for help on using the changeset viewer.