Changeset 5184 for branches/HeuristicLab.MetaOptimization
- Timestamp:
- 12/30/10 22:50:59 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 1 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/HeuristicLab.MetaOptimization.Test.csproj
r5110 r5184 11 11 <RootNamespace>HeuristicLab.MetaOptimization.Test</RootNamespace> 12 12 <AssemblyName>HeuristicLab.MetaOptimization.Test</AssemblyName> 13 <TargetFrameworkVersion>v 3.5</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 14 <TargetFrameworkProfile> 15 15 </TargetFrameworkProfile> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5144 r5184 17 17 using HeuristicLab.Random; 18 18 using HeuristicLab.Selection; 19 using HeuristicLab.Parameters; 19 20 20 21 namespace HeuristicLab.MetaOptimization.Test { 21 22 class Program { 22 private static int metaAlgorithmPopulationSize = 50;23 private static int metaAlgorithmMaxGenerations = 30;24 private static int metaProblemRepetitions = 6;25 26 private static int baseAlgorithmMaxGenerations = 250;23 private static int metaAlgorithmPopulationSize = 10; 24 private static int metaAlgorithmMaxGenerations = 10; 25 private static int metaProblemRepetitions = 1; 26 27 private static int baseAlgorithmMaxGenerations = 10; 27 28 28 29 static void Main(string[] args) { … … 36 37 //TestCombinations2(); 37 38 //TestCombinations3(); 38 TestCombinations4(); 39 //TestEnumeratorCollectionEnumerator(); 40 //TestCombinations4(); 39 41 40 42 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); … … 65 67 private static void TestToString(IValueConfiguration algorithmVc) { 66 68 var random = new MersenneTwister(); 67 Console.WriteLine(algorithmVc. ToParameterInfoString());69 Console.WriteLine(algorithmVc.ParameterInfoString); 68 70 algorithmVc.Randomize(random); 69 Console.WriteLine(algorithmVc. ToParameterInfoString());71 Console.WriteLine(algorithmVc.ParameterInfoString); 70 72 algorithmVc.Randomize(random); 71 Console.WriteLine(algorithmVc. ToParameterInfoString());73 Console.WriteLine(algorithmVc.ParameterInfoString); 72 74 algorithmVc.Randomize(random); 73 75 } … … 114 116 } 115 117 118 private static void TestEnumeratorCollectionEnumerator() { 119 IEnumerable<int> list1 = new int[] { 1, 2, 3, 4, 5 }; 120 IEnumerable<int> list2 = new int[] { 10, 20, 30 }; 121 IEnumerable<int> list3 = new int[] { 300, 400, 500 }; 122 123 var enumerators = new List<IEnumerator>(); 124 125 EnumeratorCollectionEnumerator<int> enu = new EnumeratorCollectionEnumerator<int>(); 126 enu.AddEnumerator(list1.GetEnumerator()); 127 enu.AddEnumerator(list2.GetEnumerator()); 128 enu.AddEnumerator(list3.GetEnumerator()); 129 enu.Reset(); 130 while (enu.MoveNext()) { 131 Console.WriteLine(enu.Current); 132 } 133 } 134 116 135 private static void TestCombinations4() { 117 136 GeneticAlgorithm ga = new GeneticAlgorithm(); 118 137 ga.Problem = new SingleObjectiveTestFunctionProblem(); 138 ga.Engine = new SequentialEngine.SequentialEngine(); 139 119 140 ParameterConfigurationTree vc = new ParameterConfigurationTree(ga); 120 141 121 //ConfigurePopulationSize(vc, 20, 100, 20);142 ConfigurePopulationSize(vc, 20, 100, 20); 122 143 //ConfigureMutationRate(vc, 0.10, 0.60, 0.10); 123 ConfigureMutationOperator(vc); 124 ConfigureSelectionOperator(vc, false); 125 126 //foreach (var combination in vc.IterateCombinations()) { 127 // Console.WriteLine(combination.ToParameterInfoString()); 128 //} 144 //ConfigureMutationOperator(vc); 145 ConfigureSelectionOperator(vc, true); 129 146 130 147 int count = 0; … … 134 151 var current = (IValueConfiguration)enumerator.Current; 135 152 count++; 136 Console.WriteLine(current. ToParameterInfoString());153 Console.WriteLine(current.ParameterInfoString); 137 154 } 138 155 Console.WriteLine("You are about to create {0} algorithms.", count); 139 156 140 157 Experiment experiment = vc.GenerateExperiment(ga); 141 foreach (var opt in experiment.Optimizers) { 142 Console.WriteLine(opt.Name); 158 //foreach (var opt in experiment.Optimizers) { 159 // Console.WriteLine(opt.Name); 160 //} 161 162 experiment.Prepare(); 163 experiment.Start(); 164 165 while (experiment.ExecutionState != ExecutionState.Stopped) { 166 Thread.Sleep(500); 143 167 } 144 168 } … … 220 244 metaLevelAlgorithm.Problem = metaOptimizationProblem; 221 245 metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine(); 222 223 metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator(); 246 247 metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last(); 248 224 249 metaLevelAlgorithm.MutationProbability.Value = 0.15; 225 250 … … 235 260 metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine(); 236 261 237 metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator(); 238 //metaLevelAlgorithm.MutationProbability.Value = 0.15; 262 metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last(); 239 263 240 264 return metaLevelAlgorithm; … … 257 281 }); 258 282 259 ConfigurePopulationSize(algorithmVc, 20, 100, 1);260 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);261 ConfigureMutationOperator(algorithmVc);262 ConfigureElites(algorithmVc );263 ConfigureSelectionOperator(algorithmVc, true);283 ConfigurePopulationSize(algorithmVc, 0, 10, 1); 284 //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01); 285 //ConfigureMutationOperator(algorithmVc); 286 ConfigureElites(algorithmVc, 0, 10, 1); 287 //ConfigureSelectionOperator(algorithmVc, true); 264 288 return algorithmVc; 265 289 } … … 369 393 370 394 groupSizePc.ValueConfigurations.First().Optimize = true; 371 groupSizePc.ValueConfigurations.First().RangeConstraint.LowerBound = new IntValue( 0);372 groupSizePc.ValueConfigurations.First().RangeConstraint.UpperBound = new IntValue(10 0);395 groupSizePc.ValueConfigurations.First().RangeConstraint.LowerBound = new IntValue(2); 396 groupSizePc.ValueConfigurations.First().RangeConstraint.UpperBound = new IntValue(10); 373 397 groupSizePc.ValueConfigurations.First().RangeConstraint.StepSize = new IntValue(1); 374 398 } … … 394 418 } 395 419 396 private static void ConfigureElites(IValueConfiguration algorithmVc ) {420 private static void ConfigureElites(IValueConfiguration algorithmVc, int from, int to, int stepSize) { 397 421 var elitesPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Elites").SingleOrDefault(); 398 422 elitesPc.Optimize = true; 399 423 var elitesVc = elitesPc.ValueConfigurations.First(); 400 424 elitesVc.Optimize = true; 401 elitesVc.RangeConstraint.LowerBound = new IntValue( 0);402 elitesVc.RangeConstraint.UpperBound = new IntValue( 20);403 elitesVc.RangeConstraint.StepSize = new IntValue( 1);425 elitesVc.RangeConstraint.LowerBound = new IntValue(from); 426 elitesVc.RangeConstraint.UpperBound = new IntValue(to); 427 elitesVc.RangeConstraint.StepSize = new IntValue(stepSize); 404 428 } 405 429 … … 423 447 sw.WriteLine(sb1.ToString()); 424 448 Console.WriteLine(sb1.ToString()); 449 metaLevelAlgorithm.Stopped += new EventHandler(metaLevelAlgorithm_Stopped); 450 metaLevelAlgorithm.Paused += new EventHandler(metaLevelAlgorithm_Paused); 451 metaLevelAlgorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(metaLevelAlgorithm_ExceptionOccurred); 425 452 426 453 metaLevelAlgorithm.Start(); … … 478 505 } 479 506 507 private static void metaLevelAlgorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 508 Console.WriteLine("metaLevelAlgorithm_ExceptionOccurred"); 509 } 510 511 private static void metaLevelAlgorithm_Paused(object sender, EventArgs e) { 512 Console.WriteLine("metaLevelAlgorithm_Paused"); 513 } 514 515 private static void metaLevelAlgorithm_Stopped(object sender, EventArgs e) { 516 Console.WriteLine("metaLevelAlgorithm_Stopped"); 517 } 518 480 519 private static void TestShorten() { 481 520 int n = 8; … … 554 593 } 555 594 556 public IEnumerable<Node> IterateCombinations() {557 foreach (int val in PossibleValues) {558 this.ActualValue = val;559 if (ChildNodes.Count > 0) {560 List<IEnumerable<Node>> lists = new List<IEnumerable<Node>>();561 List<IEnumerator<Node>> enumerators = new List<IEnumerator<Node>>();562 563 foreach (Node child in ChildNodes) {564 IEnumerable<Node> combinations = child.IterateCombinations();565 IEnumerator<Node> enumerator = combinations.GetEnumerator();566 enumerator.MoveNext(); // initialize567 lists.Add(combinations);568 enumerators.Add(enumerator);569 }570 571 572 bool abort = false;573 while (!abort) {574 abort = true;575 foreach (var enumerator in enumerators) {576 if (enumerator.MoveNext()) {577 abort = false;578 yield return this;579 }580 }581 }582 583 } else {584 yield return this;585 }586 }587 }588 589 595 public override string ToString() { 590 596 StringBuilder sb = new StringBuilder(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/app.config
r5144 r5184 13 13 </assemblyBinding> 14 14 </runtime> 15 <startup><supportedRuntime version="v 2.0.50727"/></startup></configuration>15 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj
r5144 r5184 11 11 <RootNamespace>HeuristicLab.Problems.MetaOptimization.Views</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Problems.MetaOptimization.Views-3.3</AssemblyName> 13 <TargetFrameworkVersion>v 3.5</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> 15 15 <TargetFrameworkProfile /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/MetaOptimizationProblemView.cs
r5144 r5184 62 62 } 63 63 if (result == System.Windows.Forms.DialogResult.OK) { 64 Experiment experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm); 64 Experiment experiment; 65 if (Content.Repetitions.Value > 1) { 66 experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm, true, Content.Repetitions.Value); 67 } else { 68 experiment = Content.ParameterConfigurationTree.GenerateExperiment(Content.Algorithm); 69 } 65 70 MainFormManager.MainForm.ShowContent(experiment); 66 71 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs
r5110 r5184 73 73 if (objectSelectorDialog.ShowDialog(this) == DialogResult.OK) { 74 74 try { 75 IItem value = objectSelectorDialog.Item;75 IItem value = (IItem)objectSelectorDialog.Item.Clone(); 76 76 return new ValueConfiguration(value, value.GetType()); 77 77 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Creators/RandomParameterConfigurationCreator.cs
r5009 r5184 21 21 } 22 22 public ILookupParameter<ParameterConfigurationTree> InitialParameterConfigurationParameter { 23 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters[ "InitialParameterConfigurationTree"]; }23 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters[MetaOptimizationProblem.ParameterConfigurationTreeParameterName]; } 24 24 } 25 25 26 public I LookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {27 get { return (I LookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }26 public IValueLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 27 get { return (IValueLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTreeSolutionCandidate"]; } 28 28 } 29 29 … … 33 33 public RandomParameterConfigurationCreator() : base() { 34 34 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation.")); 35 Parameters.Add(new LookupParameter<ParameterConfigurationTree>( "InitialParameterConfigurationTree", "The parameter configuration tree on which the new solution will be based on."));36 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "The new random parameter set."));35 Parameters.Add(new LookupParameter<ParameterConfigurationTree>(MetaOptimizationProblem.ParameterConfigurationTreeParameterName, "The parameter configuration tree on which the new solution will be based on.")); 36 Parameters.Add(new ValueLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTreeSolutionCandidate", "The new random parameter set.")); 37 37 } 38 38 public override IDeepCloneable Clone(Cloner cloner) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs
r5112 r5184 15 15 [Item("ParameterConfigurationCrossover", "TODO")] 16 16 [StorableClass] 17 public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, I Crossover {17 public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, IParameterConfigurationCrossover { 18 18 public override bool CanChangeName { 19 19 get { return false; } … … 23 23 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 24 24 } 25 public ILookupParameter<ItemArray< IValueConfiguration>> ParentsParameter {26 get { return (ScopeTreeLookupParameter< IValueConfiguration>)Parameters["Parents"]; }25 public ILookupParameter<ItemArray<ParameterConfigurationTree>> ParentsParameter { 26 get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["Parents"]; } 27 27 } 28 public ILookupParameter< IValueConfiguration> ChildParameter {29 get { return (ILookupParameter< IValueConfiguration>)Parameters["Child"]; }28 public ILookupParameter<ParameterConfigurationTree> ChildParameter { 29 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["Child"]; } 30 30 } 31 31 … … 43 43 : base() { 44 44 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 45 Parameters.Add(new ScopeTreeLookupParameter<IValueConfiguration>("Parents", "The parent vectors which should be crossed.")); 46 ParentsParameter.ActualName = "ParameterConfigurationTree"; 47 Parameters.Add(new LookupParameter<IValueConfiguration>("Child", "The child vector resulting from the crossover.")); 48 ChildParameter.ActualName = "ParameterConfigurationTree"; 45 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed.")); 46 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover.")); 49 47 50 48 Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, "")); … … 56 54 57 55 public override IOperation Apply() { 58 IValueConfiguration child1 = (IValueConfiguration)ParentsParameter.ActualValue[0].Clone();59 IValueConfiguration child2 = (IValueConfiguration)ParentsParameter.ActualValue[1];56 ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone(); 57 ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 60 58 61 59 //child1.Cross(child2, RandomParameter.ActualValue); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs
r5144 r5184 10 10 private IOptimizable node; 11 11 private List<IEnumerator> enumerators; 12 IEnumerator valueEnumerator; 12 private EnumeratorCollectionEnumerator<IItem> valueEnumerator; 13 private bool initialized = false; 13 14 14 15 public ParameterCombinationsEnumerator(IOptimizable node) { … … 21 22 } 22 23 object IEnumerator.Current { 23 get { return Current; } 24 get { 25 if (!initialized) 26 throw new SystemException("Enumeration not started. Call MoveNext!"); 27 return Current; 28 } 24 29 } 25 30 … … 27 32 28 33 public bool MoveNext() { 29 int i = 0; 30 bool ok = false; 31 while (!ok && i < enumerators.Count) { 32 if (enumerators[i].MoveNext()) { 33 ok = true; 34 if (!initialized) { 35 foreach (var enu in enumerators) { 36 enu.Reset(); 37 if (!enu.MoveNext()) 38 return false; 39 } 40 initialized = true; 41 } else { 42 int i = 0; 43 bool ok = false; 44 while (!ok && i < enumerators.Count) { 45 if (enumerators[i].MoveNext()) { 46 ok = true; 47 } else { 48 i++; 49 } 50 } 51 52 if (ok) { 53 for (int k = i - 1; k >= 0; k--) { 54 enumerators[k].Reset(); 55 enumerators[k].MoveNext(); 56 } 34 57 } else { 35 i++;58 return false; 36 59 } 37 }38 39 if (ok) {40 for (int k = i - 1; k >= 0; k--) {41 enumerators[k].Reset();42 enumerators[k].MoveNext();43 }44 } else {45 return false;46 60 } 47 61 … … 61 75 enumerators.Clear(); 62 76 valueEnumerator = null; 77 initialized = false; 63 78 64 79 var pc = node as IParameterConfiguration; 65 80 if (pc != null) { 66 valueEnumerator = pc.ValueConfigurations.CheckedItems.ToArray().GetEnumerator(); 67 //valueEnumerator.Reset(); 68 enumerators.Add(valueEnumerator); 81 valueEnumerator = new EnumeratorCollectionEnumerator<IItem>(); 69 82 70 83 foreach (var valueConfiguration in pc.ValueConfigurations.CheckedItems) { … … 72 85 var enumerator = new ParameterCombinationsEnumerator(valueConfiguration); 73 86 enumerator.Reset(); 74 enumerator.MoveNext(); 75 enumerators.Add(enumerator); 87 valueEnumerator.AddEnumerator(enumerator); 88 } else { 89 valueEnumerator.AddEnumerator(new List<IItem> { valueConfiguration }.GetEnumerator()); 76 90 } 77 91 } 92 valueEnumerator.Reset(); 93 enumerators.Add(valueEnumerator); 78 94 } 79 95 … … 81 97 if (vc != null) { 82 98 if (vc.RangeConstraint != null) { 83 valueEnumerator = vc.RangeConstraint.GetCombinations().ToArray().GetEnumerator();84 //valueEnumerator.Reset();85 //enumerator.MoveNext();99 valueEnumerator = new EnumeratorCollectionEnumerator<IItem>(); 100 valueEnumerator.AddEnumerator(vc.RangeConstraint.GetCombinations().GetEnumerator()); 101 valueEnumerator.Reset(); 86 102 enumerators.Add(valueEnumerator); 87 103 } else { … … 90 106 var enumerator = new ParameterCombinationsEnumerator(parameterConfiguration); 91 107 enumerator.Reset(); 92 enumerator.MoveNext();93 108 enumerators.Add(enumerator); 94 109 } … … 97 112 } 98 113 } 114 } 99 115 116 /// <summary> 117 /// Enumerator which can enumerate all elements of a list of enumerators 118 /// </summary> 119 /// <typeparam name="T"></typeparam> 120 public class EnumeratorCollectionEnumerator<T> : IEnumerator<T> { 121 private List<IEnumerator<T>> enumerators = new List<IEnumerator<T>>(); 122 private IEnumerator<IEnumerator<T>> currentEnumerator; 123 124 public EnumeratorCollectionEnumerator() { } 125 126 public void AddEnumerator(IEnumerator<T> enumerator) { 127 enumerators.Add(enumerator); 128 } 129 130 public void Dispose() { } 131 132 public T Current { 133 get { return currentEnumerator.Current.Current; } 134 } 135 136 object IEnumerator.Current { 137 get { return this.Current; } 138 } 139 140 public bool MoveNext() { 141 bool ok = currentEnumerator.Current.MoveNext(); 142 if (!ok) { 143 ok = currentEnumerator.MoveNext(); 144 if (!ok) 145 return false; 146 else 147 return this.MoveNext(); 148 } 149 return true; 150 } 151 152 public void Reset() { 153 foreach (var enu in enumerators) { 154 enu.Reset(); 155 } 156 currentEnumerator = enumerators.GetEnumerator(); 157 currentEnumerator.Reset(); 158 currentEnumerator.MoveNext(); 159 } 100 160 } 101 161 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r5144 r5184 14 14 [StorableClass] 15 15 public class ParameterConfigurationTree : ValueConfiguration, IEnumerable { 16 //[Storable]17 //public EngineAlgorithm Algorithm {18 // get { return (EngineAlgorithm)base.ActualValue.Value; }19 // set {20 // base.ActualValue.Value = value;21 // }22 //}23 24 16 [Storable] 25 17 private DoubleValue bestQuality; … … 83 75 get { return runs; } 84 76 set { runs = value; } 85 } 86 77 } 78 79 [Storable] 87 80 protected IDictionary<string, IItem> parameters; 88 81 public IDictionary<string, IItem> Parameters { … … 109 102 : base(original, cloner) { 110 103 this.bestQuality = cloner.Clone(original.BestQuality); 104 this.averageQuality = cloner.Clone(original.averageQuality); 105 this.worstQuality = cloner.Clone(original.worstQuality); 106 this.qualityStandardDeviation = cloner.Clone(original.qualityStandardDeviation); 107 this.qualityVariance = cloner.Clone(original.qualityVariance); 108 this.averageExecutionTime = cloner.Clone(original.averageExecutionTime); 109 this.repetitions = cloner.Clone(original.repetitions); 110 this.runs = cloner.Clone(original.runs); 111 111 this.parameters = new Dictionary<string, IItem>(); 112 112 foreach (var p in original.parameters) { … … 182 182 } 183 183 184 public Experiment GenerateExperiment(IAlgorithm algorithm ) {184 public Experiment GenerateExperiment(IAlgorithm algorithm, bool createBatchRuns, int repetitions) { 185 185 Experiment experiment = new Experiment(); 186 186 foreach (IValueConfiguration combination in this) { 187 187 IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone(); 188 clonedAlg.Name = combination. ToParameterInfoString();188 clonedAlg.Name = combination.ParameterInfoString; 189 189 combination.Parameterize(clonedAlg); 190 experiment.Optimizers.Add(clonedAlg); 190 clonedAlg.StoreAlgorithmInEachRun = false; 191 if (createBatchRuns) { 192 BatchRun batchRun = new BatchRun(string.Format("BatchRun: {0}", combination.ParameterInfoString)); 193 batchRun.Algorithm = clonedAlg; 194 batchRun.Repetitions = repetitions; 195 experiment.Optimizers.Add(batchRun); 196 } else { 197 experiment.Optimizers.Add(clonedAlg); 198 } 191 199 } 192 200 return experiment; 201 } 202 203 public Experiment GenerateExperiment(IAlgorithm algorithm) { 204 return GenerateExperiment(algorithm, false, 0); 193 205 } 194 206 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5144 r5184 300 300 } 301 301 302 public string ToParameterInfoString() { 303 StringBuilder sb = new StringBuilder(); 304 if (this.Optimize) { 305 sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value)); 306 //sb.Append(" ("); 307 //var subParams = new List<string>(); 308 //if (this.ActualValue.Value is IParameterizedItem) { 309 // subParams.Add(this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ToParameterInfoString()); 310 //} 311 //sb.Append(string.Join(", ", subParams.ToArray())); 312 //sb.Append(")"); 313 } 314 return sb.ToString(); 302 public string ParameterInfoString { 303 get { 304 StringBuilder sb = new StringBuilder(); 305 if (this.Optimize) { 306 sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value != null ? this.ActualValue.Value.ToString() : "null")); 307 308 if (this.ActualValue.Value is IParameterizedItem) { 309 string subParams = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ParameterInfoString; 310 if (!string.IsNullOrEmpty(subParams)) { 311 sb.Append(" ("); 312 sb.Append(subParams); 313 sb.Append(")"); 314 } 315 } 316 } 317 return sb.ToString(); 318 } 315 319 } 316 320 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs
r5144 r5184 44 44 45 45 while (value <= UpperBound.Value) { 46 //yield return new DoubleValue(value);47 46 solutions.Add(new DoubleValue(value)); 48 47 value += StepSize.Value; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs
r5144 r5184 44 44 45 45 while (value <= this.UpperBound.Value) { 46 //yield return new IntValue(value);47 46 solutions.Add(new IntValue(value)); 48 47 value += this.StepSize.Value; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs
r5144 r5184 39 39 40 40 while (value <= UpperBound.Value) { 41 //yield return new PercentValue(value);42 41 solutions.Add(new PercentValue(value)); 43 42 value += StepSize.Value; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5144 r5184 95 95 RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01)); 96 96 } else if (actualValue.ValueDataType == typeof(PercentValue)) { 97 RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.0 01));97 RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.01)); 98 98 } else if (actualValue.ValueDataType == typeof(BoolValue)) { 99 99 this.IsOptimizable = false; // there is nothing to configure for bools … … 211 211 } 212 212 213 public string ToParameterInfoString() { 214 StringBuilder sb = new StringBuilder(); 215 if (this.Optimize) { 216 if (this.ParameterConfigurations.Count > 0) { 217 var parameterInfos = new List<string>(); 218 foreach (var pc in this.ParameterConfigurations) { 219 if (pc.Optimize) parameterInfos.Add(pc.ToParameterInfoString()); 220 } 221 sb.Append(string.Join(", ", parameterInfos.ToArray())); 222 } 223 } 224 return sb.ToString(); 213 public string ParameterInfoString { 214 get { 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 } 224 } 225 return sb.ToString(); 226 } 225 227 } 226 228 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5111 r5184 19 19 public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator { 20 20 private bool algorithmStopped; 21 private bool algorithmExceptionOccured; 21 22 22 23 public ILookupParameter<DoubleValue> QualityParameter { … … 69 70 70 71 algorithmStopped = false; 71 algorithm.Stopped += new EventHandler(ActualValue_Stopped); 72 algorithmExceptionOccured = false; 73 algorithm.Stopped += new EventHandler(algorithm_Stopped); 74 algorithm.Paused += new EventHandler(algorithm_Paused); 75 algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred); 72 76 73 77 List<double> qualities = new List<double>(); … … 85 89 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) 86 90 } 87 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);88 executionTimes.Add(algorithm.ExecutionTime);89 91 90 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs 91 algorithm.Runs.Last().Parameters.Clear(); 92 // but keep the problem, since this differs in runs 93 algorithm.Runs.Last().Parameters.Add("Problem", problem); 92 if (algorithmExceptionOccured) { 93 // this parametercombination was bad. set penalty for this solution 94 qualities.Add(double.MaxValue); // todo: respect Maximization 95 executionTimes.Add(algorithm.ExecutionTime); 96 } else { 97 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value); 98 executionTimes.Add(algorithm.ExecutionTime); 99 100 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs 101 algorithm.Runs.Last().Parameters.Clear(); 102 // but keep the problem, since this differs in runs 103 algorithm.Runs.Last().Parameters.Add("Problem", problem); 104 } 94 105 algorithmStopped = false; 106 algorithmExceptionOccured = false; 95 107 } 96 97 108 } 98 109 99 100 algorithm.Stopped -= new EventHandler(ActualValue_Stopped); 110 algorithm.Stopped -= new EventHandler(algorithm_Stopped); 111 algorithm.Paused -= new EventHandler(algorithm_Paused); 112 algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(algorithm_ExceptionOccurred); 101 113 algorithm.Prepare(); 102 114 … … 104 116 105 117 ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds))); 106 ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions;118 ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone(); 107 119 ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First()); 108 120 ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average()); … … 110 122 ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance()); 111 123 ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation()); 112 ParameterConfigurationParameter.ActualValue.Runs = algorithm.Runs;124 ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone(); 113 125 114 126 double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance) … … 116 128 117 129 return base.Apply(); 130 } 131 132 private void algorithm_Paused(object sender, EventArgs e) { 133 algorithmStopped = true; 134 } 135 136 private void algorithm_Stopped(object sender, EventArgs e) { 137 algorithmStopped = true; 138 } 139 140 void algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 141 algorithmExceptionOccured = true; 118 142 } 119 143 … … 128 152 } 129 153 130 void ActualValue_Stopped(object sender, EventArgs e) { 131 algorithmStopped = true; 132 } 154 133 155 } 134 156 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5144 r5184 11 11 <RootNamespace>HeuristicLab.Problems.MetaOptimization</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Problems.MetaOptimization-3.3</AssemblyName> 13 <TargetFrameworkVersion>v 3.5</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> 15 15 <TargetFrameworkProfile /> … … 147 147 <Compile Include="Encoding\ValueConfigurations\ValueConfiguration.cs" /> 148 148 <Compile Include="Encoding\ValueConfigurations\CheckedValueConfigurationCollection.cs" /> 149 <Compile Include="Interfaces\IParameterConfigurationCrossover.cs" /> 149 150 <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" /> 150 151 <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5144 r5184 18 18 void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip); 19 19 void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross); 20 string ToParameterInfoString();20 string ParameterInfoString { get; } 21 21 22 22 event EventHandler IsOptimizableChanged; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfigurationCreator.cs
r4839 r5184 2 2 3 3 namespace HeuristicLab.Problems.MetaOptimization { 4 public interface IParameterConfigurationCreator : ISolutionCreator {4 public interface IParameterConfigurationCreator : ISolutionCreator, IParameterConfigurationOperator { 5 5 } 6 6 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfigurationEvaluator.cs
r5111 r5184 5 5 /// An interface which represents an evaluation operator for Meta Optimization Problems. 6 6 /// </summary> 7 public interface IParameterConfigurationEvaluator : ISingleObjectiveEvaluator {}7 public interface IParameterConfigurationEvaluator : ISingleObjectiveEvaluator, IParameterConfigurationOperator { } 8 8 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5144 r5184 40 40 public const string ProblemTypeParameterName = "ProblemType"; 41 41 public const string ProblemsParameterName = "Problems"; 42 public const string ParameterConfigurationTreeParameterName = " ParameterConfigurationTree";42 public const string ParameterConfigurationTreeParameterName = "InitialParameterConfigurationTree"; 43 43 public const string RepetitionsParameterName = "Repetitions"; 44 44 … … 95 95 set { RepetitionsParameter.Value = value; } 96 96 } 97 private BestParameterConfigurationAnalyzer BestParameterConfigurationAnalyzer { 98 get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); } 99 } 97 100 #endregion 98 101 … … 101 104 Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem())); 102 105 Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>())); 103 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, " Listof algorithm parameters that should be optimized."));106 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized.")); 104 107 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); 105 108 … … 109 112 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, new NormalDoubleValueManipulator())); 110 113 111 112 114 Maximization = new BoolValue(false); 113 115 SolutionCreator = new RandomParameterConfigurationCreator(); … … 116 118 InitializeOperators(); 117 119 RegisterParameterEvents(); 120 ParameterizeAnalyzer(); 118 121 ParameterizeSolutionCreator(); 119 122 ParameterizeEvaluator(); … … 158 161 } 159 162 private void ParameterizeAnalyzer() { 163 if (BestParameterConfigurationAnalyzer != null) { 164 BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 165 } 160 166 } 161 167 private void ParameterizeOperators() { 162 168 foreach (IParameterConfigurationCrossover op in Operators.OfType<IParameterConfigurationCrossover>()) { 169 op.ParentsParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 170 op.ChildParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 171 } 172 foreach (IParameterConfigurationManipulator op in Operators.OfType<IParameterConfigurationManipulator>()) { 173 op.ParameterConfigurationTreeParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 174 } 163 175 } 164 176
Note: See TracChangeset
for help on using the changeset viewer.