Changeset 13568 for branches/PerformanceComparison
- Timestamp:
- 01/26/16 09:00:20 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/IteratedAlgorithm.cs
r13564 r13568 61 61 } 62 62 63 public IValueParameter<DoubleValue> Target ValueParameter {64 get { return (IValueParameter<DoubleValue>)Parameters["Target Value"]; }63 public IValueParameter<DoubleValue> TargetQualityParameter { 64 get { return (IValueParameter<DoubleValue>)Parameters["TargetQuality"]; } 65 65 } 66 66 … … 131 131 RegisterAlgorithmEvents(); 132 132 AddAlgorithmAnalyzers(); 133 HandleAlgorithmMaximumEvaluationsChanged(); 134 HandleAlgorithmTargetQualityChanged(); 133 135 } 134 136 if (AlgorithmParameter.Value != algorithm) … … 152 154 var bestQuality = Results.ContainsKey(BestQualityResultName) ? ((DoubleValue)Results[BestQualityResultName].Value).Value 153 155 : (Maximization ? double.MinValue : double.MaxValue); 154 var targetValue = Target ValueParameter.Value != null ? TargetValueParameter.Value.Value156 var targetValue = TargetQualityParameter.Value != null ? TargetQualityParameter.Value.Value 155 157 : Maximization ? double.MaxValue : double.MinValue; 156 158 … … 180 182 Parameters.Add(new OptionalValueParameter<TimeSpanValue>("MaximumExecutionTime", "The maximum wall-clock time that the algorithm should run.")); 181 183 Parameters.Add(new OptionalValueParameter<IntValue>("MaximumEvaluations", "The maximum number of function evaluations that the algorithm should run.", new IntValue(100000000))); 182 Parameters.Add(new OptionalValueParameter<DoubleValue>("Target Value", "The target valuethat the algorithm should run for."));184 Parameters.Add(new OptionalValueParameter<DoubleValue>("TargetQuality", "The target quality that the algorithm should run for.")); 183 185 Parameters.Add(new FixedValueParameter<DoubleValue>("MoveCostPerSolution", "The amount of solution evaluation equivalents of a single move. Use 1 for a black-box scenario.", new DoubleValue(1))); 184 186 Parameters.Add(new FixedValueParameter<BoolValue>("StoreSolutionInRun", "Whether the solution data types should be kept in the run.")); … … 203 205 private void AfterDeserialization() { 204 206 algorithm = AlgorithmParameter.Value; 207 // BackwardsCompatibility3.3 208 #region Backwards compatible code, remove with 3.4 209 if (Parameters.ContainsKey("TargetValue")) { 210 var target = ((OptionalValueParameter<DoubleValue>)Parameters["TargetValue"]).Value; 211 Parameters.Remove("TargetValue"); 212 Parameters.Add(new OptionalValueParameter<DoubleValue>("TargetQuality", "The target quality that the algorithm should run for.", target)); 213 } 205 214 if (!Parameters.ContainsKey("Analyzer")) { 206 215 Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "Analyzers that should be called in addition to the default algorithm analyzers.", new MultiAnalyzer())); … … 222 231 } 223 232 } 233 if (bestSolutionAnalyzer == null) { 234 bestSolutionAnalyzer = new BestScopeSolutionAnalyzer(); 235 Analyzer.Operators.Add(bestSolutionAnalyzer, StoreSolutionInRun); 236 } 237 #endregion 224 238 RegisterEventHandlers(); 225 239 } … … 245 259 Algorithm.Stopped += Algorithm_Stopped; 246 260 Algorithm.ProblemChanged += Algorithm_ProblemChanged; 247 } 261 #region MaximumEvaluations 262 IParameter param; 263 if (Algorithm.Parameters.TryGetValue("MaximumEvaluations", out param)) { 264 var intFixedValueParam = (param as IFixedValueParameter<IntValue>); 265 if (intFixedValueParam != null) { 266 intFixedValueParam.Value.ValueChanged += AlgorithmMaximumEvaluationsOnValueChanged; 267 } else { 268 var intValueParam = (param as IValueParameter<IntValue>); 269 if (intValueParam != null) { 270 intValueParam.ValueChanged += AlgorithmMaximumEvaluationsParameterOnChanged; 271 if (intValueParam.Value != null) intValueParam.Value.ValueChanged += AlgorithmMaximumEvaluationsOnValueChanged; 272 } 273 } 274 } 275 #endregion 276 #region TargetQuality 277 if (Algorithm.Parameters.TryGetValue("TargetQuality", out param)) { 278 var intValueParam = (param as IValueParameter<IntValue>); 279 if (intValueParam != null) { 280 intValueParam.ValueChanged += AlgorithmTargetQualityParameterOnChanged; 281 if (intValueParam.Value != null) intValueParam.Value.ValueChanged += AlgorithmTargetQualityOnValueChanged; 282 } 283 } 284 #endregion 285 } 286 248 287 private void DeregisterAlgorithmEvents() { 249 288 Algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; … … 251 290 Algorithm.Stopped -= Algorithm_Stopped; 252 291 Algorithm.ProblemChanged -= Algorithm_ProblemChanged; 292 #region MaximumEvaluations 293 IParameter param; 294 if (Algorithm.Parameters.TryGetValue("MaximumEvaluations", out param)) { 295 var intFixedValueParam = (param as IFixedValueParameter<IntValue>); 296 if (intFixedValueParam != null) { 297 intFixedValueParam.Value.ValueChanged -= AlgorithmMaximumEvaluationsOnValueChanged; 298 } else { 299 var intValueParam = (param as IValueParameter<IntValue>); 300 if (intValueParam != null) { 301 intValueParam.ValueChanged -= AlgorithmMaximumEvaluationsParameterOnChanged; 302 if (intValueParam.Value != null) intValueParam.Value.ValueChanged -= AlgorithmMaximumEvaluationsOnValueChanged; 303 } 304 } 305 } 306 #endregion 307 #region TargetQuality 308 if (Algorithm.Parameters.TryGetValue("TargetQuality", out param)) { 309 var intValueParam = (param as IValueParameter<IntValue>); 310 if (intValueParam != null) { 311 intValueParam.ValueChanged -= AlgorithmTargetQualityParameterOnChanged; 312 if (intValueParam.Value != null) intValueParam.Value.ValueChanged -= AlgorithmTargetQualityOnValueChanged; 313 } 314 } 315 #endregion 253 316 } 254 317 #endregion … … 263 326 Analyzer.Operators.ItemsRemoved += AnalyzerOperatorsChanged; 264 327 Analyzer.Operators.ItemsReplaced += AnalyzerOperatorsChanged; 328 MaximumEvaluationsParameter.Value.ValueChanged += MaximumEvaluationsParameterOnValueChanged; 329 TargetQualityParameter.ValueChanged += TargetQualityParameterChanged; 330 if (TargetQualityParameter.Value != null) TargetQualityParameter.Value.ValueChanged += TargetQualityParameterOnValueChanged; 265 331 } 266 332 … … 516 582 var bkParam = ((ISingleObjectiveHeuristicOptimizationProblem)Problem).BestKnownQualityParameter as IValueParameter<DoubleValue>; 517 583 if (bkParam != null && bkParam.Value != null) 518 Target ValueParameter.Value = new DoubleValue(bkParam.Value.Value);584 TargetQualityParameter.Value = new DoubleValue(bkParam.Value.Value); 519 585 else if (bkParam != null && bkParam.Value == null) 520 Target ValueParameter.Value = null;586 TargetQualityParameter.Value = null; 521 587 } 522 588 … … 568 634 } 569 635 636 private void AlgorithmTargetQualityParameterOnChanged(object sender, EventArgs e) { 637 var doubleValueParam = (sender as IValueParameter<DoubleValue>); 638 if (doubleValueParam.Value != null) doubleValueParam.Value.ValueChanged += AlgorithmTargetQualityOnValueChanged; 639 HandleAlgorithmTargetQualityChanged(); 640 } 641 642 private void AlgorithmTargetQualityOnValueChanged(object sender, EventArgs e) { 643 HandleAlgorithmTargetQualityChanged(); 644 } 645 646 private void AlgorithmMaximumEvaluationsParameterOnChanged(object sender, EventArgs eventArgs) { 647 var intValueParam = (sender as IValueParameter<IntValue>); 648 if (intValueParam.Value == null) { 649 intValueParam.Value = new IntValue(); 650 return; 651 } 652 intValueParam.Value.ValueChanged += AlgorithmMaximumEvaluationsOnValueChanged; 653 HandleAlgorithmMaximumEvaluationsChanged(); 654 } 655 656 private void AlgorithmMaximumEvaluationsOnValueChanged(object sender, EventArgs eventArgs) { 657 var intValue = (IntValue)sender; 658 HandleAlgorithmMaximumEvaluationsChanged(); 659 } 660 570 661 private void Problem_BestKnownQualityParameter_ValueChanged(object sender, EventArgs e) { 571 662 var param = sender as IValueParameter<DoubleValue>; … … 592 683 if (Algorithm != null) Algorithm.Problem = Problem; 593 684 if (Problem != null) UpdateTargetValueFromBestKnownQuality(); 685 } 686 687 private void MaximumEvaluationsParameterOnValueChanged(object sender, EventArgs eventArgs) { 688 SynchronizeMaximumEvaluationsParameter(); 689 } 690 691 private void TargetQualityParameterChanged(object sender, EventArgs e) { 692 if (TargetQualityParameter.Value != null) TargetQualityParameter.Value.ValueChanged += TargetQualityParameterOnValueChanged; 693 HandleAlgorithmTargetQualityChanged(); 694 } 695 696 private void TargetQualityParameterOnValueChanged(object sender, EventArgs eventArgs) { 697 HandleAlgorithmTargetQualityChanged(); 594 698 } 595 699 … … 603 707 } 604 708 #endregion 709 710 private void HandleAlgorithmTargetQualityChanged() { 711 IParameter param; 712 if (!Algorithm.Parameters.TryGetValue("TargetQuality", out param)) throw new InvalidOperationException("Cannot find TargetQuality parameter in Algorithm " + Algorithm.Name); 713 var doubleValueParam = (param as IValueParameter<DoubleValue>); 714 715 if (doubleValueParam.Value == null && TargetQualityParameter.Value != null) { 716 doubleValueParam.Value = new DoubleValue(TargetQualityParameter.Value.Value); 717 } else if (doubleValueParam.Value != null && TargetQualityParameter.Value == null) { 718 doubleValueParam.Value = null; 719 } else if (doubleValueParam.Value != null && TargetQualityParameter.Value != null) { 720 doubleValueParam.Value.Value = TargetQualityParameter.Value.Value; 721 } 722 } 723 724 private void HandleAlgorithmMaximumEvaluationsChanged() { 725 IParameter param; 726 if (!Algorithm.Parameters.TryGetValue("MaximumEvaluations", out param)) throw new InvalidOperationException("Cannot find MaximumEvaluations parameter in Algorithm " + Algorithm.Name); 727 var intValueParam = (param as IValueParameter<IntValue>); 728 var value = intValueParam.Value; 729 if (value.Value > MaximumEvaluationsParameter.Value.Value) 730 value.Value = MaximumEvaluationsParameter.Value.Value; 731 } 732 733 private void SynchronizeMaximumEvaluationsParameter() { 734 IParameter param; 735 if (Algorithm.Parameters.TryGetValue("MaximumEvaluations", out param)) { 736 var intValueParam = (param as IValueParameter<IntValue>); 737 if (intValueParam.Value == null) intValueParam.Value = new IntValue(MaximumEvaluationsParameter.Value.Value); 738 else intValueParam.Value.Value = MaximumEvaluationsParameter.Value.Value; 739 } 740 } 605 741 } 606 742 }
Note: See TracChangeset
for help on using the changeset viewer.