Changeset 6489 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Timestamp:
- 06/27/11 23:56:35 (13 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOBestSolutionHistoryAnalyzer.cs
r6197 r6489 75 75 bestSolutionHistory = results[key].Value as RunCollection; 76 76 } 77 if (bestSolutionHistory.Count == 0 || best.ParameterInfoString != ((StringValue)bestSolutionHistory.Last().Results["Meta .ParameterInfoString"]).Value) {77 if (bestSolutionHistory.Count == 0 || best.ParameterInfoString != ((StringValue)bestSolutionHistory.Last().Results["Meta-ParameterInfoString"]).Value) { 78 78 IRun run = best.ToRun(string.Format("{0}: {1}", currentGeneration, best.ParameterInfoString), false); 79 run.Results.Add("Meta .Generation", new IntValue(currentGeneration));80 run.Results.Add("Meta .ParameterInfoString", new StringValue(best.ParameterInfoString));79 run.Results.Add("Meta-Generation", new IntValue(currentGeneration)); 80 run.Results.Add("Meta-ParameterInfoString", new StringValue(best.ParameterInfoString)); 81 81 bestSolutionHistory.Add(run); 82 82 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs
r6090 r6489 74 74 var runCollection = allRuns.Single(x => x.Key.Value == key).Value; 75 75 foreach (var run in solution.Runs) { 76 if (!((BoolValue)run.Results["Meta .FromCache"]).Value || first) {77 run.Results["Meta .FromCache"] = new BoolValue(true);76 if (!((BoolValue)run.Results["Meta-FromCache"]).Value || first) { 77 run.Results["Meta-FromCache"] = new BoolValue(true); 78 78 runCollection.Add(run); 79 79 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs
r5653 r6489 22 22 get { 23 23 if (!initialized) 24 throw new SystemException("Enumeration not started. Call MoveNext!");24 throw new InvalidOperationException("Enumeration not started. Call MoveNext!"); 25 25 return Current; 26 26 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r6421 r6489 161 161 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Algorithm", algproblemitem.AlgorithmParameter)); 162 162 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Problem", algproblemitem.ProblemParameter)); 163 164 // problems can be modified in the list of problem instances, so the parameters which are not Optimize=true, 165 // must not be modifiable in the parameter configuration tree. otherwise the parameter values would be ambiguous 166 ProblemConfiguration.ValuesReadOnly = true; 163 167 } 164 168 public ParameterConfigurationTree() { } … … 190 194 [StorableHook(HookType.AfterDeserialization)] 191 195 private void AfterDeserialization() { 196 if(ProblemConfiguration != null) ProblemConfiguration.ValuesReadOnly = true; 192 197 } 193 198 #endregion -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r6486 r6489 146 146 } 147 147 148 [Storable] 149 protected bool valuesReadOnly = false; 150 public virtual bool ValuesReadOnly { 151 get { return valuesReadOnly; } 152 set { 153 if (value != this.valuesReadOnly) { 154 this.valuesReadOnly = value; 155 foreach (var vc in this.valueConfigurations) { 156 vc.ValuesReadOnly = value; 157 } 158 } 159 } 160 } 148 161 149 162 #region Constructors and Cloning … … 220 233 this.discoverValidValues = original.discoverValidValues; 221 234 this.AutoPopulateValueConfigurations = original.AutoPopulateValueConfigurations; 235 this.valuesReadOnly = original.valuesReadOnly; 222 236 } 223 237 … … 485 499 486 500 public void Parameterize(IValueParameter parameter) { 501 if (!Optimize && ValuesReadOnly) 502 return; 503 487 504 if (Optimize) { 488 505 if (this.ActualValue.Value is IParameterizedItem) { -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ParameterizedValueConfiguration.cs
r5927 r6489 46 46 get { return discoverValidValues; } 47 47 set { discoverValidValues = value; } 48 } 49 50 public override bool ValuesReadOnly { 51 set { 52 if (value != this.valuesReadOnly) { 53 this.valuesReadOnly = value; 54 foreach (var pc in this.parameterConfigurations) { 55 pc.ValuesReadOnly = value; 56 } 57 } 58 } 48 59 } 49 60 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs
r5927 r6489 73 73 } 74 74 75 [Storable] 76 protected bool valuesReadOnly = false; 77 public virtual bool ValuesReadOnly { 78 get { return valuesReadOnly; } 79 set { 80 if (value != this.valuesReadOnly) { 81 this.valuesReadOnly = value; 82 } 83 } 84 } 85 75 86 #region Constructors and Cloning 76 87 public ValueConfiguration(IItem value, Type valueDataType) { … … 88 99 this.optimize = original.optimize; 89 100 this.number = original.number; 101 this.valuesReadOnly = original.valuesReadOnly; 90 102 RegisterActualValueEvents(); 91 103 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmRunsAnalyzer.cs
r6473 r6489 69 69 public IScope CurrentScope { 70 70 get { return CurrentScopeParameter.ActualValue; } 71 } 72 public LookupParameter<StringValue> QualityMeasureNameParameter { 73 get { return (LookupParameter<StringValue>)Parameters[MetaOptimizationProblem.QualityMeasureNameName]; } 71 74 } 72 75 #endregion … … 93 96 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName)); 94 97 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName)); 98 Parameters.Add(new LookupParameter<StringValue>(MetaOptimizationProblem.QualityMeasureNameName)); 95 99 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents.")); 96 100 } … … 104 108 private void AfterDeserialization() { 105 109 if (!Parameters.ContainsKey("CurrentScope")) Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents.")); // backwards compatibility 110 if (!Parameters.ContainsKey(MetaOptimizationProblem.QualityMeasureNameName)) Parameters.Add(new LookupParameter<StringValue>(MetaOptimizationProblem.QualityMeasureNameName)); // backwards compatibility 106 111 } 107 112 … … 118 123 double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value; 119 124 double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value; 120 var resultNames = new List<string> { "BestQuality", "Execution Time", "EvaluatedSolutions" }; 125 string qualityMeasureName = QualityMeasureNameParameter.ActualValue.Value; 126 var resultNames = new List<string> { qualityMeasureName, "Execution Time", "EvaluatedSolutions" }; 121 127 int currentGeneration = GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0; 122 128 double[] referenceQualityAverages; … … 146 152 MetaOptimizationUtil.ClearResults(run, resultNames); 147 153 MetaOptimizationUtil.ClearParameters(run, parameterNames); 148 run.Results.Add("Meta .FromCache", new BoolValue(false));149 run.Results.Add("Meta .Generation", new IntValue(currentGeneration));150 run.Results.Add("Meta .ProblemIndex", new IntValue(problemIndex));154 run.Results.Add("Meta-FromCache", new BoolValue(false)); 155 run.Results.Add("Meta-Generation", new IntValue(currentGeneration)); 156 run.Results.Add("Meta-ProblemIndex", new IntValue(problemIndex)); 151 157 run.Name = string.Format("{0} Problem {1} Run {2}", parameterConfiguration.ParameterInfoString, problemIndex, repetitionIndex); 152 qualities[problemIndex][repetitionIndex] = (((DoubleValue)run.Results["BestQuality"]).Value); 158 159 qualities[problemIndex][repetitionIndex] = GetResultValue<DoubleValue>(run.Results, qualityMeasureName).Value; 153 160 executionTimes[problemIndex][repetitionIndex] = (((TimeSpanValue)run.Results["Execution Time"]).Value); 154 161 evaluatedSolutions[problemIndex][repetitionIndex] = (((IntValue)run.Results["EvaluatedSolutions"]).Value); … … 203 210 204 211 return base.Apply(); 212 } 213 214 private T1 GetResultValue<T1>(IDictionary<string, IItem> results, string resultName) { 215 return (T1)results[resultName]; 216 217 //string separator = "."; 218 //string[] tokens = resultName.Split(separator.ToCharArray()); 219 220 //IDictionary<string, IItem> currentResults = results; 221 //IItem currentResult = null; 222 //for (int i = 0; i < tokens.Length; i++) { 223 // if(currentResults == null) 224 // throw new KeyNotFoundException("Result value " + resultName + " was not found"); 225 // if (currentResults.ContainsKey(tokens[i])) { 226 // currentResult = currentResults[tokens[i]]; 227 // currentResults = currentResult as IDictionary<string, IItem>; 228 // } else { 229 // throw new KeyNotFoundException("Result value " + resultName + " was not found"); 230 // } 231 //} 232 //return (T1)currentResult; 205 233 } 206 234 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r5653 r6489 26 26 event EventHandler IsOptimizableChanged; 27 27 event EventHandler OptimizeChanged; 28 29 /// <summary> 30 /// indicates if the actualvalues are modifiable 31 /// </summary> 32 bool ValuesReadOnly { get; set; } 28 33 } 29 34 } -
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.