Changeset 5357 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators
- Timestamp:
- 01/23/11 12:47:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5340 r5357 21 21 [Item("ParameterConfigurationEvaluator", "A base class for operators which evaluate Meta Optimization solutions.")] 22 22 [StorableClass] 23 public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator { 24 private const double PenaltyQuality = 100000.0; // todo: use something better 25 23 public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator, IStochasticOperator { 24 public ILookupParameter<IRandom> RandomParameter { 25 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 26 } 26 27 public ILookupParameter<DoubleValue> QualityParameter { 27 28 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } … … 56 57 public ParameterConfigurationEvaluator() 57 58 : base() { 59 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation.")); 58 60 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector.")); 59 61 Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description.")); … … 76 78 77 79 public override IOperation Apply() { 80 IRandom random = RandomParameter.ActualValue; 78 81 ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue; 79 82 IAlgorithm algorithm = (IAlgorithm)Activator.CreateInstance(AlgorithmTypeParameter.ActualValue.Value); … … 87 90 Console.WriteLine("Used Cache for {0}", parameterConfiguration.ParameterInfoString); 88 91 } else { 89 runs = ExecuteAlgorithm(parameterConfiguration, algorithm, problems); 92 do { 93 runs = ExecuteAlgorithm(parameterConfiguration, algorithm, problems, Repetitions.Value, GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0); 94 if (runs == null) { 95 Repair(parameterConfiguration, random); 96 parameterConfiguration.Parameterize(algorithm); 97 } 98 } while (runs == null); 90 99 } 91 100 … … 111 120 112 121 return base.Apply(); 122 } 123 124 /// <summary> 125 /// This method should repair an invalid parameterConfiguration. 126 /// The strategy is to just randomize parameter settings. It's not guaranteed to be a vaild setting 127 /// </summary> 128 private void Repair(ParameterConfigurationTree parameterConfiguration, IRandom random) { 129 parameterConfiguration.Randomize(random); 113 130 } 114 131 … … 127 144 } 128 145 129 private RunCollection ExecuteAlgorithm(ParameterConfigurationTree parameterConfiguration, IAlgorithm algorithm, IItemList<IProblem> problems) { 146 /// <summary> 147 /// Executes an algorithm 148 /// </summary> 149 /// <param name="parameterConfiguration"></param> 150 /// <param name="algorithm"></param> 151 /// <param name="problems"></param> 152 /// <returns></returns> 153 private static RunCollection ExecuteAlgorithm(ParameterConfigurationTree parameterConfiguration, IAlgorithm algorithm, IItemList<IProblem> problems, int repetitions, int currentGeneration) { 130 154 IAlgorithm algorithmClone = (IAlgorithm)algorithm.Clone(); 131 155 var parameterNames = new List<string>(); … … 145 169 algorithmClone.Problem = (IProblem)problem.Clone(); 146 170 147 for (int i = 0; i < Repetitions.Value; i++) {171 for (int i = 0; i < repetitions; i++) { 148 172 algorithmClone.Prepare(); 149 173 … … 152 176 153 177 if (algorithmClone.ExecutionState == ExecutionState.Paused) { 154 // this parametercombination was bad. set penalty for this solution 155 // TODO! 178 // the parameter settings were invalid. 179 // (1) set penalty for this solution. 180 // it's difficult to create penalty values for BestQuality and ExecutionTime. Maybe ReferenceQuality * X (but what about ExecutionTime?) 181 // therefore use repair instead. 182 183 // (2) repair and retry 184 return null; 156 185 } 157 186 int problemIndex = problems.IndexOf(problem) + 1; … … 159 188 CleanRun(run, resultNames, parameterNames); 160 189 run.Results.Add("Meta.FromCache", new BoolValue(false)); 161 run.Results.Add("Meta.Generation", new IntValue( GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0));190 run.Results.Add("Meta.Generation", new IntValue(currentGeneration)); 162 191 run.Results.Add("Meta.ProblemIndex", new IntValue(problemIndex)); 163 192 int runCountOfThisProblem = algorithmClone.Runs.Where(x => ((IntValue)x.Results["Meta.ProblemIndex"]).Value == problemIndex).Count(); … … 173 202 /// only keep the results which are important and the parameters which were optimized 174 203 /// </summary> 175 private void CleanRun(IRun run, IEnumerable<string> resultsToKeep, IEnumerable<string> parametersToKeep) {204 private static void CleanRun(IRun run, IEnumerable<string> resultsToKeep, IEnumerable<string> parametersToKeep) { 176 205 var resultsToRemove = new List<string>(); 177 206 var parametersToRemove = new List<string>();
Note: See TracChangeset
for help on using the changeset viewer.