Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/12 18:02:33 (12 years ago)
Author:
gkronber
Message:

#1847: merged trunk changes r7800:HEAD into gp move operators branch

Location:
branches/GP-MoveOperators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Optimization/3.3/Problems/Problem.cs

    r7706 r8085  
    3434  [StorableClass]
    3535  public abstract class Problem : ParameterizedNamedItem, IProblem {
    36     private static readonly string OperatorsParameterName = "Operators";
    37 
    38     public IFixedValueParameter<OperatorCollection> OperatorsParameter {
    39       get { return (IFixedValueParameter<OperatorCollection>)Parameters[OperatorsParameterName]; }
     36    private const string OperatorsParameterName = "Operators";
     37    public IFixedValueParameter<ItemCollection<IItem>> OperatorsParameter {
     38      get { return (IFixedValueParameter<ItemCollection<IItem>>)Parameters[OperatorsParameterName]; }
    4039    }
    4140
     
    5352    protected Problem()
    5453      : base() {
    55       Parameters.Add(new FixedValueParameter<OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(), false));
     54      Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
    5655      OperatorsParameter.Hidden = true;
    5756      RegisterEventHandlers();
     
    6059    [StorableHook(HookType.AfterDeserialization)]
    6160    private void AfterDeserialization() {
     61      // BackwardsCompatibility3.3
     62      #region Backwards compatible code, remove with 3.4
     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        }
     71      }
     72      #endregion
     73
    6274      RegisterEventHandlers();
    6375    }
    6476
    6577    private void RegisterEventHandlers() {
    66       Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
    67       Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
    68       Operators.CollectionReset += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
     78      Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed);
     79      Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed);
     80      Operators.CollectionReset += new CollectionItemsChangedEventHandler<IItem>(Operators_Changed);
    6981    }
    7082
     
    7284    // BackwardsCompatibility3.3
    7385    #region Backwards compatible code, remove with 3.4
    74     [Storable(Name = "Operators")]
     86    [Storable(Name = "Operators", AllowOneWay = true)]
    7587    private IEnumerable<IOperator> StorableOperators {
    76       get { return null; }
    7788      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
    7896        if (!Parameters.ContainsKey(OperatorsParameterName)) {
    79           Parameters.Add(new FixedValueParameter<OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(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));
    8098          OperatorsParameter.Hidden = true;
    8199        }
     100        if (value != null) Operators.AddRange(value);
    82101      }
    83102    }
    84103    #endregion
    85     protected OperatorCollection Operators {
     104    protected ItemCollection<IItem> Operators {
    86105      get {
    87106        // BackwardsCompatibility3.3
    88107        #region Backwards compatible code, remove with 3.4
    89108        if (!Parameters.ContainsKey(OperatorsParameterName)) {
    90           Parameters.Add(new FixedValueParameter<OperatorCollection>(OperatorsParameterName, "The operators that the problem provides to the algorithms.", new OperatorCollection(), false));
     109          Parameters.Add(new FixedValueParameter<ItemCollection<IItem>>(OperatorsParameterName, "The operators and items that the problem provides to the algorithms.", new ItemCollection<IItem>(), false));
    91110          OperatorsParameter.Hidden = true;
    92111        }
     
    95114      }
    96115    }
    97     IEnumerable<IOperator> IProblem.Operators { get { return Operators; } }
     116    IEnumerable<IItem> IProblem.Operators { get { return Operators; } }
    98117    #endregion
    99118
Note: See TracChangeset for help on using the changeset viewer.