Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/07/11 21:09:40 (13 years ago)
Author:
ascheibe
Message:

#1215

  • removed storing of valid types and valid values. This leads to wrong plugin discovery by the Persistence and Hive. Previously references to types of all available algorithms and problems were saved and needed by Hive for deserializing a MetaOpt task. Now only the actual values are saved and valid types and values are discovered after deserialization.
  • added missing license headers
  • added missing plugin references to plugin file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r6489 r7153  
    2121    }
    2222
    23     [Storable]
    2423    public string Filename { get; set; }
    2524
     
    6665    }
    6766
    68     [Storable]
    6967    protected Type[] validTypes;
    7068    public Type[] ValidTypes {
     
    136134    }
    137135
    138     [Storable]
    139136    protected IItemSet<IItem> validValues;
    140137
     
    216213    [StorableConstructor]
    217214    protected ParameterConfiguration(bool deserializing) { }
     215
    218216    protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner)
    219217      : base(original, cloner) {
     
    236234    }
    237235
    238 
    239236    public override IDeepCloneable Clone(Cloner cloner) {
    240237      return new ParameterConfiguration(this, cloner);
     
    242239    [StorableHook(HookType.AfterDeserialization)]
    243240    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
    244248      if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
    245249      if (this.actualValue != null) RegisterActualValueEvents();
     
    323327    }
    324328
     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
    325349    private IItemSet<IItem> GetValidValues(IValueParameter parameter) {
    326350      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
     
    330354        return null;
    331355      }
    332      
    333356    }
    334357
     
    612635    private void KeepActualValueConfigurationIndexConsistent() {
    613636      if (this.valueConfigurations != null && this.valueConfigurations.CheckedItems.Count() > 0) {
    614         if(this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&
     637        if (this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&
    615638           this.valueConfigurations.CheckedItems.Count(x => x.Index == this.actualValueConfigurationIndex) == 1) {
    616639          // everything is ok; do nothing
Note: See TracChangeset for help on using the changeset viewer.