Changeset 5009
- Timestamp:
- 12/01/10 20:37:36 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 4 added
- 1 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r4997 r5009 5 5 using HeuristicLab.Core; 6 6 using HeuristicLab.PluginInfrastructure; 7 using HeuristicLab.Parameters; 7 8 using HeuristicLab.Problems.MetaOptimization; 8 9 using HeuristicLab.Data; 9 10 using System; 11 using System.Threading; 12 using HeuristicLab.Random; 13 using HeuristicLab.Optimization; 10 14 11 15 namespace HeuristicLab.MetaOptimization.Test { 12 16 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 13 23 static void Main(string[] args) { 14 24 //TestIntSampling(); … … 17 27 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); 18 28 MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem(); 29 GeneticAlgorithm metaLevelAlgorithm = GetMetaAlgorithm(metaOptimizationProblem); 30 31 IValueConfiguration algorithmVc = SetupAlgorithm(baseLevelAlgorithm, metaOptimizationProblem); 32 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(); 39 TestOptimization(metaLevelAlgorithm); 40 41 //TestMemoryLeak(metaLevelAlgorithm); 42 43 Console.ReadLine(); 44 } 45 46 private static void TestMemoryLeak(GeneticAlgorithm metaLevelAlgorithm) { 47 IValueConfiguration algorithmVc = ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).AlgorithmParameterConfiguration; 48 49 Console.WriteLine("Starting Memory Test..."); 50 Console.ReadLine(); 51 52 for (int i = 0; i < 1000; i++) { 53 var clone = algorithmVc.Clone(); 54 } 55 56 Console.WriteLine("Finished. Now GC..."); 57 Console.ReadLine(); 58 59 GC.Collect(); 60 61 Console.WriteLine("Finished!"); 62 Console.ReadLine(); 63 } 64 65 private static GeneticAlgorithm GetMetaAlgorithm(MetaOptimizationProblem metaOptimizationProblem) { 66 GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm(); 67 metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize; 68 metaLevelAlgorithm.MaximumGenerations.Value = metaAlgorithmMaxGenerations; 69 70 metaLevelAlgorithm.Problem = metaOptimizationProblem; 71 metaLevelAlgorithm.Engine = new SequentialEngine.SequentialEngine(); 72 return metaLevelAlgorithm; 73 } 74 75 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; 78 baseLevelAlgorithm.MaximumGenerations.Value = baseAlgorithmMaxGenerations; 79 19 80 metaOptimizationProblem.Algorithm = baseLevelAlgorithm; 20 81 IValueConfiguration algorithmVc = metaOptimizationProblem.AlgorithmParameterConfiguration; 21 22 //ConfigurePopulationSize(algorithmVc); 82 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem()); 83 84 ConfigurePopulationSize(algorithmVc); 23 85 ConfigureMutationRate(algorithmVc); 24 25 GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm(); 26 metaLevelAlgorithm.PopulationSize.Value = 10; 27 86 ConfigureMutationOperator(algorithmVc); 87 return algorithmVc; 88 } 89 90 private static void TestConfiguration(IValueConfiguration algorithmVc, GeneticAlgorithm baseLevelAlgorithm) { 91 IRandom rand = new MersenneTwister(); 28 92 // set random values 29 93 for (int i = 0; i < 10; i++) { 30 94 IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone(); 31 clonedVc.Randomize( );32 clonedVc.Parameterize( );95 clonedVc.Randomize(rand); 96 clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value); 33 97 GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value; 34 //Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));98 Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize)); 35 99 Console.WriteLine(string.Format("MutRate: original: {0}, randomized: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability)); 100 Console.WriteLine(string.Format("MutOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator)); 36 101 } 37 102 … … 39 104 for (int i = 0; i < 10; i++) { 40 105 IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone(); 41 clonedVc.Mutate( );42 clonedVc.Parameterize( );106 clonedVc.Mutate(rand); 107 clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value); 43 108 GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value; 44 //Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));109 Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize)); 45 110 Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability)); 111 Console.WriteLine(string.Format("MutOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator)); 46 112 } 47 113 … … 49 115 for (int i = 0; i < 10; i++) { 50 116 IValueConfiguration clonedVc1 = (IValueConfiguration)algorithmVc.Clone(); 51 clonedVc1.Randomize( );52 clonedVc1.Parameterize( );117 clonedVc1.Randomize(rand); 118 clonedVc1.Parameterize(baseLevelAlgorithm); 53 119 54 120 IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone(); … … 58 124 var popSizeBefore = first.PopulationSize.Value; 59 125 var mutRateBefore = first.MutationProbability.Value; 60 clonedVc1.Cross(clonedVc2); 61 clonedVc1.Parameterize(); 62 63 //Console.WriteLine(string.Format("PopSize: first: {0}, second: {1}, crossed: {2}", popSizeBefore, second.PopulationSize, first.PopulationSize)); 126 var mutOpBefore = first.Mutator; 127 128 clonedVc1.Cross(clonedVc2, rand); 129 clonedVc1.Parameterize((GeneticAlgorithm)clonedVc2.ActualValue.Value); 130 131 Console.WriteLine(string.Format("PopSize: first: {0}, second: {1}, crossed: {2}", popSizeBefore, second.PopulationSize, first.PopulationSize)); 64 132 Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutRateBefore, second.MutationProbability, first.MutationProbability)); 65 } 66 67 Debugger.Break(); 133 Console.WriteLine(string.Format("MutRate: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator)); 134 } 135 } 136 137 private static void ConfigureMutationOperator(IValueConfiguration algorithmVc) { 138 var mutationOperator = algorithmVc.ParameterConfigurations.Where(x => x.Name == "Mutator").SingleOrDefault(); 139 mutationOperator.Optimize = true; 140 141 // uncheck multiMutator to avoid Michalewicz issue 142 var multiMutator = mutationOperator.ValueConfigurations.Where(x => x.ActualValue.Value.ItemName.StartsWith("Multi")).SingleOrDefault(); 143 if (multiMutator != null) { 144 mutationOperator.ValueConfigurations.SetItemCheckedState(multiMutator, false); 145 } 68 146 } 69 147 … … 86 164 mutationRateVc.RangeConstraint.UpperBound = new PercentValue(1.0); 87 165 mutationRateVc.RangeConstraint.StepSize = new PercentValue(0.01); 166 } 167 168 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 } 187 } 188 } 189 catch { } 190 } while (metaLevelAlgorithm.ExecutionState != ExecutionState.Stopped); 191 192 Console.WriteLine("Finished"); 88 193 } 89 194 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/RootValueConfigurationView.cs
r4982 r5009 16 16 /// </summary> 17 17 [View("ParameterConfiguration View")] 18 [Content(typeof( RootValueConfiguration), true)]18 [Content(typeof(ParameterConfigurationTree), true)] 19 19 public partial class RootValueConfigurationView : ItemView { 20 20 /// <summary> … … 23 23 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>. 24 24 /// No own data storage present.</remarks> 25 public new RootValueConfigurationContent {26 get { return ( RootValueConfiguration)base.Content; }25 public new ParameterConfigurationTree Content { 26 get { return (ParameterConfigurationTree)base.Content; } 27 27 set { base.Content = value; } 28 28 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r4839 r5009 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic; 10 using System; 9 11 10 12 namespace HeuristicLab.Problems.MetaOptimization { … … 12 14 /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 13 15 /// </summary> 14 [Item("Best QualityAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]16 [Item("BestParameterConfigurationAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")] 15 17 [StorableClass] 16 18 public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer { 17 19 // Wagner: Spezielle View für die Lösungen (ParameterConfigurations): So wie bei Runs: die zu Optimierenden Parameter(-werte) der besten solution anzeigen 18 20 19 public ScopeTreeLookupParameter< IParameterConfiguration> ParameterVectorParameter {20 get { return (ScopeTreeLookupParameter< IParameterConfiguration>)Parameters["ParameterConfiguration"]; }21 public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 22 get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 21 23 } 22 24 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 23 25 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 24 26 } 25 public LookupParameter<I ParameterConfiguration> BestSolutionParameter {26 get { return (LookupParameter<I ParameterConfiguration>)Parameters["BestSolution"]; }27 public LookupParameter<IRun> BestSolutionParameter { 28 get { return (LookupParameter<IRun>)Parameters["BestSolution"]; } 27 29 } 28 30 public ValueLookupParameter<ResultCollection> ResultsParameter { … … 32 34 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 33 35 } 34 public LookupParameter<IParameterConfiguration> BestKnownSolutionParameter { 35 get { return (LookupParameter<IParameterConfiguration>)Parameters["BestKnownSolution"]; } 36 public LookupParameter<IRun> BestKnownSolutionParameter { 37 get { return (LookupParameter<IRun>)Parameters["BestKnownSolution"]; } 38 } 39 public LookupParameter<RunCollection> PopulationParameter { 40 get { return (LookupParameter<RunCollection>)Parameters["Population"]; } 36 41 } 37 42 38 43 public BestParameterConfigurationAnalyzer() : base() { 39 Parameters.Add(new ScopeTreeLookupParameter< IParameterConfiguration>("ParameterConfiguration", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));44 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed.")); 40 45 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed.")); 41 Parameters.Add(new LookupParameter<I ParameterConfiguration>("BestSolution", "TODO The best TSP solution."));46 Parameters.Add(new LookupParameter<IRun>("BestSolution", "TODO The best TSP solution.")); 42 47 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored.")); 43 48 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance.")); 44 Parameters.Add(new LookupParameter<IParameterConfiguration>("BestKnownSolution", "TODO The best known solution of this TSP instance.")); 49 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance.")); 50 Parameters.Add(new LookupParameter<RunCollection>("Population", "TODO The best known solution of this TSP instance.")); 45 51 } 46 52 … … 56 62 ResultCollection results = ResultsParameter.ActualValue; 57 63 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 58 ItemArray< IParameterConfiguration> parameterVectors = ParameterVectorParameter.ActualValue;64 ItemArray<ParameterConfigurationTree> parameterConfigurations = ParameterConfigurationParameter.ActualValue; 59 65 60 66 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 61 67 68 EngineAlgorithm bestAlg = ((EngineAlgorithm)((ParameterConfigurationTree)parameterConfigurations[i]).ActualValue.Value); 69 Run bestRun = new Run(bestAlg); 70 62 71 if (bestKnownQuality == null || qualities[i].Value < bestKnownQuality.Value) { 63 72 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 64 BestKnownSolutionParameter.ActualValue = (IParameterConfiguration)parameterVectors[i].Clone();73 BestKnownSolutionParameter.ActualValue = bestRun; 65 74 } 66 75 67 // todo: more 76 IRun best = BestSolutionParameter.ActualValue; 77 if (best == null) { 78 BestSolutionParameter.ActualValue = bestRun; 79 results.Add(new Result("Best Parameter Settings", bestRun)); 80 } else { 81 BestSolutionParameter.ActualValue = bestRun; 82 results["Best Parameter Settings"].Value = bestRun; 83 } 84 85 RunCollection rc = new RunCollection(); 86 87 foreach (ParameterConfigurationTree pc in parameterConfigurations.OrderBy(x => x.Quality.Value*-1)) { 88 IAlgorithm alg = (IAlgorithm)pc.ActualValue.Value; 89 alg.StoreAlgorithmInEachRun = false; 90 IRun run = new Run(alg); 91 rc.Add(run); 92 } 93 if (PopulationParameter.ActualValue == null) { 94 PopulationParameter.ActualValue = rc; 95 results.Add(new Result("Population", rc)); 96 } else { 97 PopulationParameter.ActualValue = rc; 98 results["Population"].Value = rc; 99 } 100 GC.Collect(); 68 101 69 102 return base.Apply(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Creators/RandomParameterConfigurationCreator.cs
r4997 r5009 20 20 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 21 21 } 22 public ILookupParameter< IValueConfiguration> ValueConfigurationParameter {23 get { return (ILookupParameter< IValueConfiguration>)Parameters["ValueConfiguration"]; }22 public ILookupParameter<ParameterConfigurationTree> InitialParameterConfigurationParameter { 23 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["InitialParameterConfigurationTree"]; } 24 24 } 25 25 26 public ILookupParameter< IValueConfiguration> NewValueConfigurationParameter {27 get { return (ILookupParameter< IValueConfiguration>)Parameters["NewValueConfiguration"]; }26 public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 27 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 28 28 } 29 29 … … 33 33 public RandomParameterConfigurationCreator() : base() { 34 34 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation.")); 35 Parameters.Add(new LookupParameter<IValueConfiguration>("ValueConfiguration", "The new random parameter set.")); 35 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("InitialParameterConfigurationTree", "The parameter configuration tree on which the new solution will be based on.")); 36 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "The new random parameter set.")); 36 37 } 37 38 public override IDeepCloneable Clone(Cloner cloner) { … … 40 41 41 42 public override IOperation Apply() { 42 NewValueConfigurationParameter.ActualValue = (IValueConfiguration)ValueConfigurationParameter.ActualValue.Clone(); 43 NewValueConfigurationParameter.ActualValue.Randomize(); 44 NewValueConfigurationParameter.ActualValue.Parameterize(); 43 ParameterConfigurationParameter.ActualValue = (ParameterConfigurationTree)InitialParameterConfigurationParameter.ActualValue.Clone(); 44 ParameterConfigurationParameter.ActualValue.Randomize(RandomParameter.ActualValue); 45 45 return base.Apply(); 46 46 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/Crossovers/ParameterConfigurationCrossover.cs
r4997 r5009 13 13 /// 14 14 /// </summary> 15 [Item("Parameter VectorCrossover", "TODO")]15 [Item("ParameterConfigurationCrossover", "TODO")] 16 16 [StorableClass] 17 17 public class ParameterConfigurationCrossover : SingleSuccessorOperator, IParameterConfigurationOperator, ICrossover { … … 23 23 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 24 24 } 25 public ILookupParameter<ItemArray<I ParameterConfiguration>> ParentsParameter {26 get { return (ScopeTreeLookupParameter<I ParameterConfiguration>)Parameters["Parents"]; }25 public ILookupParameter<ItemArray<IValueConfiguration>> ParentsParameter { 26 get { return (ScopeTreeLookupParameter<IValueConfiguration>)Parameters["Parents"]; } 27 27 } 28 public ILookupParameter<I ParameterConfiguration> ChildParameter {29 get { return (ILookupParameter<I ParameterConfiguration>)Parameters["Child"]; }28 public ILookupParameter<IValueConfiguration> ChildParameter { 29 get { return (ILookupParameter<IValueConfiguration>)Parameters["Child"]; } 30 30 } 31 31 … … 47 47 : base() { 48 48 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 49 Parameters.Add(new ScopeTreeLookupParameter<I ParameterConfiguration>("Parents", "The parent vectors which should be crossed."));50 ParentsParameter.ActualName = "ParameterConfiguration ";51 Parameters.Add(new LookupParameter<I ParameterConfiguration>("Child", "The child vector resulting from the crossover."));52 ChildParameter.ActualName = "ParameterConfiguration ";49 Parameters.Add(new ScopeTreeLookupParameter<IValueConfiguration>("Parents", "The parent vectors which should be crossed.")); 50 ParentsParameter.ActualName = "ParameterConfigurationTree"; 51 Parameters.Add(new LookupParameter<IValueConfiguration>("Child", "The child vector resulting from the crossover.")); 52 ChildParameter.ActualName = "ParameterConfigurationTree"; 53 53 } 54 54 public override IDeepCloneable Clone(Cloner cloner) { … … 57 57 58 58 public override IOperation Apply() { 59 IValueConfiguration child1 = (IValueConfiguration)ParentsParameter.ActualValue[0].Clone(); 60 IValueConfiguration child2 = (IValueConfiguration)ParentsParameter.ActualValue[1]; 59 61 60 IParameterConfiguration child = (IParameterConfiguration)ParentsParameter.ActualValue[0].Clone(); 61 // todo 62 //for (int i = 0; i < child.Parameters.Count; i++) { 63 // if (child.Parameters[i].Parameter.DataType == typeof(IntValue)) { 64 // child.Parameters[i].Parameter.ActualValue = CrossInteger(ParentsParameter.ActualValue[0].Parameters[i], ParentsParameter.ActualValue[1].Parameters[i]); 65 // } 66 //} 67 68 this.ChildParameter.ActualValue = child; 62 child1.Cross(child2, RandomParameter.ActualValue); 63 this.ChildParameter.ActualValue = child1; 69 64 return base.Apply(); 70 65 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs
r4997 r5009 6 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 7 using HeuristicLab.PluginInfrastructure; 8 using HeuristicLab.Parameters; 9 using HeuristicLab.Data; 10 using System.Collections; 8 11 9 12 namespace HeuristicLab.Problems.MetaOptimization { … … 47 50 } 48 51 52 [Storable] 49 53 protected Type parameterDataType; 50 54 public Type ParameterDataType { … … 52 56 } 53 57 54 protected IEnumerable<IItem> validValues; 55 public IEnumerable<IItem> ValidValues { 58 [Storable] 59 protected IItemSet<IItem> validValues; 60 public IItemSet<IItem> ValidValues { 56 61 get { return validValues; } 57 62 protected set { … … 62 67 } 63 68 69 [Storable] 64 70 protected Type valueDataType; 65 71 public Type ValueDataType { … … 68 74 } 69 75 76 [Storable] 70 77 protected ICheckedValueConfigurationCollection valueConfigurations; 71 78 public ICheckedValueConfigurationCollection ValueConfigurations { … … 80 87 } 81 88 89 [Storable] 82 90 protected int actualValueConfigurationIndex = 0; 83 91 92 [Storable] 84 93 protected ConstrainedValue actualValue; 85 94 public ConstrainedValue ActualValue { … … 89 98 90 99 // store parameter reference only for name/description/image/... 91 private IValueParameter parameter; 100 //[Storable] 101 //private IValueParameter parameter; 92 102 93 103 #region Constructors and Cloning … … 95 105 this.ParameterName = parameterName; 96 106 this.parameterDataType = valueParameter.GetType(); 97 this.parameter = valueParameter;107 //this.parameter = valueParameter; 98 108 this.valueDataType = valueParameter.DataType; 99 this.validValues = GetValidValues( );109 this.validValues = GetValidValues(valueParameter); 100 110 this.ValueConfigurations = new CheckedValueConfigurationCollection(this.valueDataType); 101 111 this.ActualValue = new ConstrainedValue(valueParameter.Value, valueParameter.DataType); … … 111 121 this.parameterName = original.ParameterName; 112 122 this.parameterDataType = original.parameterDataType; 113 this.parameter = cloner.Clone(original.parameter);123 //this.parameter = cloner.Clone(original.parameter); 114 124 this.valueDataType = original.ValueDataType; 115 this.validValues = original.ValidValues.Select(x => cloner.Clone(x));116 this. ValueConfigurations = cloner.Clone(original.ValueConfigurations);125 this.validValues = cloner.Clone(original.ValidValues); 126 this.valueConfigurations = cloner.Clone(original.ValueConfigurations); 117 127 this.ActualValue = cloner.Clone(original.ActualValue); 118 128 this.optimize = original.optimize; 129 if (this.valueConfigurations != null) RegisterValueConfigurationEvents(); 119 130 } 120 131 public override IDeepCloneable Clone(Cloner cloner) { 121 132 return new ParameterConfiguration(this, cloner); 133 } 134 [StorableHook(HookType.AfterDeserialization)] 135 private void AfterDeserialization() { 136 if (this.valueConfigurations != null) RegisterValueConfigurationEvents(); 122 137 } 123 138 #endregion … … 147 162 } 148 163 149 private IEnumerable<IItem> GetValidValues() { 150 return ApplicationManager.Manager.GetInstances(valueDataType).Select(x => (IItem)x).OrderBy(x => x.ItemName).ToArray(); 164 private IItemSet<IItem> GetValidValues(IValueParameter parameter) { 165 if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) { 166 var x = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { }); 167 return new ItemSet<IItem>(x.Cast<IItem>()); 168 } else { 169 return new ItemSet<IItem>(ApplicationManager.Manager.GetInstances(valueDataType).Select(x => (IItem)x).OrderBy(x => x.ItemName)); 170 } 171 } 172 173 private static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) { 174 while (toCheck != typeof(object)) { 175 var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; 176 if (generic == cur) { 177 return true; 178 } 179 toCheck = toCheck.BaseType; 180 } 181 return false; 151 182 } 152 183 … … 167 198 } 168 199 public virtual string Description { 169 get { return parameter.Description; }200 get { return base.ItemDescription; } 170 201 set { throw new NotSupportedException(); } 171 202 } … … 177 208 } 178 209 public override string ItemDescription { 179 get { return parameter != null ? parameter.Description : base.ItemDescription; } 210 //get { return parameter != null ? parameter.Description : base.ItemDescription; } 211 get { return base.ItemDescription; } 180 212 } 181 213 public override System.Drawing.Image ItemImage { 182 get { return parameter != null ? parameter.ItemImage : base.ItemImage; } 214 //get { return parameter != null ? parameter.ItemImage : base.ItemImage; } 215 get { return base.ItemImage; } 183 216 } 184 217 public override string ItemName { 185 get { return parameter != null ?parameter.ItemName : base.ItemName; } 218 //get { return parameter != null ?parameter.ItemName : base.ItemName; } 219 get { return base.ItemName; } 186 220 } 187 221 #endregion … … 235 269 } 236 270 237 public void Parameterize() { 238 this.parameter.ActualValue = this.ActualValue.Value; 239 } 240 241 public void Randomize() { 242 if (Optimize) { 243 Random rand = new Random(); // todo: use global random 244 actualValueConfigurationIndex = rand.Next(ValueConfigurations.CheckedItems.Count()); 245 this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize(); 271 public void Parameterize(IValueParameter parameter) { 272 parameter.ActualValue = this.ActualValue.Value; 273 } 274 275 public void Randomize(IRandom random) { 276 if (Optimize) { 277 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 278 this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Randomize(random); 246 279 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 247 280 } 248 281 } 249 282 250 public void Mutate( ) {283 public void Mutate(IRandom random) { 251 284 if (Optimize) { 252 285 foreach (IValueConfiguration vc in this.ValueConfigurations.CheckedItems) { 253 vc.Mutate(); 254 } 286 vc.Mutate(random); 287 } 288 actualValueConfigurationIndex = random.Next(ValueConfigurations.CheckedItems.Count()); 255 289 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; 256 } 257 } 258 259 public void Cross(IOptimizable other) { 290 this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).Mutate(random); 291 } 292 } 293 294 public void Cross(IOptimizable other, IRandom random) { 260 295 if (Optimize) { 261 296 IParameterConfiguration otherPc = (IParameterConfiguration)other; 262 297 for (int i = 0; i < this.ValueConfigurations.Count; i++) { 263 this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i) );298 this.ValueConfigurations.ElementAt(i).Cross(otherPc.ValueConfigurations.ElementAt(i), random); 264 299 } 265 300 this.ActualValue = this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ActualValue; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/ConstrainedValue.cs
r4997 r5009 38 38 this.value.ToStringChanged -= new EventHandler(value_ToStringChanged); 39 39 } 40 40 41 #region constructors and cloning 41 42 public ConstrainedValue() { } 43 [StorableConstructor] 44 protected ConstrainedValue(bool deserializing) : base(deserializing) { } 42 45 public ConstrainedValue(IItem value, Type valueDataType) { 43 46 this.Value = value; … … 51 54 return new ConstrainedValue(this, cloner); 52 55 } 56 [StorableHook(HookType.AfterDeserialization)] 57 private void AfterDeserialization() { 58 if (this.value != null) RegisterEvents(); 59 } 60 #endregion 53 61 54 62 void value_ToStringChanged(object sender, EventArgs e) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/DoubleValueRange.cs
r4997 r5009 5 5 using HeuristicLab.Data; 6 6 using HeuristicLab.Common; 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Core; 7 9 8 10 namespace HeuristicLab.Problems.MetaOptimization { 11 [StorableClass] 9 12 public class DoubleValueRange : Range<DoubleValue> { 10 13 11 14 public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { } 12 15 public DoubleValueRange() { } 16 [StorableConstructor] 17 protected DoubleValueRange(bool deserializing) : base(deserializing) { } 13 18 protected DoubleValueRange(DoubleValueRange original, Cloner cloner) : base(original, cloner) { } 14 19 public override IDeepCloneable Clone(Cloner cloner) { … … 16 21 } 17 22 18 public override DoubleValue GetRandomValue() { 19 Random rand = new Random(); // todo: use common random 23 public override DoubleValue GetRandomValue(IRandom random) { 20 24 double val; 21 25 do { 22 val = Math.Round((rand .NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;26 val = Math.Round((random.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value; 23 27 } while (val < LowerBound.Value || val > UpperBound.Value); 24 28 return new DoubleValue(val); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/IntValueRange.cs
r4997 r5009 5 5 using HeuristicLab.Data; 6 6 using HeuristicLab.Common; 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Core; 7 9 8 10 namespace HeuristicLab.Problems.MetaOptimization { 11 [StorableClass] 9 12 public class IntValueRange : Range<IntValue> { 10 13 11 14 public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { } 12 15 public IntValueRange() { } 16 [StorableConstructor] 17 protected IntValueRange(bool deserializing) : base(deserializing) { } 13 18 protected IntValueRange(IntValueRange original, Cloner cloner) : base(original, cloner) { } 14 19 public override IDeepCloneable Clone(Cloner cloner) { … … 16 21 } 17 22 18 public override IntValue GetRandomValue() { 19 Random rand = new Random(); // todo: use common random 23 public override IntValue GetRandomValue(IRandom random) { 20 24 int val; 21 25 do { 22 val = rand .Next(LowerBound.Value / StepSize.Value, UpperBound.Value / StepSize.Value + 1) * StepSize.Value;26 val = random.Next(LowerBound.Value / StepSize.Value, UpperBound.Value / StepSize.Value + 1) * StepSize.Value; 23 27 } while (val < LowerBound.Value || val > UpperBound.Value); 24 28 return new IntValue(val); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/PercentValueRange.cs
r4997 r5009 5 5 using HeuristicLab.Data; 6 6 using HeuristicLab.Common; 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Core; 7 9 8 10 namespace HeuristicLab.Problems.MetaOptimization { 11 [StorableClass] 9 12 public class PercentValueRange : Range<PercentValue> { 10 13 11 14 public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { } 12 15 public PercentValueRange() { } 16 [StorableConstructor] 17 protected PercentValueRange(bool deserializing) : base(deserializing) { } 13 18 protected PercentValueRange(PercentValueRange original, Cloner cloner) : base(original, cloner) { } 14 19 public override IDeepCloneable Clone(Cloner cloner) { … … 16 21 } 17 22 18 public override PercentValue GetRandomValue() { 19 Random rand = new Random(); // todo: use common random 23 public override PercentValue GetRandomValue(IRandom random) { 20 24 double val; 21 25 do { 22 val = Math.Round((rand .NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value;26 val = Math.Round((random.NextDouble() * (UpperBound.Value - LowerBound.Value) + LowerBound.Value) / StepSize.Value, 0) * StepSize.Value; 23 27 } while (val < LowerBound.Value || val > UpperBound.Value); 24 28 return new PercentValue(val); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/RangeConstraints/Range.cs
r4997 r5009 92 92 this.StepSize = cloner.Clone(original.StepSize); 93 93 } 94 #endregion95 94 96 95 [StorableHook(HookType.AfterDeserialization)] … … 106 105 } 107 106 } 107 #endregion 108 108 109 109 #region Events … … 166 166 } 167 167 public bool Validate(string value, out string errorMessage) { 168 // TODO: check that upper is larger than lower 168 // TODO: check that upper is larger than lower and that stepsize < upper-lower 169 169 T lower = (T)lowerBound.Clone(); 170 170 T upper = (T)upperBound.Clone(); … … 191 191 #endregion 192 192 193 public abstract T GetRandomValue(IRandom random); 193 194 194 195 public abstract T GetRandomValue(); 196 197 #region IRange Members 198 199 200 IItem IRange.GetRandomValue() { 201 return GetRandomValue(); 195 IItem IRange.GetRandomValue(IRandom random) { 196 return GetRandomValue(random); 202 197 } 203 204 #endregion205 198 } 206 199 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/CheckedValueConfigurationCollection.cs
r4982 r5009 43 43 return new CheckedValueConfigurationCollection(this, cloner); 44 44 } 45 [StorableHook(HookType.AfterDeserialization)] 46 private void AfterDeserialization() { 47 RegisterEvents(); 48 } 45 49 46 50 private void RegisterEvents() { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs
r4997 r5009 9 9 namespace HeuristicLab.Problems.MetaOptimization { 10 10 // TODO: ItemName/Descr, storability 11 [StorableClass] 11 12 public class ValueConfiguration : Item, IValueConfiguration { 13 [Storable] 12 14 protected bool isOptimizable; 13 15 public bool IsOptimizable { … … 21 23 } 22 24 25 [Storable] 23 26 protected bool optimize; 24 27 public bool Optimize { … … 39 42 } 40 43 44 [Storable] 41 45 protected IItemCollection<IParameterConfiguration> parameterConfigurations = new ItemCollection<IParameterConfiguration>(); 42 46 public IItemCollection<IParameterConfiguration> ParameterConfigurations { … … 45 49 } 46 50 51 [Storable] 47 52 protected ConstrainedValue actualValue; 48 53 public ConstrainedValue ActualValue { … … 59 64 } 60 65 66 [Storable] 61 67 protected IRange rangeConstraint; 62 68 public IRange RangeConstraint { … … 97 103 return new ValueConfiguration(this, cloner); 98 104 } 105 [StorableHook(HookType.AfterDeserialization)] 106 private void AfterDeserialization() { 107 RegisterEvents(); 108 } 99 109 #endregion 100 110 … … 181 191 } 182 192 } 183 184 public void Parameterize( ) {193 194 public void Parameterize(IParameterizedItem item) { 185 195 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 186 pc.Parameterize( );187 } 188 } 189 190 public void Randomize( ) {196 pc.Parameterize((IValueParameter)item.Parameters[pc.ParameterName]); 197 } 198 } 199 200 public void Randomize(IRandom random) { 191 201 if (Optimize) { 192 202 if (rangeConstraint != null) { 193 this.actualValue.Value = rangeConstraint.GetRandomValue( );203 this.actualValue.Value = rangeConstraint.GetRandomValue(random); 194 204 } else { 195 205 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 196 pc.Randomize( );197 } 198 } 199 } 200 } 201 202 public void Mutate( ) {206 pc.Randomize(random); 207 } 208 } 209 } 210 } 211 212 public void Mutate(IRandom random) { 203 213 if (Optimize) { 204 214 if (rangeConstraint != null) { 205 Random rand = new Random(); // todo: use common random 206 // mutate every other value. todo: use some kind of mutation operator which is exchangable 207 if(rand.NextDouble() > 0.5) 208 this.actualValue.Value = rangeConstraint.GetRandomValue(); 215 if (random.NextDouble() > 0.5) 216 this.actualValue.Value = rangeConstraint.GetRandomValue(random); 209 217 } else { 210 218 foreach (IParameterConfiguration pc in this.ParameterConfigurations) { 211 pc.Mutate( );212 } 213 } 214 } 215 } 216 217 public void Cross(IOptimizable other ) {219 pc.Mutate(random); 220 } 221 } 222 } 223 } 224 225 public void Cross(IOptimizable other, IRandom random) { 218 226 if (Optimize) { 219 227 IValueConfiguration otherVc = (IValueConfiguration)other; … … 233 241 this.actualValue.Value = new BoolValue(false); 234 242 } else { 235 Random rand = new Random(); // todo: use common random 236 if(rand.NextDouble() > 0.5) 243 if (random.NextDouble() > 0.5) 237 244 this.actualValue.Value = new BoolValue(true); 238 245 else … … 244 251 } else { 245 252 for (int i = 0; i < this.ParameterConfigurations.Count; i++) { 246 this.ParameterConfigurations.ElementAt(i).Cross(otherVc.ParameterConfigurations.ElementAt(i) );253 this.ParameterConfigurations.ElementAt(i).Cross(otherVc.ParameterConfigurations.ElementAt(i), random); 247 254 } 248 255 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs
r4997 r5009 23 23 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 24 24 } 25 public ILookupParameter< IAlgorithm> AlgorithmParameter {26 get { return (ILookupParameter< IAlgorithm>)Parameters["Algorithm"]; }25 public ILookupParameter<EngineAlgorithm> AlgorithmParameter { 26 get { return (ILookupParameter<EngineAlgorithm>)Parameters["Algorithm"]; } 27 27 } 28 public ILookupParameter<IItemList<I Problem>> ProblemsParameter {29 get { return (ILookupParameter<IItemList<I Problem>>)Parameters["Problems"]; }28 public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter { 29 get { return (ILookupParameter<IItemList<ISingleObjectiveProblem>>)Parameters["Problems"]; } 30 30 } 31 public ILookupParameter< IValueConfiguration> ParameterConfigurationParameter {32 get { return (ILookupParameter< IValueConfiguration>)Parameters["ValueConfiguration"]; }31 public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter { 32 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 33 33 } 34 34 public ValueParameter<IntValue> RepetitionsParameter { … … 41 41 } 42 42 43 public MetaOptimizationEvaluator() : base() { 43 public MetaOptimizationEvaluator() 44 : base() { 44 45 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector.")); 45 Parameters.Add(new LookupParameter< IAlgorithm>("Algorithm", "Missing description."));46 Parameters.Add(new LookupParameter<IItemList<I Problem>>("Problems", "Missing description."));47 Parameters.Add(new LookupParameter< IValueConfiguration>("ValueConfiguration", "Missing description."));46 Parameters.Add(new LookupParameter<EngineAlgorithm>("Algorithm", "Missing description.")); 47 Parameters.Add(new LookupParameter<IItemList<ISingleObjectiveProblem>>("Problems", "Missing description.")); 48 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description.")); 48 49 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "Number of evaluations for one individual.", new IntValue(3))); 49 50 } … … 60 61 61 62 public override IOperation Apply() { 62 AlgorithmParameter.ActualValue.Prepare(); 63 //ParameterizeAlgorithm(); 64 //ParameterConfigurationParameter.ActualValue.Parameterize(AlgorithmParameter.ActualValue); 63 EngineAlgorithm algorithm = (EngineAlgorithm)ParameterConfigurationParameter.ActualValue.ActualValue.Value; 64 65 // set parameters 66 ParameterConfigurationParameter.ActualValue.Parameterize(algorithm); 67 65 68 algorithmStopped = false; 66 AlgorithmParameter.ActualValue.Stopped += new EventHandler(ActualValue_Stopped);69 algorithm.Stopped += new EventHandler(ActualValue_Stopped); 67 70 68 71 double qualitySum = 0; 69 72 70 foreach (IProblem problem in ProblemsParameter.ActualValue) { 71 AlgorithmParameter.ActualValue.Problem = problem; 72 AlgorithmParameter.ActualValue.Start(); 73 while (!algorithmStopped) { 74 Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already) 75 } 76 AlgorithmParameter.ActualValue.Stopped -= new EventHandler(ActualValue_Stopped); 77 qualitySum += ((DoubleValue)AlgorithmParameter.ActualValue.Results["BestQuality"].Value).Value; 73 //foreach (ISingleObjectiveProblem problem in ProblemsParameter.ActualValue) { 74 algorithm.Engine = new SequentialEngine.SequentialEngine(); 75 //algorithm.Problem = problem; 76 algorithm.Prepare(); 77 algorithm.Start(); 78 while (!algorithmStopped) { 79 Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already) 78 80 } 81 double quality = ((DoubleValue)algorithm.Results["BestQuality"].Value).Value; 82 ParameterConfigurationParameter.ActualValue.Quality.Value = quality; 83 qualitySum += quality; 84 //} 79 85 80 double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count; 81 this.QualityParameter.ActualValue = new DoubleValue(qualityAvg); 86 algorithm.Stopped -= new EventHandler(ActualValue_Stopped); 87 88 //double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count; 89 //this.QualityParameter.ActualValue = new DoubleValue(qualityAvg); 90 this.QualityParameter.ActualValue = new DoubleValue(quality); 82 91 83 92 return base.Apply(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r4997 r5009 78 78 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 79 79 </Reference> 80 <Reference Include="HeuristicLab.SequentialEngine-3.3"> 81 <HintPath>..\..\HeuristicLab.MetaOptimization.Test\bin\Debug\HeuristicLab.SequentialEngine-3.3.dll</HintPath> 82 </Reference> 80 83 <Reference Include="System" /> 81 84 <Reference Include="System.Core" /> … … 96 99 <Compile Include="Encodings\RangeConstraints\DoubleValueRange.cs" /> 97 100 <Compile Include="Encodings\RangeConstraints\IntValueRange.cs" /> 98 <Compile Include="Encodings\ ValueConfigurations\RootValueConfiguration.cs" />101 <Compile Include="Encodings\ParameterConfigurationTree.cs" /> 99 102 <Compile Include="Encodings\ValueConfigurations\ValueConfiguration.cs" /> 100 103 <Compile Include="Encodings\ValueConfigurations\CheckedValueConfigurationCollection.cs" /> … … 112 115 <Compile Include="Interfaces\IValueConfiguration.cs" /> 113 116 <Compile Include="Encodings\RangeConstraints\Range.cs" /> 117 <Compile Include="Interfaces\IParameterConfigurationManipulator.cs" /> 118 <Compile Include="Manipulators\ParameterConfigurationManipulator.cs" /> 114 119 <Compile Include="Properties\AssemblyInfo.cs" /> 115 120 <Compile Include="MetaOptimizationProblem.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r4997 r5009 12 12 ConstrainedValue ActualValue { get; set; } 13 13 14 void Parameterize(); 15 void Randomize(); 16 void Mutate(); 17 void Cross(IOptimizable other); 14 void Randomize(IRandom random); 15 void Mutate(IRandom random); 16 void Cross(IOptimizable other, IRandom random); 18 17 19 18 event EventHandler IsOptimizableChanged; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs
r4997 r5009 10 10 Type ParameterDataType { get; } 11 11 ICheckedValueConfigurationCollection ValueConfigurations { get; } 12 IEnumerable<IItem> ValidValues { get; } 12 IItemSet<IItem> ValidValues { get; } 13 14 void Parameterize(IValueParameter parameter); 13 15 } 14 16 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs
r4997 r5009 14 14 event EventHandler StepSizeChanged; 15 15 16 IItem GetRandomValue( );16 IItem GetRandomValue(IRandom random); 17 17 } 18 18 … … 21 21 new T UpperBound { get; set; } 22 22 new T StepSize { get; set; } 23 new T GetRandomValue( );23 new T GetRandomValue(IRandom random); 24 24 } 25 25 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs
r4997 r5009 9 9 event EventHandler ValueChanged; 10 10 11 void Parameterize(IParameterizedItem item); 11 12 } 12 13 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r4997 r5009 37 37 private const string AlgorithmParameterName = "Algorithm"; 38 38 private const string ProblemsParameterName = "Problems"; 39 private const string AlgorithmParameterConfigurationParameterName = " AlgorithmParameterConfiguration";40 private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration";39 private const string AlgorithmParameterConfigurationParameterName = "InitialParameterConfigurationTree"; 40 //private const string ProblemParametersConfigurationParameterName = "ProblemParametersConfiguration"; 41 41 42 42 #region Parameter Properties 43 public ValueParameter<IAlgorithm> AlgorithmParameter {44 get { return (ValueParameter< IAlgorithm>)Parameters[AlgorithmParameterName]; }43 public IValueParameter<EngineAlgorithm> AlgorithmParameter { 44 get { return (ValueParameter<EngineAlgorithm>)Parameters[AlgorithmParameterName]; } 45 45 } 46 public ValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter {46 public IValueParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter { 47 47 get { return (ValueParameter<IItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; } 48 48 } 49 public ValueParameter<IValueConfiguration> AlgorithmParameterConfigurationParameter {50 get { return (ValueParameter< IValueConfiguration>)Parameters[AlgorithmParameterConfigurationParameterName]; }49 public IValueParameter<ParameterConfigurationTree> AlgorithmParameterConfigurationParameter { 50 get { return (ValueParameter<ParameterConfigurationTree>)Parameters[AlgorithmParameterConfigurationParameterName]; } 51 51 } 52 52 //public ValueParameter<IItemList<IParameterConfiguration>> ProblemParametersConfigurationParameter { … … 56 56 57 57 #region Properties 58 public IAlgorithm Algorithm {58 public EngineAlgorithm Algorithm { 59 59 get { return AlgorithmParameter.Value; } 60 60 set { AlgorithmParameter.Value = value; } … … 64 64 set { ProblemsParameter.Value = value; } 65 65 } 66 public IValueConfigurationAlgorithmParameterConfiguration {66 public ParameterConfigurationTree AlgorithmParameterConfiguration { 67 67 get { return AlgorithmParameterConfigurationParameter.Value; } 68 68 set { AlgorithmParameterConfigurationParameter.Value = value; } … … 74 74 #endregion 75 75 76 public MetaOptimizationProblem() 77 : base() { 78 Parameters.Add(new ValueParameter<IAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized.")); 79 Parameters.Add(new ValueParameter<IItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<IProblem>())); 80 Parameters.Add(new ValueParameter<IValueConfiguration>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized.")); 76 public MetaOptimizationProblem() : base() { 77 Parameters.Add(new ValueParameter<EngineAlgorithm>(AlgorithmParameterName, "The algorithm which's parameters should be optimized.")); 78 Parameters.Add(new ValueParameter<IItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ItemList<ISingleObjectiveProblem>())); 79 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(AlgorithmParameterConfigurationParameterName, "List of algorithm parameters that should be optimized.")); 81 80 //Parameters.Add(new ValueParameter<IItemList<IParameterConfiguration>>(ProblemParametersConfigurationParameterName, "List of problem parameters that should be optimized.", new ItemList<IParameterConfiguration>())); 82 81 … … 122 121 } 123 122 private void ParameterizeEvaluator() { 124 ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator). ValueConfigurationParameter.ActualName;123 ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 125 124 } 126 125 private void ParameterizeAnalyzer() { … … 152 151 } 153 152 void BaseLevelAlgorithmParameter_ValueChanged(object sender, EventArgs e) { 154 if (Algorithm != null) { 155 Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); 156 AlgorithmParameterConfiguration = new RootValueConfiguration(Algorithm, Algorithm.GetType()); 157 } 153 Algorithm.ProblemChanged += new EventHandler(BaseLevelAlgorithm_ProblemChanged); // when to deregister? 158 154 BaseLevelAlgorithm_ProblemChanged(sender, e); 159 155 } 160 156 161 157 void BaseLevelAlgorithm_ProblemChanged(object sender, EventArgs e) { 162 //ClearProblemParameters(); 163 //if (Algorithm.Problem != null) { 164 // AddProblemParameters(); 165 //} 158 if (Algorithm != null && Algorithm.Problem != null) { 159 AlgorithmParameterConfiguration = new ParameterConfigurationTree(Algorithm); 160 } 166 161 } 167 162 #endregion
Note: See TracChangeset
for help on using the changeset viewer.