Changeset 12531
- Timestamp:
- 06/29/15 16:27:22 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Alps.cs
r12271 r12531 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Analysis; … … 87 88 get { return (IValueLookupParameter<PercentValue>)Parameters["MatingPoolSelectionPercentage"]; } 88 89 } 90 private IValueParameter<MultiTerminator> TerminatorParameter { 91 get { return (IValueParameter<MultiTerminator>)Parameters["Terminator"]; } 92 } 89 93 #endregion 90 94 … … 135 139 get { return MatingPoolSelectionPercentageParameter.Value; } 136 140 set { MatingPoolSelectionPercentageParameter.Value = value; } 141 } 142 public MultiTerminator Terminators { 143 get { return TerminatorParameter.Value; } 137 144 } 138 145 #endregion … … 152 159 [Storable] 153 160 private BestAverageWorstQualityAnalyzer layerQualityAnalyzer; 161 #endregion 162 #region Preconfigured Terminators 163 [Storable] 164 private ComparisonTerminator<IntValue> evaluationsTerminator; 165 [Storable] 166 private SingleObjectiveQualityTerminator qualityTerminator; 167 [Storable] 168 private ExecutionTimeTerminator executionTimeTerminator; 154 169 #endregion 155 170 … … 161 176 qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); 162 177 layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer); 178 evaluationsTerminator = cloner.Clone(original.evaluationsTerminator); 179 qualityTerminator = cloner.Clone(original.qualityTerminator); 180 executionTimeTerminator = cloner.Clone(original.executionTimeTerminator); 163 181 Initialize(); 164 182 } … … 178 196 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 }); 179 197 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 }); 198 Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria which sould be checked.", new MultiTerminator())); 180 199 181 200 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); … … 187 206 ParameterizeAnalyzers(); 188 207 UpdateAnalyzers(); 208 209 CreateTerminators(); 210 ParameterizeTerminators(); 211 UpdateTerminators(); 189 212 190 213 Initialize(); … … 206 229 ParameterizeSolutionsCreator(); 207 230 ParameterizeAnalyzers(); 231 ParameterizeTerminators(); 208 232 UpdateAnalyzers(); 233 UpdateTerminators(); 209 234 Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 210 235 } 236 protected override void RegisterProblemEvents() { 237 base.RegisterProblemEvents(); 238 var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter; 239 if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged); 240 } 241 protected override void DeregisterProblemEvents() { 242 var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter; 243 if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged); 244 base.DeregisterProblemEvents(); 245 } 246 211 247 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 212 248 base.Problem_SolutionCreatorChanged(sender, e); … … 226 262 ParameterizeStochasticOperator(@operator); 227 263 UpdateAnalyzers(); 264 UpdateTerminators(); 228 265 base.Problem_OperatorsChanged(sender, e); 229 266 } 230 267 protected virtual void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 231 268 ParameterizeAnalyzers(); 269 } 270 private void MaximizationParameter_ValueChanged(object sender, EventArgs e) { 271 ParameterizeTerminators(); 272 } 273 private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) { 274 ParameterizeTerminators(); 232 275 } 233 276 … … 296 339 Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded; 297 340 LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded; 341 qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged); 298 342 } 299 343 private void ParameterizeSolutionsCreator() { … … 323 367 } 324 368 } 325 369 private void ParameterizeTerminators() { 370 qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem); 371 } 326 372 private void ParameterizeAgeInheritanceReduction() { 327 373 AgeInheritanceReduction.Value = GetAgeInheritanceReduction(AgeInheritance.Value); … … 364 410 } 365 411 } 412 protected virtual void UpdateTerminators() { 413 var newTerminators = new Dictionary<ITerminator, bool> { 414 {evaluationsTerminator, Terminators.Operators.Contains(evaluationsTerminator) && Terminators.Operators.ItemChecked(evaluationsTerminator)}, 415 {qualityTerminator, Terminators.Operators.Contains(qualityTerminator) && Terminators.Operators.ItemChecked(qualityTerminator) }, 416 {executionTimeTerminator, Terminators.Operators.Contains(executionTimeTerminator) && Terminators.Operators.ItemChecked(executionTimeTerminator)} 417 }; 418 if (Problem != null) { 419 foreach (var terminator in Problem.Operators.OfType<ITerminator>()) 420 newTerminators.Add(terminator, !Terminators.Operators.Contains(terminator) || Terminators.Operators.ItemChecked(terminator)); 421 } 422 423 Terminators.Operators.Clear(); 424 425 foreach (var newTerminator in newTerminators) 426 Terminators.Operators.Add(newTerminator.Key, newTerminator.Value); 427 } 428 protected virtual void CreateTerminators() { 429 evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" }; 430 qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" }; 431 executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5))); 432 } 366 433 #endregion 367 434 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r12271 r12531 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Common; … … 43 44 get { return (IValueParameter<IntArray>)Parameters["PopulationSize"]; } 44 45 } 45 private IValueParameter<IntValue> MaximumGenerationsParameter {46 get { return (IValueParameter<IntValue>)Parameters["MaximumGenerations"]; }47 }48 46 public IConstrainedValueParameter<ISelector> SelectorParameter { 49 47 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } … … 74 72 set { PopulationSizeParameter.Value = value; } 75 73 } 76 public IntValue MaximumGenerations {77 get { return MaximumGenerationsParameter.Value; }78 set { MaximumGenerationsParameter.Value = value; }79 }80 81 74 public ISelector Selector { 82 75 get { return SelectorParameter.Value; } … … 112 105 } 113 106 #endregion 107 108 [Storable] 109 private ComparisonTerminator<IntValue> generationsTerminator; 114 110 115 111 [StorableConstructor] … … 118 114 private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner) 119 115 : base(original, cloner) { 116 generationsTerminator = cloner.Clone(original.generationsTerminator); 120 117 Initialize(); 121 118 } … … 126 123 : base() { 127 124 Parameters.Add(new ValueParameter<IntArray>("PopulationSize", "The size of the population of solutions each layer.", new IntArray(new[] { 100 }))); 128 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));129 125 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 130 126 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); … … 274 270 @operator.IterationsParameter.ActualName = "Generations"; 275 271 @operator.IterationsParameter.Hidden = true; 276 @operator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;272 @operator.MaximumIterationsParameter.ActualName = generationsTerminator.ThresholdParameter.Name; 277 273 @operator.MaximumIterationsParameter.Hidden = true; 278 274 } … … 291 287 292 288 #region Updates 289 protected override void UpdateTerminators() { 290 var newTerminators = new Dictionary<ITerminator, bool> { 291 {generationsTerminator, !Terminators.Operators.Contains(generationsTerminator) || Terminators.Operators.ItemChecked(generationsTerminator)}, 292 }; 293 294 base.UpdateTerminators(); 295 296 foreach (var newTerminator in newTerminators) 297 Terminators.Operators.Insert(0, newTerminator.Key, newTerminator.Value); 298 } 299 protected override void CreateTerminators() { 300 generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" }; 301 base.CreateTerminators(); 302 } 293 303 private void UpdateCrossovers() { 294 304 var oldCrossover = CrossoverParameter.Value; -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r12271 r12531 100 100 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 101 101 var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" }; 102 var generationsComparator = new Comparator() { Name = "Generations >= MaximumGenerations" }; 103 var terminateBranch = new ConditionalBranch() { Name = "Terminate?" }; 102 var termination = new TerminationOperator(); 104 103 105 104 OperatorGraph.InitialOperator = variableCreator; … … 165 164 166 165 analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; 167 analyzerPlaceholder.Successor = generationsComparator; 168 169 generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 170 generationsComparator.LeftSideParameter.ActualName = "Generations"; 171 generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name; 172 generationsComparator.ResultParameter.ActualName = "TerminateGenerations"; 173 generationsComparator.Successor = terminateBranch; 174 175 terminateBranch.ConditionParameter.ActualName = "TerminateGenerations"; 176 terminateBranch.FalseBranch = matingPoolPreProcessor; 166 analyzerPlaceholder.Successor = termination; 167 168 termination.ContinueBranch = matingPoolPreProcessor; 177 169 } 178 170
Note: See TracChangeset
for help on using the changeset viewer.