Changeset 12531 for branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Alps.cs
- Timestamp:
- 06/29/15 16:27:22 (9 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.