- Timestamp:
- 12/04/10 18:08:43 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/HeuristicLab.MetaOptimization.Test.csproj
r4997 r5023 69 69 </Reference> 70 70 <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3"> 71 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>71 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath> 72 72 </Reference> 73 73 <Reference Include="HeuristicLab.Algorithms.LocalSearch-3.3"> … … 96 96 </Reference> 97 97 <Reference Include="HeuristicLab.Collections-3.3"> 98 <HintPath>..\..\ HeuristicLab.Hive\sources\HeuristicLab.Hive\HeuristicLab.Hive.Slave.Core\3.3\bin\Debug\HeuristicLab.Collections-3.3.dll</HintPath>98 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Collections-3.3.dll</HintPath> 99 99 </Reference> 100 100 <Reference Include="HeuristicLab.Common-3.3"> 101 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath>101 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Common-3.3.dll</HintPath> 102 102 </Reference> 103 103 <Reference Include="HeuristicLab.Common.Resources-3.3"> … … 105 105 </Reference> 106 106 <Reference Include="HeuristicLab.Core-3.3"> 107 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>107 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath> 108 108 </Reference> 109 109 <Reference Include="HeuristicLab.Core.Views-3.3"> … … 111 111 </Reference> 112 112 <Reference Include="HeuristicLab.Data-3.3"> 113 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Data-3.3.dll</HintPath>113 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data-3.3.dll</HintPath> 114 114 </Reference> 115 115 <Reference Include="HeuristicLab.Data.Views-3.3"> 116 116 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Data.Views-3.3.dll</HintPath> 117 117 </Reference> 118 <Reference Include="HeuristicLab.DebugEngine-3.3"> 119 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.DebugEngine-3.3.dll</HintPath> 120 </Reference> 118 121 <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3"> 119 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.dll</HintPath>120 </Reference> 121 <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">122 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath>122 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.dll</HintPath> 123 </Reference> 124 <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3"> 125 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath> 123 126 </Reference> 124 127 <Reference Include="HeuristicLab.Encodings.PermutationEncoding-3.3"> 125 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.dll</HintPath>128 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.dll</HintPath> 126 129 </Reference> 127 130 <Reference Include="HeuristicLab.Encodings.PermutationEncoding.Views-3.3"> 128 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.PermutationEncoding.Views-3.3.dll</HintPath>129 </Reference> 130 <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">131 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath>131 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.PermutationEncoding.Views-3.3.dll</HintPath> 132 </Reference> 133 <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3"> 134 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath> 132 135 </Reference> 133 136 <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3"> … … 152 155 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Netron-3.0.2672.12446.dll</HintPath> 153 156 </Reference> 154 <Reference Include="HeuristicLab.Operators-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">155 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Operators-3.3.dll</HintPath>157 <Reference Include="HeuristicLab.Operators-3.3"> 158 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Operators-3.3.dll</HintPath> 156 159 </Reference> 157 160 <Reference Include="HeuristicLab.Operators.Programmable-3.3"> … … 164 167 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Operators.Views.GraphVisualization-3.3.dll</HintPath> 165 168 </Reference> 166 <Reference Include="HeuristicLab.Optimization-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">167 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath>169 <Reference Include="HeuristicLab.Optimization-3.3"> 170 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization-3.3.dll</HintPath> 168 171 </Reference> 169 172 <Reference Include="HeuristicLab.Optimization.Operators-3.3"> … … 174 177 </Reference> 175 178 <Reference Include="HeuristicLab.Optimizer-3.3"> 176 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Optimizer-3.3.dll</HintPath>177 </Reference> 178 <Reference Include="HeuristicLab.Parameters-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">179 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Parameters-3.3.dll</HintPath>179 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimizer-3.3.dll</HintPath> 180 </Reference> 181 <Reference Include="HeuristicLab.Parameters-3.3"> 182 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Parameters-3.3.dll</HintPath> 180 183 </Reference> 181 184 <Reference Include="HeuristicLab.Parameters.Views-3.3"> 182 185 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Parameters.Views-3.3.dll</HintPath> 183 186 </Reference> 184 <Reference Include="HeuristicLab.Persistence-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">185 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Persistence-3.3.dll</HintPath>187 <Reference Include="HeuristicLab.Persistence-3.3"> 188 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Persistence-3.3.dll</HintPath> 186 189 </Reference> 187 190 <Reference Include="HeuristicLab.Persistence.GUI-3.3"> 188 191 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Persistence.GUI-3.3.dll</HintPath> 189 192 </Reference> 190 <Reference Include="HeuristicLab.PluginInfrastructure-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">191 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>193 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 194 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 192 195 </Reference> 193 196 <Reference Include="HeuristicLab.Problems.ArtificialAnt-3.3"> … … 230 233 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.Knapsack.Views-3.3.dll</HintPath> 231 234 </Reference> 235 <Reference Include="HeuristicLab.Problems.MetaOptimization-3.3"> 236 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.MetaOptimization-3.3.dll</HintPath> 237 </Reference> 238 <Reference Include="HeuristicLab.Problems.MetaOptimization.Views-3.3"> 239 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.MetaOptimization.Views-3.3.dll</HintPath> 240 </Reference> 232 241 <Reference Include="HeuristicLab.Problems.OneMax-3.3"> 233 242 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.OneMax-3.3.dll</HintPath> … … 237 246 </Reference> 238 247 <Reference Include="HeuristicLab.Problems.TestFunctions-3.3"> 239 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath>248 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath> 240 249 </Reference> 241 250 <Reference Include="HeuristicLab.Problems.TestFunctions.Views-3.3"> … … 257 266 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.ProtobufCS-0.9.1.dll</HintPath> 258 267 </Reference> 259 <Reference Include="HeuristicLab.Random-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">260 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath>261 </Reference> 262 <Reference Include="HeuristicLab.Selection-3.3 , Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">263 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.Selection-3.3.dll</HintPath>268 <Reference Include="HeuristicLab.Random-3.3"> 269 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath> 270 </Reference> 271 <Reference Include="HeuristicLab.Selection-3.3"> 272 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Selection-3.3.dll</HintPath> 264 273 </Reference> 265 274 <Reference Include="HeuristicLab.SequentialEngine-3.3"> 266 <HintPath>..\..\..\..\..\ Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath>275 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath> 267 276 </Reference> 268 277 <Reference Include="HeuristicLab.SharpDevelop-3.1.1.5327"> … … 311 320 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\WeifenLuo.WinFormsUI.Docking-2.3.1.dll</HintPath> 312 321 </Reference> 322 <Reference Include="ZedGraph"> 323 <HintPath>..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\ZedGraph.dll</HintPath> 324 </Reference> 313 325 </ItemGroup> 314 326 <ItemGroup> 315 327 <Compile Include="Program.cs" /> 316 328 <Compile Include="Properties\AssemblyInfo.cs" /> 317 </ItemGroup>318 <ItemGroup>319 <ProjectReference Include="..\HeuristicLab.Problems.MetaOptimization\3.3\HeuristicLab.Problems.MetaOptimization-3.3.csproj">320 <Project>{ABBC1DF6-FCC6-4F86-AB75-B6B3A72E7D17}</Project>321 <Name>HeuristicLab.Problems.MetaOptimization-3.3</Name>322 </ProjectReference>323 329 </ItemGroup> 324 330 <ItemGroup> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5009 r5023 12 12 using HeuristicLab.Random; 13 13 using HeuristicLab.Optimization; 14 using HeuristicLab.Common; 15 using System.IO; 16 using HeuristicLab.Problems.TestFunctions; 17 using System.Text; 18 using HeuristicLab.Selection; 14 19 15 20 namespace HeuristicLab.MetaOptimization.Test { 16 21 class Program { 17 private static int metaAlgorithmPopulationSize = 20; 18 private static int metaAlgorithmMaxGenerations = 100; 19 20 private static int baseAlgorithmPopulationSize = 20; 21 private static int baseAlgorithmMaxGenerations = 30; 22 private static int metaAlgorithmPopulationSize = 40; 23 private static int metaAlgorithmMaxGenerations = 30; 24 25 private static int baseAlgorithmMaxGenerations = 100; 22 26 23 27 static void Main(string[] args) { … … 31 35 IValueConfiguration algorithmVc = SetupAlgorithm(baseLevelAlgorithm, metaOptimizationProblem); 32 36 33 Console.WriteLine("Press enter to start");34 Console.ReadLine();35 TestConfiguration(algorithmVc, baseLevelAlgorithm);36 37 Console.WriteLine("Press enter to start");38 Console.ReadLine();37 //Console.WriteLine("Press enter to start"); 38 //Console.ReadLine(); 39 //TestConfiguration(algorithmVc, baseLevelAlgorithm); 40 41 //Console.WriteLine("Press enter to start"); 42 //Console.ReadLine(); 39 43 TestOptimization(metaLevelAlgorithm); 40 44 … … 50 54 Console.ReadLine(); 51 55 56 var clones = new List<object>(); 52 57 for (int i = 0; i < 1000; i++) { 53 58 var clone = algorithmVc.Clone(); 59 clones.Add(clone); 54 60 } 55 61 … … 70 76 metaLevelAlgorithm.Problem = metaOptimizationProblem; 71 77 metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine(); 78 79 metaLevelAlgorithm.Mutator = new ParameterConfigurationManipulator(); 80 metaLevelAlgorithm.MutationProbability.Value = 0.15; 81 72 82 return metaLevelAlgorithm; 73 83 } 74 84 75 85 private static IValueConfiguration SetupAlgorithm(GeneticAlgorithm baseLevelAlgorithm, MetaOptimizationProblem metaOptimizationProblem) { 76 baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { ProblemSize = new IntValue(2000) }; 77 baseLevelAlgorithm.PopulationSize.Value = baseAlgorithmPopulationSize; 86 baseLevelAlgorithm.Problem = new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 87 Evaluator = new GriewankEvaluator(), 88 ProblemSize = new IntValue(1000) 89 }; 78 90 baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations; 79 91 … … 85 97 ConfigureMutationRate(algorithmVc); 86 98 ConfigureMutationOperator(algorithmVc); 99 ConfigureElites(algorithmVc); 100 ConfigureSelectionOperator(algorithmVc); 87 101 return algorithmVc; 88 102 } 89 103 90 104 private static void TestConfiguration(IValueConfiguration algorithmVc, GeneticAlgorithm baseLevelAlgorithm) { 91 IRandom rand = new MersenneTwister();105 IRandom rand = new FastRandom(0); 92 106 // set random values 93 107 for (int i = 0; i < 10; i++) { … … 99 113 Console.WriteLine(string.Format("MutRate: original: {0}, randomized: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability)); 100 114 Console.WriteLine(string.Format("MutOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator)); 101 } 102 115 Console.WriteLine(string.Format("SelOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Selector, newAlg.Selector)); 116 Console.WriteLine(string.Format("GrSi: original: {0}, randomized: {1}", "?", ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value)); 117 Console.WriteLine("---"); 118 } 119 120 Console.WriteLine("======================="); 121 algorithmVc.Randomize(rand); 122 algorithmVc.Parameterize(baseLevelAlgorithm); 103 123 // mutate 104 124 for (int i = 0; i < 10; i++) { … … 110 130 Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability)); 111 131 Console.WriteLine(string.Format("MutOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator)); 112 } 113 132 Console.WriteLine(string.Format("SelOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Selector, newAlg.Selector)); 133 Console.WriteLine(string.Format("GrSi: original: {0}, mutated: {1}", ((TournamentSelector)baseLevelAlgorithm.Selector).GroupSizeParameter.Value, ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value)); 134 Console.WriteLine("---"); 135 } 136 137 Console.WriteLine("======================="); 114 138 // cross 115 139 for (int i = 0; i < 10; i++) { 116 140 IValueConfiguration clonedVc1 = (IValueConfiguration)algorithmVc.Clone(); 141 IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone(); 142 143 GeneticAlgorithm first = (GeneticAlgorithm)clonedVc1.ActualValue.Value.Clone(); 144 GeneticAlgorithm second = (GeneticAlgorithm)clonedVc2.ActualValue.Value.Clone(); 145 117 146 clonedVc1.Randomize(rand); 118 clonedVc1.Parameterize(baseLevelAlgorithm); 119 120 IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone(); 121 GeneticAlgorithm first = (GeneticAlgorithm)clonedVc1.ActualValue.Value; 122 GeneticAlgorithm second = (GeneticAlgorithm)clonedVc2.ActualValue.Value; 147 clonedVc1.Parameterize(first); 148 149 clonedVc2.Randomize(rand); 150 clonedVc2.Parameterize(second); 123 151 124 152 var popSizeBefore = first.PopulationSize.Value; 125 153 var mutRateBefore = first.MutationProbability.Value; 126 154 var mutOpBefore = first.Mutator; 155 var selOpBefore = first.Selector; 156 var groupSizeBefore = ((TournamentSelector)first.Selector).GroupSizeParameter.Value.Value; 127 157 128 158 clonedVc1.Cross(clonedVc2, rand); 129 clonedVc1.Parameterize( (GeneticAlgorithm)clonedVc2.ActualValue.Value);159 clonedVc1.Parameterize(first); 130 160 131 161 Console.WriteLine(string.Format("PopSize: first: {0}, second: {1}, crossed: {2}", popSizeBefore, second.PopulationSize, first.PopulationSize)); 132 162 Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutRateBefore, second.MutationProbability, first.MutationProbability)); 133 Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator)); 134 } 163 Console.WriteLine(string.Format("MutOp: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator)); 164 Console.WriteLine(string.Format("SelOp: first: {0}, second: {1}, crossed: {2}", selOpBefore, second.Selector, first.Selector)); 165 Console.WriteLine(string.Format("GrSi: first: {0}, second: {1}, crossed: {2}", groupSizeBefore, ((TournamentSelector)second.Selector).GroupSizeParameter.Value, ((TournamentSelector)first.Selector).GroupSizeParameter.Value)); 166 Console.WriteLine("---"); 167 } 168 Console.WriteLine("======================="); 135 169 } 136 170 … … 144 178 mutationOperator.ValueConfigurations.SetItemCheckedState(multiMutator, false); 145 179 } 180 } 181 182 private static void ConfigureSelectionOperator(IValueConfiguration algorithmVc) { 183 var selectionOperatorPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Selector").SingleOrDefault(); 184 selectionOperatorPc.Optimize = true; 185 186 foreach (var vc in selectionOperatorPc.ValueConfigurations) { 187 if (vc.ActualValue.ValueDataType == typeof(TournamentSelector)) { 188 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, true); 189 vc.Optimize = true; 190 ConfigureTournamentGroupSize(vc); 191 } else { 192 selectionOperatorPc.ValueConfigurations.SetItemCheckedState(vc, false); 193 } 194 } 195 } 196 197 private static void ConfigureTournamentGroupSize(IValueConfiguration tournamentVc) { 198 var groupSizePc = tournamentVc.ParameterConfigurations.Where(x => x.ParameterName == "GroupSize").SingleOrDefault(); 199 groupSizePc.Optimize = true; 200 201 groupSizePc.ValueConfigurations.First().Optimize = true; 202 groupSizePc.ValueConfigurations.First().RangeConstraint.LowerBound = new IntValue(0); 203 groupSizePc.ValueConfigurations.First().RangeConstraint.UpperBound = new IntValue(100); 204 groupSizePc.ValueConfigurations.First().RangeConstraint.StepSize = new IntValue(1); 146 205 } 147 206 … … 151 210 var populationSizeVc = populationSizePc.ValueConfigurations.First(); 152 211 populationSizeVc.Optimize = true; 153 populationSizeVc.RangeConstraint.LowerBound = new IntValue( 0);212 populationSizeVc.RangeConstraint.LowerBound = new IntValue(20); 154 213 populationSizeVc.RangeConstraint.UpperBound = new IntValue(100); 155 214 populationSizeVc.RangeConstraint.StepSize = new IntValue(1); … … 166 225 } 167 226 227 private static void ConfigureElites(IValueConfiguration algorithmVc) { 228 var elitesPc = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Elites").SingleOrDefault(); 229 elitesPc.Optimize = true; 230 var elitesVc = elitesPc.ValueConfigurations.First(); 231 elitesVc.Optimize = true; 232 elitesVc.RangeConstraint.LowerBound = new IntValue(0); 233 elitesVc.RangeConstraint.UpperBound = new IntValue(20); 234 elitesVc.RangeConstraint.StepSize = new IntValue(1); 235 } 236 168 237 private static void TestOptimization(GeneticAlgorithm metaLevelAlgorithm) { 169 metaLevelAlgorithm.Start(); 170 do { 171 Thread.Sleep(1000); 172 Console.Clear(); 173 try { 174 foreach (var result in metaLevelAlgorithm.Results) { 175 Console.WriteLine(result.ToString()); 176 if (result.Name == "Population") { 177 RunCollection rc = (RunCollection)result.Value; 178 var orderedRuns = rc.OrderBy(x => x.Results["BestQuality"]); 179 foreach (IRun run in orderedRuns) { 180 Console.WriteLine("Q: {0} PoSi: {1} MuRa: {2} MuOp: {3}", 181 ((DoubleValue)run.Results["BestQuality"]).Value.ToString("0.00").PadLeft(4, ' '), 182 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' '), 183 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadRight(3, ' '), 184 run.Parameters["Mutator"]); 185 } 186 } 238 ContentManager.Initialize(new PersistenceContentManager()); 239 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Results"); 240 if(!Directory.Exists(path)) 241 Directory.CreateDirectory(path); 242 string id = DateTime.Now.ToString("MM.dd.yy - HH;mm;ss,ffff"); 243 string resultPath = Path.Combine(path, string.Format("Test - {0} - Result.hl", id)); 244 string outputPath = Path.Combine(path, string.Format("Test - {0} - Console.txt", id)); 245 246 using (var sw = new StreamWriter(outputPath)) { 247 metaLevelAlgorithm.Start(); 248 int i = 0; 249 int currentGeneration = -1; 250 do { 251 Thread.Sleep(500); 252 try { 253 if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) { 254 StringBuilder sb = new StringBuilder(); 255 sb.AppendLine(DateTime.Now.ToLongTimeString()); 256 sb.AppendLine("================================="); 257 258 foreach (var result in metaLevelAlgorithm.Results) { 259 sb.AppendLine(result.ToString()); 260 if (result.Name == "Population") { 261 RunCollection rc = (RunCollection)result.Value; 262 var orderedRuns = rc.OrderBy(x => x.Results["BestQuality"]); 263 264 sb.AppendLine("Qality PoSi MutRa Eli GrSi MutOp"); 265 foreach (IRun run in orderedRuns) { 266 sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5}", 267 ((DoubleValue)run.Results["BestQuality"]).Value.ToString("#0.00").PadLeft(7, ' '), 268 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString().PadLeft(3, ' ').PadRight(3, ' '), 269 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00").PadLeft(5, ' '), 270 ((IntValue)run.Parameters["Elites"]).Value.ToString().PadLeft(3, ' '), 271 ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString().PadLeft(4, ' '), 272 run.Parameters["Mutator"])); 273 } 274 } 275 } // foreach 276 Console.Clear(); 277 Console.WriteLine(sb.ToString()); 278 sw.WriteLine(sb.ToString()); 279 sw.Flush(); 280 currentGeneration = ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value; 281 } // if 282 if (i % 30 == 0) GC.Collect(); 283 i++; 187 284 } 188 } 189 catch { } 190 } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped); 191 285 catch { } 286 } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped); 287 } 288 289 Console.WriteLine(); 290 Console.WriteLine("Storing..."); 291 292 ContentManager.Save(metaLevelAlgorithm, resultPath, true); 192 293 Console.WriteLine("Finished"); 193 294 }
Note: See TracChangeset
for help on using the changeset viewer.