Changeset 6489 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
- Timestamp:
- 06/27/11 23:56:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r6090 r6489 40 40 public sealed class MetaOptimizationProblem : SingleObjectiveHeuristicOptimizationProblem<IParameterConfigurationEvaluator, IParameterConfigurationCreator>, IStorableContent { 41 41 public string Filename { get; set; } 42 42 43 43 public const string AlgorithmTypeParameterName = "AlgorithmType"; 44 44 public const string ProblemTypeParameterName = "ProblemType"; … … 46 46 public const string ParameterConfigurationTreeParameterName = "ParameterConfiguration"; 47 47 public const string RepetitionsParameterName = "Repetitions"; 48 public const string QualityMeasureNameName = "QualityMeasureName"; 48 49 49 50 public const string IntValueManipulatorParameterName = "IntValueManipulator"; … … 67 68 } 68 69 public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { 69 get { return ( ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; }70 get { return (OptionalValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; } 70 71 } 71 72 public IValueParameter<IntValue> RepetitionsParameter { … … 79 80 public IValueParameter<IDoubleValueManipulator> DoubleValueManipulatorParameter { 80 81 get { return (ValueParameter<IDoubleValueManipulator>)Parameters[DoubleValueManipulatorParameterName]; } 82 } 83 public IValueParameter<StringValue> QualityMeasureNameParameter { 84 get { return (ValueParameter<StringValue>)Parameters[QualityMeasureNameName]; } 81 85 } 82 86 #endregion … … 131 135 Parameters.Add(new ValueParameter<ConstrainedTypeValue<IProblem>>(ProblemTypeParameterName, "The problem type.", new ConstrainedTypeValue<IProblem>())); 132 136 Parameters.Add(new ValueParameter<ConstrainedItemList<IProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<IProblem>())); 133 Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized."));137 Parameters.Add(new OptionalValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "Tree of algorithm parameters that should be optimized.")); // needs to be optional, when last problem is removed from list, it must be set null 134 138 Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3))); 139 Parameters.Add(new ValueParameter<StringValue>(QualityMeasureNameName, "The name of the quality result of the base-level algorithm. Subresults can be accessed by dot separator.", new StringValue("BestQuality"))); 135 140 136 141 var validIntManipulators = new ItemSet<IIntValueManipulator>(ApplicationManager.Manager.GetInstances<IIntValueManipulator>()); … … 174 179 [StorableHook(HookType.AfterDeserialization)] 175 180 private void AfterDeserializationHook() { 181 if(!Parameters.ContainsKey(QualityMeasureNameName)) Parameters.Add(new ValueParameter<StringValue>(QualityMeasureNameName, "The name of the quality result of the base-level algorithm. Subresults can be accessed by dot separator.", new StringValue("BestQuality"))); // backwards compatibility 176 182 RegisterParameterEvents(); 177 183 } … … 211 217 if (RunsAnalyzer != null) { 212 218 RunsAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 213 } 219 } 214 220 if (PMOPopulationDiversityAnalyzer != null) { 215 221 PMOPopulationDiversityAnalyzer.SolutionParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; … … 260 266 IAlgorithm instance = (IAlgorithm)Activator.CreateInstance(AlgorithmType.Value); 261 267 this.ProblemType.ValidTypes = ApplicationManager.Manager.GetTypes(instance.ProblemType, true).ToList(); 262 this.ProblemType.Value = this.ProblemType.ValidTypes.SingleOrDefault(t => t == typeof(SingleObjectiveTestFunctionProblem)) ?? this.ProblemType.ValidTypes.Where(t => t != typeof(MetaOptimizationProblem)).FirstOrDefault(); 263 // ProblemType_ValueChanged will add one problem and create ParameterConfigurationTree 268 var newProblemType = this.ProblemType.ValidTypes.SingleOrDefault(t => t == typeof(SingleObjectiveTestFunctionProblem)) ?? this.ProblemType.ValidTypes.Where(t => t != typeof(MetaOptimizationProblem)).FirstOrDefault(); 269 if (this.ProblemType.Value != newProblemType) 270 this.ProblemType.Value = newProblemType; // ProblemType_ValueChanged will add one problem and create ParameterConfigurationTree 271 else 272 ProblemType_ValueChanged(this, EventArgs.Empty); // call explicitly 264 273 } 265 274 … … 274 283 } 275 284 276 private void Problems_ItemsAdded(object sender, Collection s.CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) {285 private void Problems_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) { 277 286 // the first problem in the list is always the instance for the algorithm - this way some basic wiring between problem and algorithm can be sustained 278 287 if (e.Items.Single().Index == 0) { … … 287 296 } 288 297 289 private void Problems_ItemsRemoved(object sender, Collection s.CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) {298 private void Problems_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IProblem>> e) { 290 299 if (e.Items.Single().Index == 0) { 291 300 ParameterConfigurationTreeParameter.ActualValue = null;
Note: See TracChangeset
for help on using the changeset viewer.