Changeset 5277
- Timestamp:
- 01/11/11 16:00:17 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 3 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5267 r5277 31 31 //private static int baseAlgorithmMaxGenerations = 1000; 32 32 33 private static int metaAlgorithmPopulationSize = 1 0;33 private static int metaAlgorithmPopulationSize = 16; 34 34 private static int metaAlgorithmMaxGenerations = 20; 35 35 private static int metaProblemRepetitions = 3; 36 private static int baseAlgorithmMaxGenerations = 10;36 private static int baseAlgorithmMaxGenerations = 50; 37 37 38 38 static void Main(string[] args) { … … 54 54 //TestWaitAny(); 55 55 //TestExecutionTimeUpdateInvervalPerformance(); 56 TestMemoryConsumption(); 57 return; 56 //TestMemoryConsumption(); 58 57 59 58 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); … … 61 60 MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem(); 62 61 metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions); 63 GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);64 //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);62 //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem); 63 GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem); 65 64 //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem); 66 65 … … 106 105 algs.Add(clonedGa); 107 106 sw.Reset(); 108 ContentManager.Save((IStorableContent)metaLevelAlgorithm, "alg_" +i+".hl", true);107 ContentManager.Save((IStorableContent)metaLevelAlgorithm, "alg_" + i + ".hl", true); 109 108 Console.WriteLine("Cloned alg #{0}", i); 110 109 } … … 119 118 RepeatExecuteParallel(3, 1, 1, tb); 120 119 tb.AppendRow("--", "--", "--", "--", "--", "--", "--", "--", "--"); 121 RepeatExecuteParallel(repetitions, tasks, 1, tb); 122 RepeatExecuteParallel(repetitions, tasks, 2.5, tb); 120 RepeatExecuteParallel(repetitions, tasks, 1, tb); 121 RepeatExecuteParallel(repetitions, tasks, 2.5, tb); 123 122 RepeatExecuteParallel(repetitions, tasks, 5, tb); 124 123 RepeatExecuteParallel(repetitions, tasks, 10, tb); 125 124 RepeatExecuteParallel(repetitions, tasks, 25, tb); 126 125 RepeatExecuteParallel(repetitions, tasks, 50, tb); 127 RepeatExecuteParallel(repetitions, tasks, 100, tb); 128 RepeatExecuteParallel(repetitions, tasks, 250, tb); 129 RepeatExecuteParallel(repetitions, tasks, 500, tb); 126 RepeatExecuteParallel(repetitions, tasks, 100, tb); 127 RepeatExecuteParallel(repetitions, tasks, 250, tb); 128 RepeatExecuteParallel(repetitions, tasks, 500, tb); 130 129 RepeatExecuteParallel(repetitions, tasks, 1000, tb); 131 RepeatExecuteParallel(repetitions, tasks, 2500, tb); 130 RepeatExecuteParallel(repetitions, tasks, 2500, tb); 132 131 RepeatExecuteParallel(repetitions, tasks, 5000, tb); 133 132 … … 148 147 private static void RepeatExecuteParallel(int repetitions, int tasks, double executionTimeUpdateIntervalMs, TableBuilder tb) { 149 148 for (int i = 0; i < repetitions; i++) { 150 ExecuteParallel(tasks, executionTimeUpdateIntervalMs, tb); 151 Console.Clear(); 149 ExecuteParallel(tasks, executionTimeUpdateIntervalMs, tb); 150 Console.Clear(); 152 151 Console.WriteLine(tb.ToString()); 153 152 } … … 167 166 tasks[i] = new Task<TimeSpan>((alg) => { 168 167 Console.WriteLine("Task {0} started.", Task.CurrentId); 169 168 170 169 Stopwatch swx = new Stopwatch(); 171 170 swx.Start(); … … 197 196 double totalMilliseconds = tasks.Select(t => t.Result.TotalMilliseconds).Sum(); 198 197 tb.AppendRow( 199 taskCount.ToString(), 200 executionTimeUpdateIntervalMs.ToString(), 198 taskCount.ToString(), 199 executionTimeUpdateIntervalMs.ToString(), 201 200 TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds).ToString(), 202 TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds / taskCount).ToString(), 201 TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds / taskCount).ToString(), 203 202 sw.Elapsed.ToString(), 204 203 TimeSpan.FromMilliseconds(totalMilliseconds).ToString(), 205 204 (totalMilliseconds / sw.ElapsedMilliseconds).ToString("0.00"), 206 205 counter.ToString(), 207 (totalExecutionTimeMilliseconds /counter).ToString("0.00"));206 (totalExecutionTimeMilliseconds / counter).ToString("0.00")); 208 207 } 209 208 tasks = null; … … 510 509 ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; 511 510 512 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {513 Evaluator = new GriewankEvaluator(),514 ProblemSize = new IntValue(5)515 });516 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {517 Evaluator = new GriewankEvaluator(),518 ProblemSize = new IntValue(50)519 });511 //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 512 // Evaluator = new GriewankEvaluator(), 513 // ProblemSize = new IntValue(5) 514 //}); 515 //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 516 // Evaluator = new GriewankEvaluator(), 517 // ProblemSize = new IntValue(50) 518 //}); 520 519 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 521 520 Evaluator = new GriewankEvaluator(), … … 526 525 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01); 527 526 ConfigureMutationOperator(algorithmVc); 528 ConfigureElites(algorithmVc, 0, 10, 1);529 ConfigureSelectionOperator(algorithmVc, true);527 //ConfigureElites(algorithmVc, 0, 10, 1); 528 //ConfigureSelectionOperator(algorithmVc, true); 530 529 return algorithmVc; 531 530 } … … 554 553 IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone(); 555 554 GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone(); 556 //clonedVc.Mutate(rand); 557 558 //.Apply(rand, clonedVc); todo 555 ParameterConfigurationManipulator.Apply(rand, clonedVc, new UniformIntValueManipulator(), new NormalDoubleValueManipulator()); 559 556 clonedVc.Parameterize(newAlg); 557 560 558 Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize)); 561 559 Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability)); … … 588 586 589 587 //clonedVc1.Cross(clonedVc2, rand); todo 588 589 ParameterConfigurationCrossover.Apply(rand, clonedVc1, clonedVc2, new DiscreteIntValueCrossover(), new AverageDoubleValueCrossover()); 590 590 clonedVc1.Parameterize(first); 591 591 … … 706 706 int currentGeneration = -1; 707 707 do { 708 Thread.Sleep( 500);708 Thread.Sleep(1000); 709 709 if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) { 710 710 while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueConfigurationCheckedItemList.cs
r5231 r5277 15 15 namespace HeuristicLab.Problems.MetaOptimization.Views { 16 16 [View("ValueConfigurationList View")] 17 [Content(typeof(ICheckedValueConfiguration Collection), IsDefaultView = true)]18 public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItem CollectionView<IValueConfiguration> {19 public new ICheckedValueConfiguration CollectionContent {20 get { return (ICheckedValueConfiguration Collection)base.Content; }17 [Content(typeof(ICheckedValueConfigurationList), IsDefaultView = true)] 18 public sealed partial class ValueConfigurationCheckedItemCollectionView : CheckedItemListView<IValueConfiguration> { 19 public new ICheckedValueConfigurationList Content { 20 get { return (ICheckedValueConfigurationList)base.Content; } 21 21 set { base.Content = value; } 22 22 } … … 28 28 29 29 protected override void DeregisterContentEvents() { 30 Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<I ValueConfiguration>(Content_ItemsRemoved);30 Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved); 31 31 base.DeregisterContentEvents(); 32 32 } … … 34 34 protected override void RegisterContentEvents() { 35 35 base.RegisterContentEvents(); 36 Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<I ValueConfiguration>(Content_ItemsRemoved);36 Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(Content_ItemsRemoved); 37 37 } 38 38 39 39 #region Event Handlers (Content) 40 private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<I ValueConfiguration> e) {40 private new void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 41 41 if (InvokeRequired) { 42 Invoke(new EventHandler<CollectionItemsChangedEventArgs<I ValueConfiguration>>(Content_ItemsRemoved), sender, e);42 Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>>>(Content_ItemsRemoved), sender, e); 43 43 } else { 44 44 base.Content_ItemsRemoved(sender, e); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs
r5207 r5277 58 58 ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 59 59 60 child1.Cross(RandomParameter.ActualValue, child2, Cross, this);60 child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue); 61 61 this.ChildParameter.ActualValue = child1; 62 62 … … 64 64 } 65 65 66 private static void Cross(IRandom random, IOptimizable configuartion, ParameterConfigurationCrossover pccross) { 67 if (configuartion is IValueConfiguration) { 68 var vc = configuartion as IValueConfiguration; 66 public static void Apply(IRandom random, IOptimizable configuartion, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 67 configuartion.Cross(random, other, Cross, intValueCrossover, doubleValueCrossover); 68 } 69 70 private static void Cross(IRandom random, IOptimizable configuartion, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 71 var vc = configuartion as IValueConfiguration; 72 var pc = configuartion as IParameterConfiguration; 73 if (vc != null) { 69 74 var value = vc.ActualValue.Value; 70 75 var range = vc.RangeConstraint; 71 76 72 77 if (value is IntValue) { 73 pccross.IntValueCrossoverParameter.ActualValue.Apply(random, (IntValue)value, (IntValueRange)range);78 intValueCrossover.Apply(random, (IntValue)value, (IntValue)((IValueConfiguration)other).ActualValue.Value, (IntValueRange)range); 74 79 } else if (value is PercentValue) { 75 pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());80 doubleValueCrossover.Apply(random, (PercentValue)value, (DoubleValue)((IValueConfiguration)other).ActualValue.Value, ((PercentValueRange)range).AsDoubleValueRange()); 76 81 } else if (value is DoubleValue) { 77 pccross.DoubleValueCrossoverParameter.ActualValue.Apply(random, (DoubleValue)value, (DoubleValueRange)range);82 doubleValueCrossover.Apply(random, (DoubleValue)value, (DoubleValue)((IValueConfiguration)other).ActualValue.Value, (DoubleValueRange)range); 78 83 } 79 } else if (configuartion is IParameterConfiguration) { 80 84 } else if (pc != null) { 85 if (random.NextDouble() > 0.5) { 86 pc.ActualValueConfigurationIndex = ((ParameterConfiguration)other).ActualValueConfigurationIndex; 87 } 88 pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue; 81 89 } 82 90 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Manipulators/ParameterConfigurationManipulator.cs
r5112 r5277 49 49 50 50 public sealed override IOperation Apply() { 51 Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, this);51 Apply(RandomParameter.ActualValue, ParameterConfigurationTreeParameter.ActualValue, IntValueManipulatorParameter.ActualValue, DoubleValueManipulatorParameter.ActualValue); 52 52 return base.Apply(); 53 53 } 54 54 55 public static void Apply(IRandom random, IValueConfiguration configuration, ParameterConfigurationManipulator pcmanip) {56 configuration.Mutate(random, Mutate, pcmanip);55 public static void Apply(IRandom random, IValueConfiguration configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 56 configuration.Mutate(random, Mutate, intValueManipulator, doubleValueManipulator); 57 57 } 58 58 59 private static void Mutate(IRandom random, IOptimizable configuration, ParameterConfigurationManipulator pcmanip) { 60 if (configuration is IValueConfiguration) { 61 var vc = configuration as IValueConfiguration; 59 private static void Mutate(IRandom random, IOptimizable configuration, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 60 var vc = configuration as IValueConfiguration; 61 var pc = configuration as IParameterConfiguration; 62 63 if (vc != null) { 62 64 var value = vc.ActualValue.Value; 63 65 var range = vc.RangeConstraint; 64 66 if (value is IntValue) { 65 pcmanip.IntValueManipulatorParameter.ActualValue.Apply(random, (IntValue)value, (IntValueRange)range);67 intValueManipulator.Apply(random, (IntValue)value, (IntValueRange)range); 66 68 } else if (value is PercentValue) { 67 pcmanip.DoubleValueManipulatorParameter.ActualValue.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange());69 doubleValueManipulator.Apply(random, (PercentValue)value, ((PercentValueRange)range).AsDoubleValueRange()); 68 70 } else if (value is DoubleValue) { 69 pcmanip.DoubleValueManipulatorParameter.ActualValue.Apply(random, (DoubleValue)value, (DoubleValueRange)range);71 doubleValueManipulator.Apply(random, (DoubleValue)value, (DoubleValueRange)range); 70 72 } 71 } else if (configuration is IParameterConfiguration) { 72 var pc = configuration as IParameterConfiguration; 73 pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.CheckedItems.Count()); 74 pc.ActualValue = pc.ValueConfigurations.CheckedItems.ElementAt(pc.ActualValueConfigurationIndex).ActualValue; 73 } else if (pc != null) { 74 do { 75 pc.ActualValueConfigurationIndex = random.Next(pc.ValueConfigurations.Count()); 76 } while (!pc.ValueConfigurations.ItemChecked(pc.ValueConfigurations[pc.ActualValueConfigurationIndex])); 77 pc.ActualValue = pc.ValueConfigurations[pc.ActualValueConfigurationIndex].ActualValue; 75 78 } 76 79 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs
r5184 r5277 82 82 83 83 foreach (var valueConfiguration in pc.ValueConfigurations.CheckedItems) { 84 if (valueConfiguration. Optimize) {85 var enumerator = new ParameterCombinationsEnumerator(valueConfiguration );84 if (valueConfiguration.Value.Optimize) { 85 var enumerator = new ParameterCombinationsEnumerator(valueConfiguration.Value); 86 86 enumerator.Reset(); 87 87 valueEnumerator.AddEnumerator(enumerator); 88 88 } else { 89 valueEnumerator.AddEnumerator(new List<IItem> { valueConfiguration }.GetEnumerator());89 valueEnumerator.AddEnumerator(new List<IItem> { valueConfiguration.Value }.GetEnumerator()); 90 90 } 91 91 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5267 r5277 12 12 using System.Reflection; 13 13 using HeuristicLab.Optimization; 14 using HeuristicLab.Collections; 14 15 15 16 namespace HeuristicLab.Problems.MetaOptimization { … … 78 79 79 80 [Storable] 80 protected ICheckedValueConfiguration CollectionvalueConfigurations;81 public ICheckedValueConfiguration CollectionValueConfigurations {81 protected ICheckedValueConfigurationList valueConfigurations; 82 public ICheckedValueConfigurationList ValueConfigurations { 82 83 get { return this.valueConfigurations; } 83 84 protected set { … … 135 136 validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray(); 136 137 } 137 this.ValueConfigurations = new CheckedValueConfiguration Collection();138 this.ValueConfigurations = new CheckedValueConfigurationList(); 138 139 this.ActualValue = new ConstrainedValue( 139 140 valueParameter.Value != null ? (IItem)valueParameter.Value.Clone() : null, … … 173 174 174 175 private void RegisterValueConfigurationEvents() { 175 this.ValueConfigurations.CheckedItemsChanged += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged);176 this.ValueConfigurations.ItemsAdded += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded);177 this.ValueConfigurations.ItemsRemoved += new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved);176 this.ValueConfigurations.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged); 177 this.ValueConfigurations.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded); 178 this.ValueConfigurations.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved); 178 179 } 179 180 180 181 private void DeregisterValueConfigurationEvents() { 181 this.ValueConfigurations.CheckedItemsChanged -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged);182 this.ValueConfigurations.ItemsAdded -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded);183 this.ValueConfigurations.ItemsRemoved -= new Collection s.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved);182 this.ValueConfigurations.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_CheckedItemsChanged); 183 this.ValueConfigurations.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsAdded); 184 this.ValueConfigurations.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(ValueConfigurations_ItemsRemoved); 184 185 } 185 186 … … 268 269 } 269 270 270 void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {271 void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 271 272 OnToStringChanged(); 272 273 } 273 void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {274 void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 274 275 OnToStringChanged(); 275 276 } 276 void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<I ValueConfiguration> e) {277 void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 277 278 OnToStringChanged(); 278 279 } … … 360 361 361 362 if (this.ActualValue.Value is IParameterizedItem) { 362 string subParams = this.ValueConfigurations .CheckedItems.ElementAt(actualValueConfigurationIndex).ParameterInfoString;363 string subParams = this.ValueConfigurations[actualValueConfigurationIndex].ParameterInfoString; 363 364 if (!string.IsNullOrEmpty(subParams)) { 364 365 sb.Append(" ("); … … 383 384 if (Optimize) { 384 385 if (this.ActualValue.Value is IParameterizedItem) { 385 this.ValueConfigurations .CheckedItems.ElementAt(actualValueConfigurationIndex).Parameterize((IParameterizedItem)this.ActualValue.Value);386 this.ValueConfigurations[actualValueConfigurationIndex].Parameterize((IParameterizedItem)this.ActualValue.Value); 386 387 } 387 388 } … … 410 411 public void Randomize(IRandom random) { 411 412 if (Optimize) { 412 foreach (var vc in this.ValueConfigurations.CheckedItems) { 413 vc.Randomize(random); 414 } 415 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 416 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 417 } 418 } 419 420 public void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip) { 421 if (Optimize) { 422 foreach (IValueConfiguration vc in this.ValueConfigurations.CheckedItems) { 423 vc.Mutate(random, mutate, pcmanip); 424 } 425 mutate(random, this, pcmanip); 426 } 427 } 428 429 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross) { 413 foreach (var vc in this.ValueConfigurations) { 414 if (this.ValueConfigurations.ItemChecked(vc)) { 415 vc.Randomize(random); 416 } 417 } 418 do { 419 actualValueConfigurationIndex = random.Next(ValueConfigurations.Count()); 420 } while (!this.ValueConfigurations.ItemChecked(this.ValueConfigurations[actualValueConfigurationIndex])); 421 this.ActualValue = this.ValueConfigurations[actualValueConfigurationIndex].ActualValue; 422 } 423 } 424 425 public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 426 if (Optimize) { 427 foreach (var vc in this.ValueConfigurations) { 428 if (this.ValueConfigurations.ItemChecked(vc)) { 429 vc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator); 430 } 431 } 432 mutate(random, this, intValueManipulator, doubleValueManipulator); 433 } 434 } 435 436 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 430 437 if (Optimize) { 431 438 IParameterConfiguration otherPc = (IParameterConfiguration)other; 432 439 for (int i = 0; i < this.ValueConfigurations.Count; i++) { 433 cross(random, other, pccross); 434 //this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i), random); 435 } 436 //if (random.NextDouble() > 0.5) { 437 // actualValueConfigurationIndex = ((ParameterConfiguration)other).actualValueConfigurationIndex; 438 //} 439 //this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 440 if (this.ValueConfigurations.ItemChecked(this.ValueConfigurations[i])) { 441 this.ValueConfigurations[i].Cross(random, otherPc.ValueConfigurations[i], cross, intValueCrossover, doubleValueCrossover); 442 } 443 } 444 cross(random, this, other, intValueCrossover, doubleValueCrossover); 440 445 } 441 446 } 442 447 443 448 public void UpdateActualValueIndexToItem(IValueConfiguration vc) { 444 for (int i = 0; i < this.ValueConfigurations.C heckedItems.Count(); i++) {445 if (this.ValueConfigurations. CheckedItems.ElementAt(i) == vc) {449 for (int i = 0; i < this.ValueConfigurations.Count(); i++) { 450 if (this.ValueConfigurations.ElementAt(i) == vc) { 446 451 this.actualValueConfigurationIndex = i; 447 452 return; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs
r5231 r5277 6 6 using HeuristicLab.Common; 7 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Collections; 8 9 9 10 namespace HeuristicLab.Problems.MetaOptimization { … … 11 12 // todo: control creatable item types 12 13 [StorableClass] 13 public class CheckedValueConfiguration Collection : CheckedItemCollection<IValueConfiguration>, ICheckedValueConfigurationCollection{14 public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList { 14 15 [Storable] 15 16 private int minItemCount = 1; … … 24 25 } 25 26 26 public CheckedValueConfiguration Collection(ItemSet<IItem> validValues) {27 public CheckedValueConfigurationList(ItemSet<IItem> validValues) { 27 28 this.validValues = validValues; 28 29 RegisterEvents(); 29 30 } 30 public CheckedValueConfiguration Collection() {31 public CheckedValueConfigurationList() { 31 32 RegisterEvents(); 32 33 } 33 34 [StorableConstructor] 34 protected CheckedValueConfiguration Collection(bool deserializing) : base(deserializing) {35 protected CheckedValueConfigurationList(bool deserializing) : base(deserializing) { 35 36 RegisterEvents(); 36 37 } 37 protected CheckedValueConfiguration Collection(CheckedValueConfigurationCollectionoriginal, Cloner cloner) : base(original, cloner) {38 protected CheckedValueConfigurationList(CheckedValueConfigurationList original, Cloner cloner) : base(original, cloner) { 38 39 this.minItemCount = original.MinItemCount; 39 40 this.validValues = original.validValues; … … 41 42 } 42 43 public override IDeepCloneable Clone(Cloner cloner) { 43 return new CheckedValueConfiguration Collection(this, cloner);44 return new CheckedValueConfigurationList(this, cloner); 44 45 } 45 46 [StorableHook(HookType.AfterDeserialization)] … … 49 50 50 51 private void RegisterEvents() { 51 this.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved); 52 } 53 private void DeregisterEvents() { 54 this.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(CheckedValueConfigurationCollection_ItemsRemoved); 52 this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved); 55 53 } 56 54 57 private void CheckedValueConfigurationCollection_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) { 55 private void DeregisterEvents() { 56 this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved); 57 } 58 59 private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 58 60 // auch collectionreset gehört berücksichtigt 59 61 // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt … … 66 68 //} 67 69 } 70 68 71 } 69 72 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5231 r5277 245 245 } 246 246 247 public void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip) {247 public void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator) { 248 248 if (Optimize) { 249 249 if (rangeConstraint != null) { 250 mutate(random, this, pcmanip);250 mutate(random, this, intValueManipulator, doubleValueManipulator); 251 251 } else { 252 252 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 253 pc.Mutate(random, mutate, pcmanip);254 } 255 } 256 } 257 } 258 259 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross) {253 pc.Mutate(random, mutate, intValueManipulator, doubleValueManipulator); 254 } 255 } 256 } 257 } 258 259 public void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover) { 260 260 if (Optimize) { 261 IValueConfiguration otherVc = (IValueConfiguration)other;262 261 if (rangeConstraint != null) { 263 cross(random, this, pccross); 264 265 //if (this.actualValue.ValueDataType == typeof(IntValue)) { 266 // //this.actualValue.Value = new IntValue((((IntValue)this.actualValue.Value).Value + ((IntValue)other.ActualValue.Value).Value) / 2); 267 268 // IntegerVector[] parents = new IntegerVector[2]; 269 // parents[0] = new IntegerVector(new int[] { ((IntValue)this.actualValue.Value).Value }); 270 // parents[1] = new IntegerVector(new int[] { ((IntValue)other.ActualValue.Value).Value }); 271 272 // this.actualValue.Value = new IntValue(HeuristicLab.Encodings.IntegerVectorEncoding.DiscreteCrossover.Apply(random, parents[0], parents[1]).First()); 273 274 //} else if (this.actualValue.ValueDataType == typeof(DoubleValue)) { 275 // //this.actualValue.Value = new DoubleValue((((DoubleValue)this.actualValue.Value).Value + ((DoubleValue)other.ActualValue.Value).Value) / 2); 276 // RealVector[] parents = new RealVector[2]; 277 // parents[0] = new RealVector(new double[] { ((DoubleValue)this.actualValue.Value).Value }); 278 // parents[1] = new RealVector(new double[] { ((DoubleValue)other.ActualValue.Value).Value }); 279 280 // if (random.NextDouble() < 0.5) { 281 // this.actualValue.Value = new DoubleValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 282 // } else { 283 // this.actualValue.Value = new DoubleValue(HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 284 // } 285 // //this.actualValue.Value = new DoubleValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 286 287 //} else if (this.actualValue.ValueDataType == typeof(PercentValue)) { 288 // //this.actualValue.Value = new PercentValue((((PercentValue)this.actualValue.Value).Value + ((PercentValue)other.ActualValue.Value).Value) / 2); 289 290 // RealVector[] parents = new RealVector[2]; 291 // parents[0] = new RealVector(new double[] { ((PercentValue)this.actualValue.Value).Value }); 292 // parents[1] = new RealVector(new double[] { ((PercentValue)other.ActualValue.Value).Value }); 293 294 // if (random.NextDouble() < 0.5) { 295 // this.actualValue.Value = new PercentValue(AverageCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 296 // } else { 297 // this.actualValue.Value = new PercentValue(HeuristicLab.Encodings.RealVectorEncoding.DiscreteCrossover.Apply(random, new ItemArray<RealVector>(parents)).First()); 298 // } 299 300 //} else if (this.actualValue.ValueDataType == typeof(BoolValue)) { 301 // if (random.NextDouble() > 0.5) 302 // this.actualValue.Value = this.actualValue.Value; 303 // else 304 // this.actualValue.Value = other.ActualValue.Value; 305 //} else { 306 // throw new NotImplementedException(); 307 //} 308 } else { 262 cross(random, this, other, intValueCrossover, doubleValueCrossover); 263 } else { 264 IValueConfiguration otherVc = (IValueConfiguration)other; 309 265 for (int i = 0; i < this.ParameterConfigurations.Count; i++) { 310 this.ParameterConfigurations.ElementAt(i).Cross(random, otherVc.ParameterConfigurations.ElementAt(i), cross, pccross);266 this.ParameterConfigurations.ElementAt(i).Cross(random, otherVc.ParameterConfigurations.ElementAt(i), cross, intValueCrossover, doubleValueCrossover); 311 267 } 312 268 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5184 r5277 149 149 <Compile Include="Interfaces\IParameterConfigurationCrossover.cs" /> 150 150 <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" /> 151 <Compile Include="Operators\Crossovers\AverageDoubleValueCrossover.cs" /> 152 <Compile Include="Operators\Crossovers\DiscreteDoubleValueCrossover.cs" /> 151 153 <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" /> 152 154 <Compile Include="Operators\Interfaces\IDoubleValueCrossover.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/ICheckedValueConfigurationCollection.cs
r5110 r5277 6 6 7 7 namespace HeuristicLab.Problems.MetaOptimization { 8 public interface ICheckedValueConfiguration Collection : ICheckedItemCollection<IValueConfiguration> {8 public interface ICheckedValueConfigurationList : ICheckedItemList<IValueConfiguration> { 9 9 int MinItemCount { get; } 10 10 IItemSet<IItem> ValidValues { get; } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5184 r5277 7 7 8 8 namespace HeuristicLab.Problems.MetaOptimization { 9 public delegate void MutateDelegate(IRandom random, IOptimizable configuartion, ParameterConfigurationManipulator pcmanip);10 public delegate void CrossDelegate(IRandom random, IOptimizable configuartion, ParameterConfigurationCrossover pccross);9 public delegate void MutateDelegate(IRandom random, IOptimizable configuartion, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator); 10 public delegate void CrossDelegate(IRandom random, IOptimizable configuartion, IOptimizable other, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover); 11 11 12 12 public interface IOptimizable : IItem { … … 16 16 17 17 void Randomize(IRandom random); 18 void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip);19 void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross);18 void Mutate(IRandom random, MutateDelegate mutate, IIntValueManipulator intValueManipulator, IDoubleValueManipulator doubleValueManipulator); 19 void Cross(IRandom random, IOptimizable other, CrossDelegate cross, IIntValueCrossover intValueCrossover, IDoubleValueCrossover doubleValueCrossover); 20 20 string ParameterInfoString { get; } 21 21 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs
r5207 r5277 9 9 string ParameterName { get; set; } 10 10 Type ParameterDataType { get; } 11 ICheckedValueConfiguration CollectionValueConfigurations { get; }11 ICheckedValueConfigurationList ValueConfigurations { get; } 12 12 Type[] ValidTypes { get; } 13 13 int ActualValueConfigurationIndex { get; set; } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5212 r5277 109 109 var validIntManipulators = new ItemSet<IIntValueManipulator>( ApplicationManager.Manager.GetInstances<IIntValueManipulator>()); 110 110 var validDoubleManipulators = new ItemSet<IDoubleValueManipulator>(ApplicationManager.Manager.GetInstances<IDoubleValueManipulator>()); 111 var validIntCrossovers = new ItemSet<IIntValueCrossover>(ApplicationManager.Manager.GetInstances<IIntValueCrossover>()); 112 var validDoubleCrossovers = new ItemSet<IDoubleValueCrossover>(ApplicationManager.Manager.GetInstances<IDoubleValueCrossover>()); 111 113 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.First())); 112 114 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.First())); 115 Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.First())); 116 Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(AverageDoubleValueCrossover)).SingleOrDefault())); 113 117 114 118 Maximization = new BoolValue(false); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/DiscreteIntValueCrossover.cs
r5111 r5277 28 28 } 29 29 30 public void Apply(IRandom random, IntValue value, IntValue Range range) {31 Apply (random, value, range);30 public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) { 31 ApplyStatic(random, value, other, range); 32 32 } 33 33 34 public static void ApplyStatic(IRandom random, IntValue value, IntValueRange range) { 35 34 public static void ApplyStatic(IRandom random, IntValue value, IntValue other, IntValueRange range) { 35 if (random.NextDouble() > 0.5) { 36 value.Value = other.Value; 37 } 36 38 } 37 39 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Interfaces/IDoubleValueCrossover.cs
r5111 r5277 9 9 namespace HeuristicLab.Problems.MetaOptimization { 10 10 public interface IDoubleValueCrossover : ICrossover { 11 void Apply(IRandom random, DoubleValue value, DoubleValue Range range);11 void Apply(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range); 12 12 } 13 13 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Interfaces/IIntValueCrossover.cs
r5111 r5277 9 9 namespace HeuristicLab.Problems.MetaOptimization { 10 10 public interface IIntValueCrossover : ICrossover { 11 void Apply(IRandom random, IntValue value, IntValue Range range);11 void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range); 12 12 } 13 13 }
Note: See TracChangeset
for help on using the changeset viewer.