Changeset 5313 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Timestamp:
- 01/17/11 19:17:51 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r5303 r5313 105 105 } 106 106 107 [Storable] 108 protected string name; 109 public string Name { 110 get { return name; } 111 set { name = value; } 112 } 113 107 114 #region constructors and cloning 108 115 public ParameterConfigurationTree(EngineAlgorithm algorithm) … … 110 117 this.Optimize = true; // root must always be optimized 111 118 this.parameters = new Dictionary<string, IItem>(); 112 119 this.Name = algorithm.ItemName; 113 120 PopulateParameterConfigurations(algorithm); 114 121 } … … 119 126 protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner) 120 127 : base(original, cloner) { 128 this.name = original.name; 121 129 this.bestQualities = cloner.Clone(original.BestQualities); 122 130 this.averageQualities = cloner.Clone(original.averageQualities); … … 186 194 if (createBatchRuns) { 187 195 BatchRun batchRun = new BatchRun(string.Format("BatchRun: {0}", combination.ParameterInfoString)); 188 batchRun. Algorithm= clonedAlg;196 batchRun.Optimizer = clonedAlg; 189 197 batchRun.Repetitions = repetitions; 190 198 experiment.Optimizers.Add(batchRun); … … 218 226 return allOptimizables[random.Next(allOptimizables.Count)]; 219 227 } 228 229 public override string ToString() { 230 return this.Name; 231 } 220 232 } 221 233 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r5303 r5313 13 13 using HeuristicLab.Optimization; 14 14 using HeuristicLab.Collections; 15 using System.Drawing; 15 16 16 17 namespace HeuristicLab.Problems.MetaOptimization { … … 43 44 44 45 [Storable] 46 private Image itemImage; 47 public virtual Image ItemImage { 48 get { return itemImage ?? base.ItemImage; } 49 } 50 51 [Storable] 45 52 protected string parameterName; 46 53 public string ParameterName { … … 133 140 this.validTypes = GetValidTypes(valueParameter).ToArray(); 134 141 this.IsNullable = valueParameter.ItemName.StartsWith("Optional"); 142 this.itemImage = valueParameter.ItemImage; 135 143 if (IsNullable) { 136 144 validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray(); 137 145 } 138 this.ValueConfigurations = new CheckedValueConfigurationList( );146 this.ValueConfigurations = new CheckedValueConfigurationList(this.validValues ?? CreateValidValues()); 139 147 this.ActualValue = new ConstrainedValue( 140 148 valueParameter.Value != null ? (IItem)valueParameter.Value.Clone() : null, … … 162 170 this.actualValueConfigurationIndex = original.actualValueConfigurationIndex; 163 171 this.isNullable = original.isNullable; 172 this.itemImage = original.itemImage; 164 173 if (this.valueConfigurations != null) RegisterValueConfigurationEvents(); 165 174 } … … 246 255 } 247 256 248 private I temSet<IItem> CreateValidValues() {257 private IItemSet<IItem> CreateValidValues() { 249 258 var validValues = new ItemSet<IItem>(); 250 259 foreach (Type t in this.validTypes) { … … 295 304 } 296 305 public override string ItemDescription { 297 //get { return parameter != null ? parameter.Description : base.ItemDescription; }298 306 get { return base.ItemDescription; } 299 307 } 300 public override System.Drawing.Image ItemImage {301 //get { return parameter != null ? parameter.ItemImage : base.ItemImage; }302 get { return base.ItemImage; }303 }304 308 public override string ItemName { 305 //get { return parameter != null ?parameter.ItemName : base.ItemName; }306 309 get { return base.ItemName; } 307 310 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/CheckedValueConfigurationCollection.cs
r5277 r5313 25 25 } 26 26 27 public CheckedValueConfigurationList(I temSet<IItem> validValues) {27 public CheckedValueConfigurationList(IItemSet<IItem> validValues) { 28 28 this.validValues = validValues; 29 29 RegisterEvents(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5303 r5313 27 27 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 28 28 } 29 public ILookupParameter< EngineAlgorithm> AlgorithmParameter {30 get { return (ILookupParameter< EngineAlgorithm>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }29 public ILookupParameter<TypeValue> AlgorithmTypeParameter { 30 get { return (ILookupParameter<TypeValue>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; } 31 31 } 32 32 public ILookupParameter<IItemList<ISingleObjectiveProblem>> ProblemsParameter { … … 57 57 : base() { 58 58 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector.")); 59 Parameters.Add(new LookupParameter< EngineAlgorithm>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description."));59 Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description.")); 60 60 Parameters.Add(new LookupParameter<IItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName, "Missing description.")); 61 61 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description.")); … … 77 77 public override IOperation Apply() { 78 78 ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue; 79 EngineAlgorithm algorithm = (EngineAlgorithm)A lgorithmParameter.ActualValue;79 EngineAlgorithm algorithm = (EngineAlgorithm)Activator.CreateInstance(AlgorithmTypeParameter.ActualValue.Value); 80 80 IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue; 81 81 ItemDictionary<StringValue, RunCollection> runsCache = ResultsParameter.ActualValue.ContainsKey("Runs") ? (ItemDictionary<StringValue, RunCollection>)ResultsParameter.ActualValue["Runs"].Value : null; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5303 r5313 133 133 <ItemGroup> 134 134 <Compile Include="Analyzers\BestParameterConfigurationAnalyzer.cs" /> 135 <Compile Include="ConstrainedTypeValue.cs" /> 136 <Compile Include="TypeValue.cs" /> 135 137 <None Include="Properties\AssemblyInfo.cs.frame" /> 136 138 <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5303 r5313 40 40 public const string ProblemTypeParameterName = "ProblemType"; 41 41 public const string ProblemsParameterName = "Problems"; 42 public const string ParameterConfigurationTreeParameterName = " InitialParameterConfigurationTree";42 public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree"; 43 43 public const string RepetitionsParameterName = "Repetitions"; 44 44 … … 49 49 50 50 #region Parameter Properties 51 public IValueParameter< EngineAlgorithm> AlgorithmTypeParameter {52 get { return (ValueParameter< EngineAlgorithm>)Parameters[AlgorithmTypeParameterName]; }53 } 54 public IValueParameter< ISingleObjectiveProblem> ProblemTypeParameter {55 get { return (ValueParameter< ISingleObjectiveProblem>)Parameters[ProblemTypeParameterName]; }51 public IValueParameter<ConstrainedTypeValue<EngineAlgorithm>> AlgorithmTypeParameter { 52 get { return (ValueParameter<ConstrainedTypeValue<EngineAlgorithm>>)Parameters[AlgorithmTypeParameterName]; } 53 } 54 public IValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>> ProblemTypeParameter { 55 get { return (ValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>>)Parameters[ProblemTypeParameterName]; } 56 56 } 57 57 public IValueParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter { … … 76 76 #region Properties 77 77 public EngineAlgorithm Algorithm { 78 get { return CreateAlgorithm(AlgorithmType.Value, ProblemType.Value); } 79 } 80 public ConstrainedTypeValue<EngineAlgorithm> AlgorithmType { 78 81 get { return AlgorithmTypeParameter.Value; } 79 82 set { AlgorithmTypeParameter.Value = value; } 80 83 } 81 public ISingleObjectiveProblem Problem{84 public ConstrainedTypeValue<ISingleObjectiveProblem> ProblemType { 82 85 get { return ProblemTypeParameter.Value; } 83 86 set { ProblemTypeParameter.Value = value; } … … 108 111 public MetaOptimizationProblem() 109 112 : base() { 110 Parameters.Add(new ValueParameter< EngineAlgorithm>(AlgorithmTypeParameterName, "The algorithm which's parameters should be optimized.", new GeneticAlgorithm()));111 Parameters.Add(new ValueParameter< ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem()));113 Parameters.Add(new ValueParameter<ConstrainedTypeValue<EngineAlgorithm>>(AlgorithmTypeParameterName, "The algorithm which's parameters should be optimized.", new ConstrainedTypeValue<EngineAlgorithm>(typeof(GeneticAlgorithm)))); 114 Parameters.Add(new ValueParameter<ConstrainedTypeValue<ISingleObjectiveProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<ISingleObjectiveProblem>(typeof(SingleObjectiveTestFunctionProblem)))); 112 115 Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>())); 113 116 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized.")); … … 134 137 ParameterizeOperators(); 135 138 136 Problems.Type = Problem.GetType(); 137 Algorithm.Problem = Problem; 138 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 139 ProblemTypeParameter_ValueChanged(this, EventArgs.Empty); 139 140 } 140 141 … … 143 144 private MetaOptimizationProblem(MetaOptimizationProblem original, Cloner cloner) 144 145 : base(original, cloner) { 145 // todo146 146 this.RegisterParameterEvents(); 147 147 } … … 160 160 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 161 161 AlgorithmTypeParameter.ValueChanged += new EventHandler(AlgorithmTypeParameter_ValueChanged); 162 AlgorithmType.ValueChanged += new EventHandler(AlgorithmType_ValueChanged); 162 163 ProblemTypeParameter.ValueChanged += new EventHandler(ProblemTypeParameter_ValueChanged); 164 ProblemType.ValueChanged += new EventHandler(ProblemType_ValueChanged); 163 165 } 164 166 … … 215 217 ParameterizeAnalyzer(); 216 218 } 217 void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) { 218 Algorithm.Problem = Problem; 219 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 220 } 221 void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) { 222 Problems.Type = Problem.GetType(); 223 Algorithm.Problem = Problem; 224 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm); 225 } 226 #endregion 219 private void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) { 220 AlgorithmType_ValueChanged(sender, e); 221 } 222 223 private void AlgorithmType_ValueChanged(object sender, EventArgs e) { 224 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value)); 225 } 226 227 private void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) { 228 ProblemType_ValueChanged(sender, e); 229 } 230 231 private void ProblemType_ValueChanged(object sender, EventArgs e) { 232 Problems.Clear(); 233 Problems.Type = ProblemType.Value; 234 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(CreateAlgorithm(AlgorithmType.Value, ProblemType.Value)); 235 } 236 #endregion 237 238 private EngineAlgorithm CreateAlgorithm(Type algorithmType, Type problemType) { 239 EngineAlgorithm algorithm = (EngineAlgorithm)Activator.CreateInstance(algorithmType); 240 algorithm.Problem = (IProblem)Activator.CreateInstance(problemType); 241 return algorithm; 242 } 243 244 public void ImportAlgorithm(EngineAlgorithm algorithm) { 245 AlgorithmType.Value = algorithm.GetType(); 246 if(algorithm.Problem != null) ProblemType.Value = algorithm.Problem.GetType(); 247 ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(algorithm); 248 if(algorithm.Problem != null) Problems.Add((ISingleObjectiveProblem)algorithm.Problem); 249 } 227 250 } 228 251 }
Note: See TracChangeset
for help on using the changeset viewer.