Changeset 5357 for branches/HeuristicLab.MetaOptimization
- Timestamp:
- 01/23/11 12:47:33 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5340 r5357 39 39 static void Main(string[] args) { 40 40 ContentManager.Initialize(new PersistenceContentManager()); 41 41 42 42 //TestTableBuilder(); 43 43 //TestShorten(); … … 51 51 //TestCombinations3(); 52 52 //TestEnumeratorCollectionEnumerator(); 53 //TestCombinations4(); 53 //TestCombinations4(); return; 54 54 //TestAlgorithmPerformanceIssue(); 55 55 //TestWaitAny(); … … 566 566 }); 567 567 568 ConfigurePopulationSize(algorithmVc, 12, 100, 1);568 ConfigurePopulationSize(algorithmVc, 0, 20, 1); 569 569 //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01); 570 570 //ConfigureMutationOperator(algorithmVc); 571 ConfigureElites(algorithmVc, 0, 10, 1);571 ConfigureElites(algorithmVc, 0, 30, 1); 572 572 //ConfigureSelectionOperator(algorithmVc, true); 573 573 return algorithmVc; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs
r5277 r5357 109 109 } 110 110 } 111 enumerators.Reverse(); // this makes the list of combinations better readable 111 112 } 112 113 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5340 r5357 214 214 get { 215 215 StringBuilder sb = new StringBuilder(); 216 if (this.Optimize) { 217 if (this.ParameterConfigurations.Count > 0) { 218 var parameterInfos = new List<string>(); 219 foreach (var pc in this.ParameterConfigurations) { 220 if (pc.Optimize) parameterInfos.Add(pc.ParameterInfoString); 221 } 222 sb.Append(string.Join(", ", parameterInfos.ToArray())); 223 } 216 if (this.Optimize && this.ParameterConfigurations.Count > 0) { 217 var parameterInfos = new List<string>(); 218 foreach (var pc in this.ParameterConfigurations) { 219 if (pc.Optimize) parameterInfos.Add(pc.ParameterInfoString); 220 } 221 sb.Append(string.Join(", ", parameterInfos.ToArray())); 224 222 } 225 223 return sb.ToString(); … … 273 271 var list = new List<IOptimizable>(); 274 272 foreach (var pc in ParameterConfigurations) { 275 if (pc.Optimize) {276 if (pc.ValueConfigurations.CheckedItems.Count() > 1) list.Add(pc); // only add if there are more than 1 choices. otherwise it makes no sense to optimize which VC is selected273 if (pc.Optimize) { 274 if (pc.ValueConfigurations.CheckedItems.Count() > 1) list.Add(pc); // only add if there are more than 1 choices. otherwise it makes no sense to optimize which VC is selected 277 275 list.AddRange(pc.GetAllOptimizables()); 278 276 } -
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.