Changeset 5184 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
- Timestamp:
- 12/30/10 22:50:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5111 r5184 19 19 public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator { 20 20 private bool algorithmStopped; 21 private bool algorithmExceptionOccured; 21 22 22 23 public ILookupParameter<DoubleValue> QualityParameter { … … 69 70 70 71 algorithmStopped = false; 71 algorithm.Stopped += new EventHandler(ActualValue_Stopped); 72 algorithmExceptionOccured = false; 73 algorithm.Stopped += new EventHandler(algorithm_Stopped); 74 algorithm.Paused += new EventHandler(algorithm_Paused); 75 algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred); 72 76 73 77 List<double> qualities = new List<double>(); … … 85 89 Thread.Sleep(200); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already) 86 90 } 87 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);88 executionTimes.Add(algorithm.ExecutionTime);89 91 90 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs 91 algorithm.Runs.Last().Parameters.Clear(); 92 // but keep the problem, since this differs in runs 93 algorithm.Runs.Last().Parameters.Add("Problem", problem); 92 if (algorithmExceptionOccured) { 93 // this parametercombination was bad. set penalty for this solution 94 qualities.Add(double.MaxValue); // todo: respect Maximization 95 executionTimes.Add(algorithm.ExecutionTime); 96 } else { 97 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value); 98 executionTimes.Add(algorithm.ExecutionTime); 99 100 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs 101 algorithm.Runs.Last().Parameters.Clear(); 102 // but keep the problem, since this differs in runs 103 algorithm.Runs.Last().Parameters.Add("Problem", problem); 104 } 94 105 algorithmStopped = false; 106 algorithmExceptionOccured = false; 95 107 } 96 97 108 } 98 109 99 100 algorithm.Stopped -= new EventHandler(ActualValue_Stopped); 110 algorithm.Stopped -= new EventHandler(algorithm_Stopped); 111 algorithm.Paused -= new EventHandler(algorithm_Paused); 112 algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred); 101 113 algorithm.Prepare(); 102 114 … … 104 116 105 117 ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds))); 106 ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions;118 ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone(); 107 119 ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First()); 108 120 ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average()); … … 110 122 ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance()); 111 123 ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation()); 112 ParameterConfigurationParameter.ActualValue.Runs = algorithm.Runs;124 ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone(); 113 125 114 126 double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance) … … 116 128 117 129 return base.Apply(); 130 } 131 132 private void algorithm_Paused(object sender, EventArgs e) { 133 algorithmStopped = true; 134 } 135 136 private void algorithm_Stopped(object sender, EventArgs e) { 137 algorithmStopped = true; 138 } 139 140 void algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 141 algorithmExceptionOccured = true; 118 142 } 119 143 … … 128 152 } 129 153 130 void ActualValue_Stopped(object sender, EventArgs e) { 131 algorithmStopped = true; 132 } 154 133 155 } 134 156 }
Note: See TracChangeset
for help on using the changeset viewer.