Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/26/14 16:09:14 (9 years ago)
Author:
mkommend
Message:

#2174: Adapted encodings to store its specific parameters in the standard parameter collection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/IntegerEncoding.cs

    r11587 r11588  
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    2929using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132using HeuristicLab.PluginInfrastructure;
     
    3637  public class IntegerEncoding : Encoding<IIntegerVectorCreator> {
    3738    #region Encoding Parameters
    38     [Storable]
    3939    private IFixedValueParameter<IntValue> lengthParameter;
    4040    public IFixedValueParameter<IntValue> LengthParameter {
     
    4242      set {
    4343        if (value == null) throw new ArgumentNullException("Length parameter must not be null.");
     44        if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null.");
    4445        if (lengthParameter == value) return;
     46
     47        if (lengthParameter != null) Parameters.Remove(lengthParameter);
    4548        lengthParameter = value;
     49        Parameters.Add(lengthParameter);
    4650        OnLengthParameterChanged();
    4751      }
    4852    }
    4953
    50     [Storable]
    5154    private IValueParameter<IntMatrix> boundsParameter;
    5255    public IValueParameter<IntMatrix> BoundsParameter {
     
    5558        if (value == null) throw new ArgumentNullException("Bounds parameter must not be null.");
    5659        if (boundsParameter == value) return;
     60
     61        if (boundsParameter != null) Parameters.Remove(boundsParameter);
    5762        boundsParameter = value;
     63        Parameters.Add(boundsParameter);
    5864        OnBoundsParameterChanged();
    5965      }
    60     }
    61 
    62     public override IEnumerable<IValueParameter> Parameters {
    63       get { return new IValueParameter[] { LengthParameter, BoundsParameter }; }
    6466    }
    6567    #endregion
     
    9597      if (step.HasValue && step.Value <= 0) throw new ArgumentException("step must be greater than zero or null", "step");
    9698
    97       Length = length;
    98       Bounds = new IntMatrix(1, step.HasValue ? 3 : 2);
    99       Bounds[0, 0] = min;
    100       Bounds[0, 1] = max;
    101       if (step.HasValue) Bounds[0, 2] = step.Value;
     99      var bounds = new IntMatrix(1, step.HasValue ? 3 : 2);
     100      bounds[0, 0] = min;
     101      bounds[0, 1] = max;
     102      if (step.HasValue) bounds[0, 2] = step.Value;
     103
     104      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     105      BoundsParameter = new ValueParameter<IntMatrix>(Name + "Bounds", bounds);
    102106
    103107      SolutionCreator = new UniformRandomIntegerVectorCreator();
     
    112116      if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min");
    113117
    114       Length = length;
    115       Bounds = new IntMatrix(min.Count, step != null ? 3 : 2);
     118      var bounds = new IntMatrix(min.Count, step != null ? 3 : 2);
    116119      for (int i = 0; i < min.Count; i++) {
    117         Bounds[i, 0] = min[i];
    118         Bounds[i, 1] = max[i];
    119         if (step != null) Bounds[i, 2] = step[i];
    120       }
     120        bounds[i, 0] = min[i];
     121        bounds[i, 1] = max[i];
     122        if (step != null) bounds[i, 2] = step[i];
     123      }
     124
     125      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     126      BoundsParameter = new ValueParameter<IntMatrix>(Name + "Bounds", bounds);
    121127
    122128      SolutionCreator = new UniformRandomIntegerVectorCreator();
Note: See TracChangeset for help on using the changeset viewer.