Changeset 5281
- Timestamp:
- 01/11/11 17:55:30 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5277 r5281 31 31 //private static int baseAlgorithmMaxGenerations = 1000; 32 32 33 private static int metaAlgorithmPopulationSize = 16;33 private static int metaAlgorithmPopulationSize = 7; 34 34 private static int metaAlgorithmMaxGenerations = 20; 35 35 private static int metaProblemRepetitions = 3; 36 36 private static int baseAlgorithmMaxGenerations = 50; 37 private static double mutationProbability = 0.35; 37 38 38 39 static void Main(string[] args) { … … 468 469 metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last(); 469 470 470 metaLevelAlgorithm.MutationProbability.Value = 0.15;471 metaLevelAlgorithm.MutationProbability.Value = mutationProbability; 471 472 472 473 return metaLevelAlgorithm; … … 509 510 ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; 510 511 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 //});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 }); 519 520 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 520 521 Evaluator = new GriewankEvaluator(), … … 708 709 Thread.Sleep(1000); 709 710 if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) { 710 while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100);711 while (metaLevelAlgorithm.Results.Count < 6) Thread.Sleep(1000); 711 712 StringBuilder sb = new StringBuilder(); 712 713 sb.AppendLine(DateTime.Now.ToLongTimeString()); … … 714 715 715 716 sb.AppendLine(metaLevelAlgorithm.ExecutionState.ToString()); 716 var rsClone = (ResultCollection)metaLevelAlgorithm.Results.Clone(); 717 ResultCollection rsClone = null; 718 while (rsClone == null) { 719 try { 720 rsClone = (ResultCollection)metaLevelAlgorithm.Results.Clone(); 721 } 722 catch { } 723 } 717 724 foreach (var result in rsClone) { 718 725 sb.AppendLine(result.ToString()); … … 721 728 var orderedRuns = rc.OrderBy(x => x.Results["AverageQualityNormalized"]); 722 729 723 TableBuilder tb = new TableBuilder("QNorm", " PoSi", "MutRa", "Eli", "SelOp", "MutOp", "NrSelSubScopes");730 TableBuilder tb = new TableBuilder("QNorm", "Qualities", "PoSi", "MutRa", "Eli", "SelOp", "MutOp", "NrSelSubScopes"); 724 731 foreach (IRun run in orderedRuns) { 725 732 string selector; … … 732 739 tb.AppendRow( 733 740 ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.00"), 741 ((DoubleArray)run.Results["RunsAverageQualities"]).ToString(), 734 742 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString(), 735 743 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00"), -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r5212 r5281 14 14 /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 15 15 /// </summary> 16 [Item("BestParameterConfigurationAnalyzer", " TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]16 [Item("BestParameterConfigurationAnalyzer", "")] 17 17 [StorableClass] 18 18 public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer { … … 39 39 get { return (LookupParameter<RunCollection>)Parameters["Population"]; } 40 40 } 41 42 // stores the medians of the qualities of each problem43 41 public LookupParameter<DoubleArray> ProblemQualityMediansParameter { 44 42 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; } … … 50 48 public BestParameterConfigurationAnalyzer() 51 49 : base() { 52 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", " TODO The TSP solutions given in path representation from which the best solution should be analyzed."));53 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", " TODO The qualities of the TSP solutions which should be analyzed."));54 Parameters.Add(new LookupParameter<IRun>("BestSolution", " TODO The best TSP solution."));55 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", " TODO The result collection where the best TSP solution should be stored."));56 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", " TODO The quality of the best known solution of this TSP instance."));57 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", " TODO The best known solution of this TSP instance."));58 Parameters.Add(new LookupParameter<RunCollection>("Population", " TODO The best known solution of this TSP instance."));50 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "")); 51 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "")); 52 Parameters.Add(new LookupParameter<IRun>("BestSolution", "")); 53 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "")); 54 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "")); 55 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "")); 56 Parameters.Add(new LookupParameter<RunCollection>("Population", "")); 59 57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", "")); 60 58 Parameters.Add(new LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName)); … … 114 112 } 115 113 116 // medians for the problems117 DoubleArray medians = new DoubleArray(ProblemsParameter.ActualValue.Count);118 for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) {119 double[] values = new double[rc.Count];120 for (int ri = 0; ri < rc.Count; ri++) {121 values[ri] = ((DoubleArray)rc.ElementAt(ri).Results["RunsAverageQualities"])[pi];122 }123 medians[pi] = values.Median();124 }125 ProblemQualityMediansParameter.ActualValue = medians;126 127 if (results.ContainsKey("ProblemsAverageQualityMedians")) {128 results["ProblemsAverageQualityMedians"].Value = medians;129 } else {130 results.Add(new Result("ProblemsAverageQualityMedians", medians));131 }132 133 114 return base.Apply(); 134 115 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5231 r5281 70 70 EngineAlgorithm algorithm = (EngineAlgorithm)AlgorithmParameter.ActualValue.Clone(); 71 71 IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue; 72 ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue; 72 73 73 74 double[] medians; 74 75 if (ProblemQualityMediansParameter.ActualValue == null) { 75 // this is generation zero. no reference qualities for scaling have been calculated yet. calculate a random individuum to get reference values76 medians = new double[problems.Count]; // todo76 // this is generation zero. no reference qualities for normalization have been calculated yet. 77 medians = new double[problems.Count]; 77 78 for (int i = 0; i < medians.Length; i++) { 78 79 medians[i] = 1; … … 83 84 84 85 // set parameters 85 ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);86 parameterConfiguration.Parameterize(algorithm); 86 87 algorithm.StoreAlgorithmInEachRun = false; 87 88 … … 121 122 algorithm.Prepare(); 122 123 123 ParameterConfigurationParameter.ActualValue.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds)))));124 ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone();125 ParameterConfigurationParameter.ActualValue.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray()); // todo: respect Maximization:true/false126 ParameterConfigurationParameter.ActualValue.AverageQualities = new DoubleArray(qualities.Select(q => q.Average()).ToArray());127 ParameterConfigurationParameter.ActualValue.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray()); // todo: respect Maximization:true/false128 ParameterConfigurationParameter.ActualValue.QualityVariances = new DoubleArray(qualities.Select(q => q.Variance()).ToArray());129 ParameterConfigurationParameter.ActualValue.QualityStandardDeviations = new DoubleArray(qualities.Select(q => q.StandardDeviation()).ToArray());130 ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone();124 parameterConfiguration.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds))))); 125 parameterConfiguration.Repetitions = (IntValue)Repetitions.Clone(); 126 parameterConfiguration.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray()); // todo: respect Maximization:true/false 127 parameterConfiguration.AverageQualities = new DoubleArray(qualities.Select(q => q.Average()).ToArray()); 128 parameterConfiguration.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray()); // todo: respect Maximization:true/false 129 parameterConfiguration.QualityVariances = new DoubleArray(qualities.Select(q => q.Variance()).ToArray()); 130 parameterConfiguration.QualityStandardDeviations = new DoubleArray(qualities.Select(q => q.StandardDeviation()).ToArray()); 131 parameterConfiguration.Runs = (RunCollection)algorithm.Runs.Clone(); 131 132 132 // normalize qualities 133 double[] qualitiesNormalized = new double[problems.Count]; 134 for (int i = 0; i < problems.Count; i++) { 135 qualitiesNormalized[i] = qualities[i].Average() / medians[i]; 136 } 137 ParameterConfigurationParameter.ActualValue.QualitiesNormalized = new DoubleArray(qualitiesNormalized); 138 ParameterConfigurationParameter.ActualValue.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average()); 139 140 this.QualityParameter.ActualValue = ParameterConfigurationParameter.ActualValue.AverageQualityNormalized; 133 this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, medians)); 141 134 142 135 return base.Apply(); 136 } 137 138 public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] medians) { 139 double[] qualitiesNormalized = new double[medians.Length]; 140 for (int i = 0; i < medians.Length; i++) { 141 qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / medians[i]; 142 } 143 parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized); 144 parameterConfigurationTree.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average()); 145 return parameterConfigurationTree.AverageQualityNormalized.Value; 143 146 } 144 147 … … 153 156 } 154 157 } 155 156 /// <summary>157 /// Can execute an algorithm synchronously158 /// </summary>159 public class AlgorithmExecutor {160 private EngineAlgorithm algorithm;161 private AutoResetEvent waitHandle = new AutoResetEvent(false);162 163 public AlgorithmExecutor(EngineAlgorithm algorithm) {164 this.algorithm = algorithm;165 }166 167 public void StartSync() {168 algorithm.Stopped += new EventHandler(algorithm_Stopped);169 algorithm.Paused += new EventHandler(algorithm_Paused);170 algorithm.Start();171 waitHandle.WaitOne();172 waitHandle.Dispose();173 algorithm.Stopped -= new EventHandler(algorithm_Stopped);174 algorithm.Paused -= new EventHandler(algorithm_Paused);175 }176 177 void algorithm_Paused(object sender, EventArgs e) {178 waitHandle.Set();179 }180 181 void algorithm_Stopped(object sender, EventArgs e) {182 waitHandle.Set();183 }184 }185 158 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5277 r5281 132 132 <None Include="Properties\AssemblyInfo.cs.frame" /> 133 133 <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" /> 134 <Compile Include="Analyzers\MedianQualityAnalyzer.cs" /> 134 135 <Compile Include="ConstrainedItemList.cs" /> 135 136 <Compile Include="Encoding\NullValue.cs" /> … … 147 148 <Compile Include="Encoding\ValueConfigurations\ValueConfiguration.cs" /> 148 149 <Compile Include="Encoding\ValueConfigurations\CheckedValueConfigurationCollection.cs" /> 150 <Compile Include="Evaluators\AlgorithmExecutor.cs" /> 149 151 <Compile Include="Interfaces\IParameterConfigurationCrossover.cs" /> 150 152 <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5277 r5281 98 98 get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); } 99 99 } 100 private MedianQualityAnalyzer MedianQualityAnalyzer { 101 get { return Operators.OfType<MedianQualityAnalyzer>().FirstOrDefault(); } 102 } 100 103 #endregion 101 104 … … 158 161 Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>()); 159 162 Operators.Add(new BestParameterConfigurationAnalyzer()); 163 Operators.Add(new MedianQualityAnalyzer()); 160 164 } 161 165 private void ParameterizeSolutionCreator() { … … 167 171 if (BestParameterConfigurationAnalyzer != null) { 168 172 BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 173 } 174 if (MedianQualityAnalyzer != null) { 175 MedianQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 169 176 } 170 177 }
Note: See TracChangeset
for help on using the changeset viewer.