Changeset 5087 for branches/HeuristicLab.MetaOptimization
- Timestamp:
- 12/12/10 11:34:13 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5023 r5087 17 17 using System.Text; 18 18 using HeuristicLab.Selection; 19 using HeuristicLab.Algorithms.EvolutionStrategy; 19 20 20 21 namespace HeuristicLab.MetaOptimization.Test { 21 22 class Program { 22 private static int metaAlgorithmPopulationSize = 40;23 private static int metaAlgorithmPopulationSize = 50; 23 24 private static int metaAlgorithmMaxGenerations = 30; 24 25 private static int baseAlgorithmMaxGenerations = 100; 25 private static int metaProblemRepetitions = 3; 26 27 private static int baseAlgorithmMaxGenerations = 250; 26 28 27 29 static void Main(string[] args) { 30 //TestShorten(); 31 28 32 //TestIntSampling(); 29 33 //TestDoubleSampling(); 30 34 31 35 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); 36 32 37 MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem(); 33 GeneticAlgorithm metaLevelAlgorithm = GetMetaAlgorithm(metaOptimizationProblem); 34 35 IValueConfiguration algorithmVc = SetupAlgorithm(baseLevelAlgorithm, metaOptimizationProblem); 38 ((MetaOptimizationEvaluator)metaOptimizationProblem.Evaluator).Repetitions.Value = metaProblemRepetitions; 39 GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem); 40 //EvolutionStrategy metaLevelAlgorithm = GetMetaES(metaOptimizationProblem); 41 42 IValueConfiguration algorithmVc = SetupGAAlgorithm(baseLevelAlgorithm, metaOptimizationProblem); 36 43 37 44 //Console.WriteLine("Press enter to start"); 38 45 //Console.ReadLine(); 39 46 //TestConfiguration(algorithmVc, baseLevelAlgorithm); 40 47 41 48 //Console.WriteLine("Press enter to start"); 42 49 //Console.ReadLine(); … … 69 76 } 70 77 71 private static GeneticAlgorithm GetMeta Algorithm(MetaOptimizationProblem metaOptimizationProblem) {78 private static GeneticAlgorithm GetMetaGA(MetaOptimizationProblem metaOptimizationProblem) { 72 79 GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm(); 73 80 metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize; … … 83 90 } 84 91 85 private static IValueConfiguration SetupAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) { 86 baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 87 Evaluator = new GriewankEvaluator(), 88 ProblemSize = new IntValue(1000) 89 }; 92 private static EvolutionStrategy GetMetaES(MetaOptimizationProblem metaOptimizationProblem) { 93 EvolutionStrategy metaLevelAlgorithm = new EvolutionStrategy(); 94 metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize; 95 metaLevelAlgorithm.MaximumGenerations.Value = metaAlgorithmMaxGenerations; 96 97 metaLevelAlgorithm.Problem = metaOptimizationProblem; 98 metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine(); 99 100 metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator(); 101 //metaLevelAlgorithm.MutationProbability.Value = 0.15; 102 103 return metaLevelAlgorithm; 104 } 105 106 private static IValueConfiguration SetupGAAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) { 107 baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem(); 90 108 baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations; 91 109 92 110 metaOptimizationProblem.Algorithm = baseLevelAlgorithm; 93 111 IValueConfiguration algorithmVc = metaOptimizationProblem.AlgorithmParameterConfiguration; 94 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem()); 112 113 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 114 Evaluator = new GriewankEvaluator(), 115 ProblemSize = new IntValue(500) 116 }); 117 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 118 Evaluator = new GriewankEvaluator(), 119 ProblemSize = new IntValue(1000) 120 }); 95 121 96 122 ConfigurePopulationSize(algorithmVc); … … 189 215 vc.Optimize = true; 190 216 ConfigureTournamentGroupSize(vc); 217 } else if (vc.ActualValue.ValueDataType == typeof(RandomSelector)) { 218 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true); 191 219 } else { 192 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, false);220 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true); 193 221 } 194 222 } … … 235 263 } 236 264 237 private static void TestOptimization( GeneticAlgorithm metaLevelAlgorithm) {265 private static void TestOptimization(EngineAlgorithm metaLevelAlgorithm) { 238 266 ContentManager.Initialize(new PersistenceContentManager()); 239 267 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Results"); 240 if (!Directory.Exists(path))268 if (!Directory.Exists(path)) 241 269 Directory.CreateDirectory(path); 242 string id = DateTime.Now.ToString("MM.dd.yy - HH;mm;ss,ffff"); 243 string resultPath = Path.Combine(path, string.Format("Test - {0} - Result.hl", id)); 244 string outputPath = Path.Combine(path, string.Format("Test - {0} - Console.txt", id)); 270 string id = DateTime.Now.ToString("yyyy.MM.dd - HH;mm;ss,ffff"); 271 string resultPath = Path.Combine(path, string.Format("{0} - Result.hl", id)); 272 string outputPath = Path.Combine(path, string.Format("{0} - Console.txt", id)); 273 245 274 246 275 using (var sw = new StreamWriter(outputPath)) { 276 sw.AutoFlush = true; 277 278 StringBuilder sb1 = new StringBuilder(); 279 sb1.AppendLine(string.Format("Meta.PopulationSize: {0}", metaAlgorithmPopulationSize)); 280 sb1.AppendLine(string.Format("Meta.MaxGenerations: {0}", metaAlgorithmMaxGenerations)); 281 sb1.AppendLine(string.Format("Meta.Repetitions : {0}", metaProblemRepetitions)); 282 sb1.AppendLine(string.Format("Base.MaxGenerations: {0}", baseAlgorithmMaxGenerations)); 283 sw.WriteLine(sb1.ToString()); 284 Console.WriteLine(sb1.ToString()); 285 247 286 metaLevelAlgorithm.Start(); 248 287 int i = 0; … … 250 289 do { 251 290 Thread.Sleep(500); 252 try { 253 if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) { 254 StringBuilder sb = new StringBuilder(); 255 sb.AppendLine(DateTime.Now.ToLongTimeString()); 256 sb.AppendLine("================================="); 257 258 foreach (var result in metaLevelAlgorithm.Results) { 259 sb.AppendLine(result.ToString()); 260 if (result.Name == "Population") { 261 RunCollection rc = (RunCollection)result.Value; 262 var orderedRuns = rc.OrderBy(x => x.Results["BestQuality"]); 263 264 sb.AppendLine("Qality PoSi MutRa Eli GrSi MutOp"); 265 foreach (IRun run in orderedRuns) { 266 sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}", 267 ((DoubleValue)run.Results["BestQuality"]).Value.ToString("#0.00").PadLeft(7, ' '), 268 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' ').PadRight(3, ' '), 269 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadLeft(5, ' '), 270 ((IntValue)run.Parameters["Elites"]).Value.ToString().PadLeft(3, ' '), 271 ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString().PadLeft(4, ' '), 272 run.Parameters["Mutator"])); 291 if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) { 292 while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100); 293 StringBuilder sb = new StringBuilder(); 294 sb.AppendLine(DateTime.Now.ToLongTimeString()); 295 sb.AppendLine("================================="); 296 297 foreach (var result in metaLevelAlgorithm.Results) { 298 sb.AppendLine(result.ToString()); 299 if (result.Name == "Population") { 300 RunCollection rc = (RunCollection)result.Value; 301 var orderedRuns = rc.OrderBy(x => x.Results["RunsAverageQuality"]); 302 303 sb.AppendLine("Qual. PoSi MutRa Eli GrSi MutOp"); 304 foreach (IRun run in orderedRuns) { 305 string selector; 306 if (run.Parameters["Selector"] is TournamentSelector) { 307 selector = string.Format("{0} ({1})", run.Parameters["Selector"].ToString(), ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString()); 308 } else { 309 selector = string.Format("{0}", run.Parameters["Selector"].ToString()); 273 310 } 311 312 sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}", 313 ((DoubleValue)run.Results["RunsAverageQuality"]).Value.ToString("#0.00").PadLeft(7, ' '), 314 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' ').PadRight(3, ' '), 315 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadLeft(5, ' '), 316 ((IntValue)run.Parameters["Elites"]).Value.ToString().PadLeft(3, ' '), 317 Shorten(selector, 20).PadRight(20, ' '), 318 run.Parameters["Mutator"].ToString())); 274 319 } 275 } // foreach 276 Console.Clear(); 277 Console.WriteLine(sb.ToString()); 278 sw.WriteLine(sb.ToString()); 279 sw.Flush(); 280 currentGeneration = ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value; 281 } // if 282 if (i % 30 == 0) GC.Collect(); 283 i++; 284 } 285 catch { } 320 } 321 } // foreach 322 Console.Clear(); 323 Console.WriteLine(sb.ToString()); 324 sw.WriteLine(sb.ToString()); 325 currentGeneration = ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value; 326 } // if 327 if (i % 30 == 0) GC.Collect(); 328 i++; 286 329 } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped); 287 330 } … … 290 333 Console.WriteLine("Storing..."); 291 334 292 ContentManager.Save( metaLevelAlgorithm, resultPath, true);335 ContentManager.Save((IStorableContent)metaLevelAlgorithm, resultPath, true); 293 336 Console.WriteLine("Finished"); 337 } 338 339 private static void TestShorten() { 340 int n = 8; 341 Console.WriteLine(Shorten("1", n)); 342 Console.WriteLine(Shorten("12", n)); 343 Console.WriteLine(Shorten("123", n)); 344 Console.WriteLine(Shorten("1234", n)); 345 Console.WriteLine(Shorten("12345", n)); 346 Console.WriteLine(Shorten("123456", n)); 347 Console.WriteLine(Shorten("1234567", n)); 348 Console.WriteLine(Shorten("12345678", n)); 349 Console.WriteLine(Shorten("123456789", n)); 350 Console.WriteLine(Shorten("1234567890", n)); 351 Console.WriteLine(Shorten("12345678901", n)); 352 } 353 354 private static string Shorten(string s, int n) { 355 string placeholder = ".."; 356 if (s.Length <= n) return s; 357 int len = n / 2 - placeholder.Length / 2; 358 string start = s.Substring(0, len); 359 string end = s.Substring(s.Length - len, len); 360 return start + placeholder + end; 294 361 } 295 362 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.Designer.cs
r4981 r5087 41 41 this.viewHost.Size = new System.Drawing.Size(513, 345); 42 42 this.viewHost.TabIndex = 0; 43 this.viewHost.ViewsLabelVisible = false; 43 44 this.viewHost.ViewType = null; 44 45 // -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs
r4997 r5087 53 53 Content.ActualValue.ValueDataType == typeof(DoubleValue) || 54 54 Content.ActualValue.ValueDataType == typeof(PercentValue)) { 55 this.viewHost.ViewsLabelVisible = true; 55 56 this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint; 56 57 } else if(Content.ActualValue.ValueDataType == typeof(BoolValue)) { 57 58 this.viewHost.Content = null; // no configuration required 58 59 } else { 60 this.viewHost.ViewsLabelVisible = false; 59 61 this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations; 60 62 } … … 63 65 } 64 66 } else { 67 this.viewHost.ViewsLabelVisible = false; 65 68 this.viewHost.Content = Content.ActualValue; 66 69 } 67 70 } 71 SetEnabledStateOfControls(); 68 72 } 69 73 void Content_IsOptimizabeChanged(object sender, EventArgs e) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs
r4982 r5087 24 24 public ValueConfigurationCheckedItemCollectionView() { 25 25 InitializeComponent(); 26 this.viewHost.ViewsLabelVisible = false; 26 27 } 27 28 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.Designer.cs
r4839 r5087 62 62 this.valueViewHost.Size = new System.Drawing.Size(470, 219); 63 63 this.valueViewHost.TabIndex = 3; 64 this.valueViewHost.ViewsLabelVisible = false; 64 65 this.valueViewHost.ViewType = null; 65 66 // -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.resx
r4839 r5087 166 166 fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+ 167 167 tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/ 168 6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALD gAACw4BQL7hQQAAAbVJREFUOE+lk7lLA0EU168 6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALDQAACw0B7QfALAAAAbVJREFUOE+lk7lLA0EU 169 169 xuMRcdeYyIBRQcmxURTiEXE8ECQqpAkpJJVNihSKjVjbW1lJChuxtBGUNGKRwj9AvA9QEMRGS01M4YYZ 170 170 v9nN5twgavGDt/tmvn3HtxbOueU/6JcpGQEpMAfqfyMoLjeAZbYU5iw2ryJe0N6ZVUZJI3JesGrkhYB4 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r5023 r5087 40 40 } 41 41 42 public BestParameterConfigurationAnalyzer() : base() { 42 public BestParameterConfigurationAnalyzer() 43 : base() { 43 44 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed.")); 44 45 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed.")); … … 63 64 ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue; 64 65 65 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;66 int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 66 67 67 EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterTrees[i]).ActualValue.Value);68 Run bestRun = new Run(bestAlg);69 ((ParameterConfigurationTree)parameterTrees[i]).CollectResultValues(bestRun.Results);70 68 71 if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false 72 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 69 ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest]; 70 IRun bestRun = new Run(); 71 best.CollectResultValues(bestRun.Results); 72 best.CollectParameterValues(bestRun.Parameters); 73 74 if (bestKnownQuality == null || qualities[idxBest].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false 75 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[idxBest].Value); 76 73 77 BestKnownSolutionParameter.ActualValue = bestRun; 74 78 } 75 79 76 IRun best = BestSolutionParameter.ActualValue; 77 if (best == null) { 80 if (BestSolutionParameter.ActualValue == null) { 78 81 BestSolutionParameter.ActualValue = bestRun; 79 82 results.Add(new Result("Best Parameter Settings", bestRun)); … … 84 87 85 88 // population 89 90 int i = 0; 86 91 RunCollection rc = new RunCollection(); 87 92 foreach (ParameterConfigurationTree pt in parameterTrees.OrderByDescending(x => x.BestQuality.Value)) { // todo: respect Maximization:true/false 88 IAlgorithm alg = (IAlgorithm)pt.ActualValue.Value; 89 alg.StoreAlgorithmInEachRun = false; 90 IRun run = new Run(alg); 93 IRun run = new Run(); 94 run.Name = string.Format("Individuum ({0})", i); 91 95 pt.CollectResultValues(run.Results); 96 pt.CollectParameterValues(run.Parameters); 92 97 rc.Add(run); 98 i++; 93 99 } 94 100 if (PopulationParameter.ActualValue == null) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurationTree.cs
r5023 r5087 13 13 [StorableClass] 14 14 public class ParameterConfigurationTree : ValueConfiguration { 15 [Storable]16 public EngineAlgorithm Algorithm {17 get { return (EngineAlgorithm)base.ActualValue.Value; }18 set {19 base.ActualValue.Value = value;20 }21 }15 //[Storable] 16 //public EngineAlgorithm Algorithm { 17 // get { return (EngineAlgorithm)base.ActualValue.Value; } 18 // set { 19 // base.ActualValue.Value = value; 20 // } 21 //} 22 22 23 23 [Storable] … … 48 48 set { worstQuality = value; } 49 49 } 50 50 51 51 [Storable] 52 52 private DoubleValue qualityVariance; … … 55 55 set { qualityVariance = value; } 56 56 } 57 57 58 58 [Storable] 59 59 private DoubleValue qualityStandardDeviation; … … 62 62 set { qualityStandardDeviation = value; } 63 63 } 64 64 65 65 [Storable] 66 66 private TimeSpanValue averageExecutionTime; … … 78 78 79 79 [Storable] 80 public RunCollection Runs { get; set; } 81 80 protected RunCollection runs; 81 public RunCollection Runs { 82 get { return runs; } 83 set { runs = value; } 84 } 85 86 protected IDictionary<string, IItem> parameters; 87 public IDictionary<string, IItem> Parameters { 88 get { return parameters; } 89 set { parameters = value; } 90 } 91 82 92 #region constructors and cloning 83 public ParameterConfigurationTree(EngineAlgorithm algorithm) : base(algorithm, algorithm.GetType()) { 93 public ParameterConfigurationTree(EngineAlgorithm algorithm) 94 : base(null, algorithm.GetType()) { 84 95 this.Optimize = true; // root must always be optimized 85 96 this.BestQuality = new DoubleValue(); 97 this.parameters = new Dictionary<string, IItem>(); 98 99 PopulateParameterConfigurations(algorithm); 100 Initialize(); 86 101 } 87 102 public ParameterConfigurationTree() { … … 90 105 [StorableConstructor] 91 106 protected ParameterConfigurationTree(bool deserializing) : base(deserializing) { } 92 protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner) : base(original, cloner) { 107 protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner) 108 : base(original, cloner) { 93 109 this.bestQuality = cloner.Clone(original.BestQuality); 94 this.Algorithm.Prepare(); 95 this.Algorithm.Runs.Clear(); 110 this.parameters = new Dictionary<string, IItem>(); 111 foreach (var p in original.parameters) { 112 this.parameters.Add(p.Key, cloner.Clone(p.Value)); 113 } 96 114 Initialize(); 97 115 } … … 121 139 } 122 140 141 public virtual void CollectParameterValues(IDictionary<string, IItem> values) { 142 foreach (var p in parameters) { 143 values.Add(p); 144 } 145 } 146 123 147 #region Events 124 148 //public event EventHandler AlgorithmChanged; … … 134 158 135 159 //private void RegisterAlgorithmEvents() { 136 160 137 161 //} 138 162 //private void DeregisterAlgorithmEvents() { … … 151 175 #endregion 152 176 177 public override void Parameterize(IParameterizedItem item) { 178 base.Parameterize(item); 179 this.parameters.Clear(); 180 ((IAlgorithm)item).CollectParameterValues(this.Parameters); 181 } 153 182 } 154 183 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs
r5023 r5087 281 281 public void Randomize(IRandom random) { 282 282 if (Optimize) { 283 foreach (var vc in this.ValueConfigurations.CheckedItems) { 284 vc.Randomize(random); 285 } 283 286 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 284 this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize(random);285 287 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 286 288 } … … 294 296 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 295 297 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 296 this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Mutate(random);297 298 } 298 299 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs
r5023 r5087 34 34 if (optimize) { 35 35 ClearParameterConfigurations(); 36 PopulateParameterConfigurations();36 if (this.actualValue.Value is IParameterizedNamedItem) PopulateParameterConfigurations(this.actualValue.Value as IParameterizedNamedItem); 37 37 } else { 38 38 ClearParameterConfigurations(); … … 53 53 [Storable] 54 54 protected ConstrainedValue actualValue; 55 public ConstrainedValue ActualValue {55 public virtual ConstrainedValue ActualValue { 56 56 get { return actualValue; } 57 57 set { … … 59 59 ClearParameterConfigurations(); 60 60 this.actualValue = value; 61 PopulateParameterConfigurations();61 if (this.actualValue.Value is IParameterizedNamedItem) PopulateParameterConfigurations(this.actualValue.Value as IParameterizedNamedItem); 62 62 OnValueChanged(); 63 63 OnToStringChanged(); … … 112 112 #endregion 113 113 114 protected virtual void PopulateParameterConfigurations() { 115 if (this.actualValue.Value is IParameterizedNamedItem) { 116 var parameterizedItem = this.actualValue.Value as IParameterizedNamedItem; 117 foreach (var childParameter in parameterizedItem.Parameters) { 118 var pc = ParameterConfiguration.Create(parameterizedItem, childParameter); 119 if (pc != null) this.parameterConfigurations.Add(pc); 120 } 114 protected virtual void PopulateParameterConfigurations(IParameterizedNamedItem parameterizedItem) { 115 foreach (var childParameter in parameterizedItem.Parameters) { 116 var pc = ParameterConfiguration.Create(parameterizedItem, childParameter); 117 if (pc != null) this.parameterConfigurations.Add(pc); 121 118 } 122 119 } … … 195 192 } 196 193 197 public v oid Parameterize(IParameterizedItem item) {194 public virtual void Parameterize(IParameterizedItem item) { 198 195 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 199 196 pc.Parameterize((IValueParameter)item.Parameters[pc.ParameterName]); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs
r5023 r5087 63 63 64 64 public override IOperation Apply() { 65 EngineAlgorithm algorithm = (EngineAlgorithm)ParameterConfigurationParameter.ActualValue.ActualValue.Value; 65 EngineAlgorithm algorithm = AlgorithmParameter.ActualValue; 66 IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue; 66 67 67 68 // set parameters 68 69 ParameterConfigurationParameter.ActualValue.Parameterize(algorithm); 70 algorithm.Problem = problems.First(); 71 algorithm.StoreAlgorithmInEachRun = false; 69 72 70 73 algorithmStopped = false; … … 73 76 List<double> qualities = new List<double>(); 74 77 List<TimeSpan> executionTimes = new List<TimeSpan>(); 78 algorithm.Engine = new SequentialEngine.SequentialEngine(); 75 79 algorithm.Prepare(true); 76 80 77 for (int i = 0; i < Repetitions.Value; i++) { 78 algorithm.Engine = new SequentialEngine.SequentialEngine(); 79 algorithm.Prepare(); 80 algorithm.Start(); 81 while (!algorithmStopped) { 82 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) 81 foreach (ISingleObjectiveProblem problem in problems) { 82 algorithm.Problem = problem; 83 84 for (int i = 0; i < Repetitions.Value; i++) { 85 algorithm.Prepare(); 86 algorithm.Start(); 87 while (!algorithmStopped) { 88 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) 89 } 90 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value); 91 executionTimes.Add(algorithm.ExecutionTime); 92 93 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs 94 algorithm.Runs.Last().Parameters.Clear(); 95 // but keep the problem, since this differs in runs 96 algorithm.Runs.Last().Parameters.Add("Problem", problem); 97 algorithmStopped = false; 83 98 } 84 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);85 executionTimes.Add(algorithm.ExecutionTime);86 99 87 algorithmStopped = false;88 100 } 101 102 89 103 algorithm.Stopped -= new EventHandler(ActualValue_Stopped); 104 algorithm.Prepare(); 90 105 91 106 qualities = qualities.OrderBy(x => x).ToList(); // todo: respect Maximization:true/false 92 107 93 108 ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds))); 94 109 ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions; … … 102 117 double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance) 103 118 this.QualityParameter.ActualValue = new DoubleValue(quality); 104 119 105 120 return base.Apply(); 106 121 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5023 r5087 79 79 </Reference> 80 80 <Reference Include="HeuristicLab.SequentialEngine-3.3"> 81 <HintPath>..\..\ HeuristicLab.MetaOptimization.Test\bin\Debug\HeuristicLab.SequentialEngine-3.3.dll</HintPath>81 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath> 82 82 </Reference> 83 83 <Reference Include="System" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5009 r5087 151 151 } 152 152 void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) { 153 Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister? 154 BaseLevelAlgorithm_ProblemChanged(sender, e); 153 AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm); 154 155 //Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister? 156 //BaseLevelAlgorithm_ProblemChanged(sender, e); 155 157 } 156 158 157 159 void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) { 158 if (Algorithm != null && Algorithm.Problem != null) {159 AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm);160 }160 //if (Algorithm != null && Algorithm.Problem != null) { 161 // AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm); 162 //} 161 163 } 162 164 #endregion
Note: See TracChangeset
for help on using the changeset viewer.