Changeset 7153 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding
- Timestamp:
- 12/07/11 21:09:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs
r6489 r7153 21 21 } 22 22 23 [Storable]24 23 public string Filename { get; set; } 25 24 … … 66 65 } 67 66 68 [Storable]69 67 protected Type[] validTypes; 70 68 public Type[] ValidTypes { … … 136 134 } 137 135 138 [Storable]139 136 protected IItemSet<IItem> validValues; 140 137 … … 216 213 [StorableConstructor] 217 214 protected ParameterConfiguration(bool deserializing) { } 215 218 216 protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner) 219 217 : base(original, cloner) { … … 236 234 } 237 235 238 239 236 public override IDeepCloneable Clone(Cloner cloner) { 240 237 return new ParameterConfiguration(this, cloner); … … 242 239 [StorableHook(HookType.AfterDeserialization)] 243 240 protected virtual void AfterDeserialization() { 241 this.validTypes = GetValidTypes(parameterDataType).ToArray(); 242 243 if (IsNullable) { 244 validTypes = new List<Type>(validTypes) { typeof(NullValue) }.ToArray(); 245 } 246 this.validValues = CreateValidValues(); 247 244 248 if (this.valueConfigurations != null) RegisterValueConfigurationEvents(); 245 249 if (this.actualValue != null) RegisterActualValueEvents(); … … 323 327 } 324 328 329 private static IEnumerable<Type> GetValidTypes(Type parameter) { 330 // in case of IOperator return empty list, otherwise hundreds of types would be returned. this mostly occurs for Successor which will never be optimized 331 if (parameter == typeof(IOperator)) 332 return new List<Type>(); 333 334 // return only one type for ValueTypeValues<> (Int, Double, Percent, Bool). Otherwise 2 types would be returned for DoubleValue (PercentValue which is derived) 335 if (IsSubclassOfRawGeneric(typeof(ValueTypeValue<>), parameter)) 336 return new List<Type> { parameter }; 337 338 //TODO: not sure if this if makes sense; maybe only leave else branch here 339 if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) { 340 // use existing validvalues if known 341 var parameterValidValues = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { }); 342 return parameterValidValues.Cast<object>().Select(x => x.GetType()); 343 } else { 344 // otherwise use all assignable types 345 return ApplicationManager.Manager.GetTypes(parameter, true); 346 } 347 } 348 325 349 private IItemSet<IItem> GetValidValues(IValueParameter parameter) { 326 350 if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) { … … 330 354 return null; 331 355 } 332 333 356 } 334 357 … … 612 635 private void KeepActualValueConfigurationIndexConsistent() { 613 636 if (this.valueConfigurations != null && this.valueConfigurations.CheckedItems.Count() > 0) { 614 if (this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&637 if (this.valueConfigurations.Count <= this.actualValueConfigurationIndex && 615 638 this.valueConfigurations.CheckedItems.Count(x => x.Index == this.actualValueConfigurationIndex) == 1) { 616 639 // everything is ok; do nothing
Note: See TracChangeset
for help on using the changeset viewer.