Changeset 8004


Ignore:
Timestamp:
06/14/12 09:53:42 (7 years ago)
Author:
mkommend
Message:

#1864: Corrected deserialization of the operator collection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r7999 r8004  
    3434  [StorableClass]
    3535  public abstract class Problem : ParameterizedNamedItem, IProblem {
    36     private static readonly string OperatorsParameterName = "Operators";
     36    private const string OperatorsParameterName = "Operators";
    3737    public IFixedValueParameter<ItemCollection<IItem>> OperatorsParameter {
    3838      get { return (IFixedValueParameter<ItemCollection<IItem>>)Parameters[OperatorsParameterName]; }
     
    6161      // BackwardsCompatibility3.3
    6262      #region Backwards compatible code, remove with 3.4
    63       if (Parameters.ContainsKey(OperatorsParameterName) && Parameters[OperatorsParameterName] is FixedValueParameter<OperatorCollection>) {
    64         OperatorCollection tmp = ((IFixedValueParameter<OperatorCollection>)Parameters[OperatorsParameterName]).Value;
    65         Parameters.Remove(OperatorsParameterName);
    66         Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(tmp), false));       
    67         OperatorsParameter.Hidden = true;
     63      IParameter operatorsParam;
     64      if (Parameters.TryGetValue(OperatorsParameterName, out operatorsParam)) {
     65        var operators = operatorsParam.ActualValue as OperatorCollection;
     66        if (operators != null) {
     67          Parameters.Remove(OperatorsParameterName);
     68          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(operators), false));
     69          OperatorsParameter.Hidden = true;
     70        }
    6871      }
    6972      #endregion
     
    8487    private IEnumerable<IOperator> StorableOperators {
    8588      set {
     89        IParameter operatorsParam;
     90        if (Parameters.TryGetValue(OperatorsParameterName, out operatorsParam)) {
     91          var items = operatorsParam.ActualValue as ItemCollection<IItem>;
     92          if (items == null) Parameters.Remove(operatorsParam);
     93        }
     94
     95        //necessary to convert old experiments files where no parameter was used for saving the operators
    8696        if (!Parameters.ContainsKey(OperatorsParameterName)) {
    87           Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(value), false));
     97          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
    8898          OperatorsParameter.Hidden = true;
    8999        }
     100        if (value != null) Operators.AddRange(value);
    90101      }
    91102    }
Note: See TracChangeset for help on using the changeset viewer.