- Timestamp:
- 12/21/10 01:13:49 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 7 added
- 4 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5111 r5144 1 using System.Collections.Generic; 2 using System.Diagnostics; 1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using System.IO; 3 5 using System.Linq; 6 using System.Text; 7 using System.Threading; 8 using HeuristicLab.Algorithms.EvolutionStrategy; 4 9 using HeuristicLab.Algorithms.GeneticAlgorithm; 10 using HeuristicLab.Common; 5 11 using HeuristicLab.Core; 12 using HeuristicLab.Data; 13 using HeuristicLab.Optimization; 6 14 using HeuristicLab.PluginInfrastructure; 7 using HeuristicLab.Parameters;8 15 using HeuristicLab.Problems.MetaOptimization; 9 using HeuristicLab.Data; 10 using System; 11 using System.Threading; 16 using HeuristicLab.Problems.TestFunctions; 12 17 using HeuristicLab.Random; 13 using HeuristicLab.Optimization;14 using HeuristicLab.Common;15 using System.IO;16 using HeuristicLab.Problems.TestFunctions;17 using System.Text;18 18 using HeuristicLab.Selection; 19 using HeuristicLab.Algorithms.EvolutionStrategy;20 using HeuristicLab.PluginInfrastructure.Manager;21 19 22 20 namespace HeuristicLab.MetaOptimization.Test { … … 35 33 //TestTypeDiscovery(); 36 34 //TestOperators(); 37 35 //TestCombinations(); 36 //TestCombinations2(); 37 //TestCombinations3(); 38 TestCombinations4(); 39 38 40 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); 39 41 … … 45 47 IValueConfiguration algorithmVc = SetupGAAlgorithm(baseLevelAlgorithm, metaOptimizationProblem); 46 48 49 //TestToString(algorithmVc); 50 51 47 52 //Console.WriteLine("Press enter to start"); 48 53 //Console.ReadLine(); 49 54 //TestConfiguration(algorithmVc, baseLevelAlgorithm); 50 55 51 56 //Console.WriteLine("Press enter to start"); 52 57 //Console.ReadLine(); … … 58 63 } 59 64 65 private static void TestToString(IValueConfiguration algorithmVc) { 66 var random = new MersenneTwister(); 67 Console.WriteLine(algorithmVc.ToParameterInfoString()); 68 algorithmVc.Randomize(random); 69 Console.WriteLine(algorithmVc.ToParameterInfoString()); 70 algorithmVc.Randomize(random); 71 Console.WriteLine(algorithmVc.ToParameterInfoString()); 72 algorithmVc.Randomize(random); 73 } 74 75 private static void TestCombinations() { 76 Console.WriteLine("IntRange 3-18:3"); 77 IntValueRange intRange = new IntValueRange(new IntValue(3), new IntValue(18), new IntValue(3)); 78 foreach (var val in intRange.GetCombinations()) { 79 Console.WriteLine(val); 80 } 81 82 Console.WriteLine("DoubleRange 1.0-2.5:0.5"); 83 var dblRange = new DoubleValueRange(new DoubleValue(0.7), new DoubleValue(2.8), new DoubleValue(0.5)); 84 foreach (var val in dblRange.GetCombinations()) { 85 Console.WriteLine(val); 86 } 87 88 Console.WriteLine("PercentRange 33%-66%:33%"); 89 var pctRange = new PercentValueRange(new PercentValue(0.32), new PercentValue(0.98), new PercentValue(0.33)); 90 foreach (var val in pctRange.GetCombinations()) { 91 Console.WriteLine(val); 92 } 93 } 94 95 private static void TestCombinations3() { 96 Node root = new Node("root"); 97 root.ChildNodes.Add(new Node("root.n1")); 98 root.ChildNodes.Add(new Node("root.n2")); 99 Node n3 = new Node("root.n3"); 100 n3.ChildNodes.Add(new Node("root.n3.n1")); 101 n3.ChildNodes.Add(new Node("root.n3.n2")); 102 root.ChildNodes.Add(n3); 103 104 Console.WriteLine(root.ToString()); 105 Console.WriteLine("--"); 106 int cnt = 0; 107 var enumerator = new NodeEnumerator(root); 108 enumerator.Reset(); 109 while (enumerator.MoveNext()) { 110 Console.WriteLine(enumerator.Current.ToString()); 111 cnt++; 112 } 113 Console.WriteLine("count: " + cnt); 114 } 115 116 private static void TestCombinations4() { 117 GeneticAlgorithm ga = new GeneticAlgorithm(); 118 ga.Problem = new SingleObjectiveTestFunctionProblem(); 119 ParameterConfigurationTree vc = new ParameterConfigurationTree(ga); 120 121 //ConfigurePopulationSize(vc, 20, 100, 20); 122 //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 //} 129 130 int count = 0; 131 IEnumerator enumerator = new ParameterCombinationsEnumerator(vc); 132 enumerator.Reset(); 133 while (enumerator.MoveNext()) { 134 var current = (IValueConfiguration)enumerator.Current; 135 count++; 136 Console.WriteLine(current.ToParameterInfoString()); 137 } 138 Console.WriteLine("You are about to create {0} algorithms.", count); 139 140 Experiment experiment = vc.GenerateExperiment(ga); 141 foreach (var opt in experiment.Optimizers) { 142 Console.WriteLine(opt.Name); 143 } 144 } 145 60 146 private static void TestOperators() { 61 147 IRandom random = new MersenneTwister(); … … 64 150 manip.IntValueManipulatorParameter.ActualValue = new UniformIntValueManipulator(); 65 151 manip.DoubleValueManipulatorParameter.ActualValue = new NormalDoubleValueManipulator(); 66 152 67 153 var doubleRange = new DoubleValueRange(new DoubleValue(0), new DoubleValue(100), new DoubleValue(0.1)); 68 154 using (var sw = new StreamWriter("out-DoubleValue.txt")) { … … 70 156 var val = new DoubleValue(50); 71 157 NormalDoubleValueManipulator.ApplyStatic(random, val, doubleRange); 72 158 73 159 sw.WriteLine(val); 74 160 } … … 98 184 private static void TestTypeDiscovery() { 99 185 PluginLoader.pluginAssemblies.Any(); 100 186 101 187 var items = ApplicationManager.Manager.GetInstances(typeof(DoubleArray)).ToArray(); 102 188 … … 107 193 108 194 private static void TestMemoryLeak(GeneticAlgorithm metaLevelAlgorithm) { 109 IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem). AlgorithmParameterConfiguration;195 IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).ParameterConfigurationTree; 110 196 111 197 Console.WriteLine("Starting Memory Test..."); … … 160 246 161 247 metaOptimizationProblem.Algorithm = baseLevelAlgorithm; 162 IValueConfiguration algorithmVc = metaOptimizationProblem. AlgorithmParameterConfiguration;248 IValueConfiguration algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; 163 249 164 250 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { … … 171 257 }); 172 258 173 ConfigurePopulationSize(algorithmVc );174 ConfigureMutationRate(algorithmVc );259 ConfigurePopulationSize(algorithmVc, 20, 100, 1); 260 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01); 175 261 ConfigureMutationOperator(algorithmVc); 176 262 ConfigureElites(algorithmVc); 177 ConfigureSelectionOperator(algorithmVc );263 ConfigureSelectionOperator(algorithmVc, true); 178 264 return algorithmVc; 179 265 } … … 203 289 GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone(); 204 290 //clonedVc.Mutate(rand); 205 291 206 292 //.Apply(rand, clonedVc); todo 207 293 clonedVc.Parameterize(newAlg); … … 259 345 } 260 346 261 private static void ConfigureSelectionOperator(IValueConfiguration algorithmVc ) {347 private static void ConfigureSelectionOperator(IValueConfiguration algorithmVc, bool configureTournamenSize) { 262 348 var selectionOperatorPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Selector").SingleOrDefault(); 263 349 selectionOperatorPc.Optimize = true; … … 266 352 if (vc.ActualValue.ValueDataType == typeof(TournamentSelector)) { 267 353 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true); 268 vc.Optimize = true; 269 ConfigureTournamentGroupSize(vc); 354 if (configureTournamenSize) { 355 vc.Optimize = true; 356 ConfigureTournamentGroupSize(vc); 357 } 270 358 } else if (vc.ActualValue.ValueDataType == typeof(RandomSelector)) { 271 359 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true); … … 286 374 } 287 375 288 private static void ConfigurePopulationSize(IValueConfiguration algorithmVc ) {376 private static void ConfigurePopulationSize(IValueConfiguration algorithmVc, int lower, int upper, int stepsize) { 289 377 var populationSizePc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "PopulationSize").SingleOrDefault(); 290 378 populationSizePc.Optimize = true; 291 379 var populationSizeVc = populationSizePc.ValueConfigurations.First(); 292 380 populationSizeVc.Optimize = true; 293 populationSizeVc.RangeConstraint.LowerBound = new IntValue( 20);294 populationSizeVc.RangeConstraint.UpperBound = new IntValue( 100);295 populationSizeVc.RangeConstraint.StepSize = new IntValue( 1);296 } 297 298 private static void ConfigureMutationRate(IValueConfiguration algorithmVc ) {381 populationSizeVc.RangeConstraint.LowerBound = new IntValue(lower); 382 populationSizeVc.RangeConstraint.UpperBound = new IntValue(upper); 383 populationSizeVc.RangeConstraint.StepSize = new IntValue(stepsize); 384 } 385 386 private static void ConfigureMutationRate(IValueConfiguration algorithmVc, double lower, double upper, double stepsize) { 299 387 var mutationRatePc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "MutationProbability").SingleOrDefault(); 300 388 mutationRatePc.Optimize = true; 301 389 var mutationRateVc = mutationRatePc.ValueConfigurations.First(); 302 390 mutationRateVc.Optimize = true; 303 mutationRateVc.RangeConstraint.LowerBound = new PercentValue( 0.0);304 mutationRateVc.RangeConstraint.UpperBound = new PercentValue( 1.0);305 mutationRateVc.RangeConstraint.StepSize = new PercentValue( 0.01);391 mutationRateVc.RangeConstraint.LowerBound = new PercentValue(lower); 392 mutationRateVc.RangeConstraint.UpperBound = new PercentValue(upper); 393 mutationRateVc.RangeConstraint.StepSize = new PercentValue(stepsize); 306 394 } 307 395 … … 446 534 } 447 535 } 536 537 public class Node { 538 public string Name { get; set; } 539 public int ActualValue { get; set; } 540 public int[] PossibleValues { get; set; } 541 public List<Node> ChildNodes { get; set; } 542 543 public Node(string name) { 544 this.Name = name; 545 PossibleValues = new int[] { 1, 2, 3 }; 546 ChildNodes = new List<Node>(); 547 } 548 549 public void Init() { 550 this.ActualValue = PossibleValues.First(); 551 foreach (var child in ChildNodes) { 552 child.Init(); 553 } 554 } 555 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(); // initialize 567 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 public override string ToString() { 590 StringBuilder sb = new StringBuilder(); 591 sb.Append(string.Format("{0}:{1}", this.Name, this.ActualValue)); 592 if (this.ChildNodes.Count() > 0) { 593 sb.Append(" ("); 594 var lst = new List<string>(); 595 foreach (Node child in ChildNodes) { 596 lst.Add(child.ToString()); 597 } 598 sb.Append(string.Join(", ", lst.ToArray())); 599 sb.Append(")"); 600 } 601 602 return sb.ToString(); 603 } 604 } 605 606 public class NodeEnumerator : IEnumerator<Node> { 607 private Node node; 608 private List<IEnumerator> enumerators; 609 610 public NodeEnumerator(Node node) { 611 this.node = node; 612 this.enumerators = new List<IEnumerator>(); 613 } 614 615 public Node Current { 616 get { return node; } 617 } 618 object IEnumerator.Current { 619 get { return Current; } 620 } 621 622 public void Dispose() { } 623 624 public bool MoveNext() { 625 int i = 0; 626 bool ok = false; 627 while(!ok && i < enumerators.Count) { 628 if(enumerators[i].MoveNext()) { 629 ok = true; 630 } else { 631 i++; 632 } 633 } 634 635 if (ok) { 636 for (int k = i-1; k >= 0; k--) { 637 enumerators[k].Reset(); 638 enumerators[k].MoveNext(); 639 } 640 } else { 641 return false; 642 } 643 644 node.ActualValue = (int)enumerators[0].Current; 645 return true; 646 } 647 648 public void Reset() { 649 enumerators.Clear(); 650 enumerators.Add(node.PossibleValues.GetEnumerator()); 651 enumerators[0].Reset(); 652 653 foreach (var child in node.ChildNodes) { 654 var enumerator = new NodeEnumerator(child); 655 enumerator.Reset(); 656 enumerator.MoveNext(); 657 enumerators.Add(enumerator); 658 } 659 } 660 } 448 661 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/app.config
r4997 r5144 13 13 </assemblyBinding> 14 14 </runtime> 15 < /configuration>15 <startup><supportedRuntime version="v2.0.50727"/></startup></configuration> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj
r5111 r5144 99 99 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath> 100 100 </Reference> 101 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 102 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath> 103 </Reference> 104 <Reference Include="HeuristicLab.Optimization.Views-3.3"> 105 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization.Views-3.3.dll</HintPath> 106 </Reference> 101 107 <Reference Include="HeuristicLab.Parameters-3.3"> 102 108 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Parameters-3.3.dll</HintPath> … … 126 132 <DependentUpon>ConstrainedItemListView.cs</DependentUpon> 127 133 </Compile> 134 <Compile Include="MetaOptimizationProblemView.cs"> 135 <SubType>UserControl</SubType> 136 </Compile> 137 <Compile Include="MetaOptimizationProblemView.Designer.cs"> 138 <DependentUpon>MetaOptimizationProblemView.cs</DependentUpon> 139 </Compile> 128 140 <Compile Include="OptimizableView.cs"> 129 141 <SubType>UserControl</SubType> … … 133 145 </Compile> 134 146 <None Include="Properties\AssemblyInfo.cs.frame" /> 135 <Compile Include=" RootValueConfigurationView.cs">136 <SubType>UserControl</SubType> 137 </Compile> 138 <Compile Include=" RootValueConfigurationView.Designer.cs">139 <DependentUpon> RootValueConfigurationView.cs</DependentUpon>147 <Compile Include="ParameterConfigurationTreeView.cs"> 148 <SubType>UserControl</SubType> 149 </Compile> 150 <Compile Include="ParameterConfigurationTreeView.Designer.cs"> 151 <DependentUpon>ParameterConfigurationTreeView.cs</DependentUpon> 140 152 </Compile> 141 153 <Compile Include="ValueConfigurationViews\ValueConfigurationCheckedItemList.cs"> … … 171 183 </ItemGroup> 172 184 <ItemGroup> 185 <EmbeddedResource Include="MetaOptimizationProblemView.resx"> 186 <DependentUpon>MetaOptimizationProblemView.cs</DependentUpon> 187 </EmbeddedResource> 173 188 <EmbeddedResource Include="OptimizableView.resx"> 174 189 <DependentUpon>OptimizableView.cs</DependentUpon> 175 190 </EmbeddedResource> 176 <EmbeddedResource Include=" RootValueConfigurationView.resx">177 <DependentUpon> RootValueConfigurationView.cs</DependentUpon>191 <EmbeddedResource Include="ParameterConfigurationTreeView.resx"> 192 <DependentUpon>ParameterConfigurationTreeView.cs</DependentUpon> 178 193 </EmbeddedResource> 179 194 <EmbeddedResource Include="ValueConfigurationViews\RangeView.resx"> … … 187 202 </EmbeddedResource> 188 203 </ItemGroup> 189 <ItemGroup> 190 <Folder Include="ParameterConfigurationViews\" /> 191 </ItemGroup> 204 <ItemGroup /> 192 205 <ItemGroup> 193 206 <ProjectReference Include="..\..\HeuristicLab.Problems.MetaOptimization\3.3\HeuristicLab.Problems.MetaOptimization-3.3.csproj"> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r5112 r5144 8 8 using HeuristicLab.Optimization; 9 9 using HeuristicLab.Data; 10 using System.Collections; 10 11 11 12 namespace HeuristicLab.Problems.MetaOptimization { 12 13 // todo: storable, name, descr, ... 13 14 [StorableClass] 14 public class ParameterConfigurationTree : ValueConfiguration {15 public class ParameterConfigurationTree : ValueConfiguration, IEnumerable { 15 16 //[Storable] 16 17 //public EngineAlgorithm Algorithm { … … 180 181 ((IAlgorithm)item).CollectParameterValues(this.Parameters); 181 182 } 183 184 public Experiment GenerateExperiment(IAlgorithm algorithm) { 185 Experiment experiment = new Experiment(); 186 foreach (IValueConfiguration combination in this) { 187 IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone(); 188 clonedAlg.Name = combination.ToParameterInfoString(); 189 combination.Parameterize(clonedAlg); 190 experiment.Optimizers.Add(clonedAlg); 191 } 192 return experiment; 193 } 194 195 public IEnumerator GetEnumerator() { 196 IEnumerator enumerator = new ParameterCombinationsEnumerator(this); 197 enumerator.Reset(); 198 return enumerator; 199 } 200 201 public long GetCombinationCount() { 202 long cnt = 0; 203 foreach (var c in this) { 204 cnt++; 205 } 206 return cnt; 207 } 182 208 } 183 209 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5112 r5144 9 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 10 using HeuristicLab.PluginInfrastructure; 11 using System.Text; 11 12 12 13 namespace HeuristicLab.Problems.MetaOptimization { … … 299 300 } 300 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(); 315 } 316 301 317 public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter) { 302 318 if (parameter is IValueParameter) { … … 348 364 } 349 365 } 366 367 public void UpdateActualValueIndexToItem(IValueConfiguration vc) { 368 for (int i = 0; i < this.ValueConfigurations.CheckedItems.Count(); i++) { 369 if (this.ValueConfigurations.CheckedItems.ElementAt(i) == vc) { 370 this.actualValueConfigurationIndex = i; 371 return; 372 } 373 } 374 } 375 350 376 } 351 377 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs
r5112 r5144 37 37 if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value; 38 38 } 39 40 public override IEnumerable<DoubleValue> GetCombinations() { 41 var solutions = new List<DoubleValue>(); 42 double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value; 43 if (value < LowerBound.Value) value += StepSize.Value; 44 45 while (value <= UpperBound.Value) { 46 //yield return new DoubleValue(value); 47 solutions.Add(new DoubleValue(value)); 48 value += StepSize.Value; 49 } 50 return solutions; 51 } 39 52 } 40 53 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs
r5112 r5144 37 37 if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value; 38 38 } 39 40 public override IEnumerable<IntValue> GetCombinations() { 41 var solutions = new List<IntValue>(); 42 int value = (this.LowerBound.Value / StepSize.Value) * StepSize.Value; 43 if (value < this.LowerBound.Value) value += StepSize.Value; 44 45 while (value <= this.UpperBound.Value) { 46 //yield return new IntValue(value); 47 solutions.Add(new IntValue(value)); 48 value += this.StepSize.Value; 49 } 50 return solutions; 51 } 39 52 } 40 53 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs
r5112 r5144 32 32 return new DoubleValueRange(LowerBound, UpperBound, StepSize); 33 33 } 34 35 public override IEnumerable<PercentValue> GetCombinations() { 36 var solutions = new List<PercentValue>(); 37 double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value; 38 if (value < LowerBound.Value) value += StepSize.Value; 39 40 while (value <= UpperBound.Value) { 41 //yield return new PercentValue(value); 42 solutions.Add(new PercentValue(value)); 43 value += StepSize.Value; 44 } 45 return solutions; 46 } 34 47 } 35 48 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs
r5112 r5144 1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 2 4 using HeuristicLab.Common; 3 5 using HeuristicLab.Core; … … 206 208 207 209 protected abstract T GetRandomSample(IRandom random); 208 209 210 IItem IRange.GetRandomValue(IRandom random) { 210 211 return GetRandomValue(random); 211 212 } 213 214 public abstract IEnumerable<T> GetCombinations(); 215 IEnumerable<IItem> IRange.GetCombinations() { 216 return GetCombinations().Cast<IItem>().ToArray(); 217 } 212 218 } 213 219 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5112 r5144 9 9 using HeuristicLab.Encodings.IntegerVectorEncoding; 10 10 using HeuristicLab.PluginInfrastructure; 11 using System.Collections.Generic; 12 using System.Text; 11 13 12 14 namespace HeuristicLab.Problems.MetaOptimization { … … 89 91 this.IsOptimizable = true; 90 92 if (actualValue.ValueDataType == typeof(IntValue)) { 91 rangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));93 RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1)); 92 94 } else if (actualValue.ValueDataType == typeof(DoubleValue)) { 93 rangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));95 RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01)); 94 96 } else if (actualValue.ValueDataType == typeof(PercentValue)) { 95 rangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));97 RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001)); 96 98 } else if (actualValue.ValueDataType == typeof(BoolValue)) { 97 99 this.IsOptimizable = false; // there is nothing to configure for bools 98 100 } else { 99 rangeConstraint = null; 100 } 101 RegisterRangeConstraintEvents(); 101 RangeConstraint = null; 102 } 102 103 } 103 104 … … 155 156 } 156 157 #endregion 157 158 158 159 #region IItem Members 159 160 public override string ItemDescription { … … 169 170 } 170 171 #endregion 171 172 172 173 #region Event Handlers 173 174 public virtual event EventHandler ValueChanged; … … 208 209 return base.ToString(); 209 210 } 211 } 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(); 210 225 } 211 226 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5111 r5144 134 134 <Compile Include="ConstrainedItemList.cs" /> 135 135 <Compile Include="Encoding\NullValue.cs" /> 136 <Compile Include="Encoding\ParameterCombinationsEnumerator.cs" /> 136 137 <Compile Include="Encoding\RangeConstraints\PercentValueRange.cs"> 137 138 <SubType>Code</SubType> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5111 r5144 18 18 void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip); 19 19 void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross); 20 20 string ToParameterInfoString(); 21 21 22 event EventHandler IsOptimizableChanged; 22 23 event EventHandler OptimizeChanged; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs
r5111 r5144 14 14 15 15 void Parameterize(IValueParameter parameter); 16 void UpdateActualValueIndexToItem(IValueConfiguration vc); 16 17 } 17 18 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs
r5009 r5144 3 3 using HeuristicLab.Core; 4 4 using HeuristicLab.Data; 5 using System.Collections.Generic; 5 6 6 7 namespace HeuristicLab.Problems.MetaOptimization { … … 15 16 16 17 IItem GetRandomValue(IRandom random); 18 19 IEnumerable<IItem> GetCombinations(); 17 20 } 18 21 … … 22 25 new T StepSize { get; set; } 23 26 new T GetRandomValue(IRandom random); 27 new IEnumerable<T> GetCombinations(); 24 28 } 25 29 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs
r5009 r5144 2 2 using HeuristicLab.Core; 3 3 using HeuristicLab.Data; 4 using System.Collections.Generic; 4 5 5 6 namespace HeuristicLab.Problems.MetaOptimization { … … 8 9 IRange RangeConstraint { get; } 9 10 event EventHandler ValueChanged; 10 11 11 12 void Parameterize(IParameterizedItem item); 12 13 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5111 r5144 40 40 public const string ProblemTypeParameterName = "ProblemType"; 41 41 public const string ProblemsParameterName = "Problems"; 42 public const string ParameterConfiguration ParameterName = "InitialParameterConfigurationTree";42 public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree"; 43 43 public const string RepetitionsParameterName = "Repetitions"; 44 44 … … 58 58 get { return (ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; } 59 59 } 60 public IValueParameter<ParameterConfigurationTree> ParameterConfiguration Parameter {61 get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfiguration ParameterName]; }60 public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { 61 get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; } 62 62 } 63 63 public IValueParameter<IntValue> RepetitionsParameter { … … 87 87 set { ProblemsParameter.Value = value; } 88 88 } 89 public ParameterConfigurationTree AlgorithmParameterConfiguration{90 get { return ParameterConfiguration Parameter.Value; }91 set { ParameterConfiguration Parameter.Value = value; }89 public ParameterConfigurationTree ParameterConfigurationTree { 90 get { return ParameterConfigurationTreeParameter.Value; } 91 set { ParameterConfigurationTreeParameter.Value = value; } 92 92 } 93 93 public IntValue Repetitions { … … 101 101 Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem())); 102 102 Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>())); 103 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfiguration ParameterName, "List of algorithm parameters that should be optimized."));103 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "List of algorithm parameters that should be optimized.")); 104 104 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); 105 105 … … 122 122 Problems.Type = Problem.GetType(); 123 123 Algorithm.Problem = Problem; 124 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);124 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 125 125 } 126 126 … … 185 185 void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) { 186 186 Algorithm.Problem = Problem; 187 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);187 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 188 188 } 189 189 void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) { 190 190 Problems.Type = Problem.GetType(); 191 191 Algorithm.Problem = Problem; 192 ParameterConfiguration Parameter.ActualValue = new ParameterConfigurationTree(Algorithm);192 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 193 193 } 194 194 #endregion
Note: See TracChangeset
for help on using the changeset viewer.