Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/10 20:37:36 (14 years ago)
Author:
cneumuel
Message:

#1215 worked on metaoptimization

File:
1 edited

Legend:

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

    r4997 r5009  
    2323      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
    2424    }
    25     public ILookupParameter<IAlgorithm> AlgorithmParameter {
    26       get { return (ILookupParameter<IAlgorithm>)Parameters["Algorithm"]; }
     25    public ILookupParameter<EngineAlgorithm> AlgorithmParameter {
     26      get { return (ILookupParameter<EngineAlgorithm>)Parameters["Algorithm"]; }
    2727    }
    28     public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
    29       get { return (ILookupParameter<IItemList<IProblem>>)Parameters["Problems"]; }
     28    public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {
     29      get { return (ILookupParameter<IItemList<ISingleObjectiveProblem>>)Parameters["Problems"]; }
    3030    }
    31     public ILookupParameter<IValueConfiguration> ParameterConfigurationParameter {
    32       get { return (ILookupParameter<IValueConfiguration>)Parameters["ValueConfiguration"]; }
     31    public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
     32      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    3333    }
    3434    public ValueParameter<IntValue> RepetitionsParameter {
     
    4141    }
    4242
    43     public MetaOptimizationEvaluator() : base() {
     43    public MetaOptimizationEvaluator()
     44      : base() {
    4445      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
    45       Parameters.Add(new LookupParameter<IAlgorithm>("Algorithm", "Missing description."));
    46       Parameters.Add(new LookupParameter<IItemList<IProblem>>("Problems", "Missing description."));
    47       Parameters.Add(new LookupParameter<IValueConfiguration>("ValueConfiguration", "Missing description."));
     46      Parameters.Add(new LookupParameter<EngineAlgorithm>("Algorithm", "Missing description."));
     47      Parameters.Add(new LookupParameter<IItemList<ISingleObjectiveProblem>>("Problems", "Missing description."));
     48      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description."));
    4849      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "Number of evaluations for one individual.", new IntValue(3)));
    4950    }
     
    6061
    6162    public override IOperation Apply() {
    62       AlgorithmParameter.ActualValue.Prepare();
    63       //ParameterizeAlgorithm();
    64       //ParameterConfigurationParameter.ActualValue.Parameterize(AlgorithmParameter.ActualValue);
     63      EngineAlgorithm algorithm = (EngineAlgorithm)ParameterConfigurationParameter.ActualValue.ActualValue.Value;
     64
     65      // set parameters
     66      ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);
     67
    6568      algorithmStopped = false;
    66       AlgorithmParameter.ActualValue.Stopped += new EventHandler(ActualValue_Stopped);
     69      algorithm.Stopped += new EventHandler(ActualValue_Stopped);
    6770
    6871      double qualitySum = 0;
    6972
    70       foreach (IProblem problem in ProblemsParameter.ActualValue) {
    71         AlgorithmParameter.ActualValue.Problem = problem;
    72         AlgorithmParameter.ActualValue.Start();
    73         while (!algorithmStopped) {
    74           Thread.Sleep(1000); // 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)
    75         }
    76         AlgorithmParameter.ActualValue.Stopped -= new EventHandler(ActualValue_Stopped);
    77         qualitySum += ((DoubleValue)AlgorithmParameter.ActualValue.Results["BestQuality"].Value).Value;
     73      //foreach (ISingleObjectiveProblem problem in ProblemsParameter.ActualValue) {
     74      algorithm.Engine = new SequentialEngine.SequentialEngine();
     75      //algorithm.Problem = problem;
     76      algorithm.Prepare();
     77      algorithm.Start();
     78      while (!algorithmStopped) {
     79        Thread.Sleep(1000); // 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)
    7880      }
     81      double quality = ((DoubleValue)algorithm.Results["BestQuality"].Value).Value;
     82      ParameterConfigurationParameter.ActualValue.Quality.Value = quality;
     83      qualitySum += quality;
     84      //}
    7985
    80       double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count;
    81       this.QualityParameter.ActualValue = new DoubleValue(qualityAvg);
     86      algorithm.Stopped -= new EventHandler(ActualValue_Stopped);
     87
     88      //double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count;
     89      //this.QualityParameter.ActualValue = new DoubleValue(qualityAvg);
     90      this.QualityParameter.ActualValue = new DoubleValue(quality);
    8291
    8392      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.