Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/12 14:00:45 (12 years ago)
Author:
abeham
Message:

#1695
I solved this issue now. I found that CollectParameterValues was too monolithic in that you have to overwrite and re-implement the same method again if you wanted to change just a detail (in that case that operators are stored by their name). So I split CollectParameterValues into two separate logical parts:

  • CollectParameterValues is iterating over the parameters
  • GetCollectedValues decides what values are collected from the given parameter value

Algorithm and Problem now overwrite only GetCollectedValues, but reuse the implementation of the base class in that they only filter the values. When they see an IOperator they will instead convert it to its name. Using IEnumerable and yield I think that's a nice solution.

File:
1 edited

Legend:

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

    r7431 r7579  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    9798    #endregion
    9899
     100    protected override IEnumerable<KeyValuePair<string, IItem>> GetCollectedValues(IItem value) {
     101      var children = base.GetCollectedValues(value);
     102      foreach (var child in children) {
     103        if (child.Value is IOperator)
     104          yield return new KeyValuePair<string, IItem>(child.Key, new StringValue(((IOperator)child.Value).Name));
     105        else yield return child;
     106      }
     107    }
     108
    99109    #region events
    100110    private void Operators_Changed(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.