Changeset 5009 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators
- Timestamp:
- 12/01/10 20:37:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs
r4997 r5009 23 23 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 24 24 } 25 public ILookupParameter< IAlgorithm> AlgorithmParameter {26 get { return (ILookupParameter< IAlgorithm>)Parameters["Algorithm"]; }25 public ILookupParameter<EngineAlgorithm> AlgorithmParameter { 26 get { return (ILookupParameter<EngineAlgorithm>)Parameters["Algorithm"]; } 27 27 } 28 public ILookupParameter<IItemList<I Problem>> ProblemsParameter {29 get { return (ILookupParameter<IItemList<I Problem>>)Parameters["Problems"]; }28 public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter { 29 get { return (ILookupParameter<IItemList<ISingleObjectiveProblem>>)Parameters["Problems"]; } 30 30 } 31 public ILookupParameter< IValueConfiguration> ParameterConfigurationParameter {32 get { return (ILookupParameter< IValueConfiguration>)Parameters["ValueConfiguration"]; }31 public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 32 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 33 33 } 34 34 public ValueParameter<IntValue> RepetitionsParameter { … … 41 41 } 42 42 43 public MetaOptimizationEvaluator() : base() { 43 public MetaOptimizationEvaluator() 44 : base() { 44 45 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<I Problem>>("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.")); 48 49 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "Number of evaluations for one individual.", new IntValue(3))); 49 50 } … … 60 61 61 62 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 65 68 algorithmStopped = false; 66 AlgorithmParameter.ActualValue.Stopped += new EventHandler(ActualValue_Stopped);69 algorithm.Stopped += new EventHandler(ActualValue_Stopped); 67 70 68 71 double qualitySum = 0; 69 72 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) 78 80 } 81 double quality = ((DoubleValue)algorithm.Results["BestQuality"].Value).Value; 82 ParameterConfigurationParameter.ActualValue.Quality.Value = quality; 83 qualitySum += quality; 84 //} 79 85 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); 82 91 83 92 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.