Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/30/10 22:50:59 (14 years ago)
Author:
cneumuel
Message:

#1215

  • enhanced combinations generator (now with batchruns!)
  • fixed ActualNames for metaopt-alg
  • added penalty for invalid solution-candidates (algs which throw exceptions)
  • migrated to .NET 4.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5111 r5184  
    1919  public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator {
    2020    private bool algorithmStopped;
     21    private bool algorithmExceptionOccured;
    2122
    2223    public ILookupParameter<DoubleValue> QualityParameter {
     
    6970
    7071      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);
    7276
    7377      List<double> qualities = new List<double>();
     
    8589            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)
    8690          }
    87           qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);
    88           executionTimes.Add(algorithm.ExecutionTime);
    8991
    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          }
    94105          algorithmStopped = false;
     106          algorithmExceptionOccured = false;
    95107        }
    96 
    97108      }
    98109
    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);
    101113      algorithm.Prepare();
    102114
     
    104116
    105117      ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds)));
    106       ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions;
     118      ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone();
    107119      ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First());
    108120      ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average());
     
    110122      ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance());
    111123      ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation());
    112       ParameterConfigurationParameter.ActualValue.Runs = algorithm.Runs;
     124      ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone();
    113125
    114126      double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance)
     
    116128
    117129      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;
    118142    }
    119143
     
    128152    }
    129153
    130     void ActualValue_Stopped(object sender, EventArgs e) {
    131       algorithmStopped = true;
    132     }
     154
    133155  }
    134156}
Note: See TracChangeset for help on using the changeset viewer.