Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11588


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

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

Location:
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
Files:
7 edited

Legend:

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

    r11587 r11588  
    3636  public sealed class BinaryEncoding : Encoding<IBinaryVectorCreator> {
    3737    #region Encoding Parameters
    38     [Storable]
    3938    private IFixedValueParameter<IntValue> lengthParameter;
    4039    public IFixedValueParameter<IntValue> LengthParameter {
     
    4241      set {
    4342        if (value == null) throw new ArgumentNullException("Length parameter must not be null.");
     43        if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null.");
    4444        if (lengthParameter == value) return;
     45
     46        if (lengthParameter != null) Parameters.Remove(lengthParameter);
    4547        lengthParameter = value;
     48        Parameters.Add(lengthParameter);
    4649        OnLengthParameterChanged();
    4750      }
    48     }
    49     public override IEnumerable<IValueParameter> Parameters {
    50       get { return new IValueParameter[] { LengthParameter }; }
    5151    }
    5252    #endregion
     
    7272    public BinaryEncoding(string name, int length)
    7373      : base(name) {
    74       lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     74      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
    7575      SolutionCreator = new RandomBinaryVectorCreator();
    7676      RegisterParameterEvents();
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/Encoding.cs

    r11587 r11588  
    3131  [Item("Encoding", "Base class for describing different encodings.")]
    3232  [StorableClass]
    33   public abstract class Encoding<T> : NamedItem, IEncoding
     33  public abstract class Encoding<T> : ParameterizedNamedItem, IEncoding
    3434    where T : class,ISolutionCreator {
    3535    public override sealed bool CanChangeName {
    3636      get { return false; }
    3737    }
    38 
    39     public abstract IEnumerable<IValueParameter> Parameters { get; }
    4038
    4139    protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>());
  • 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();
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/MultiEncoding.cs

    r11587 r11588  
    3535
    3636    private readonly List<IEncoding> encodings;
    37 
    3837    [Storable]
    3938    public IEnumerable<IEncoding> Encodings {
     
    4241    }
    4342
    44     public override IEnumerable<IValueParameter> Parameters {
    45       get { return Encodings.SelectMany(e => e.Parameters); }
    46     }
    4743
    4844    [StorableConstructor]
     
    7167      encodings.Add(encoding);
    7268
     69      Parameters.AddRange(encoding.Parameters);
     70
    7371      foreach (var @operator in Operators.OfType<IMultiEncodingOperator>()) {
    7472        @operator.AddEncoding(encoding);
     
    7977    public bool Remove(IEncoding encoding) {
    8078      var success = encodings.Remove(encoding);
     79      Parameters.RemoveRange(encoding.Parameters);
    8180      foreach (var @operator in Operators.OfType<IMultiEncodingOperator>()) {
    8281        @operator.RemoveEncoding(encoding);
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/PermutationEncoding.cs

    r11587 r11588  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.PermutationEncoding;
     29using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031using HeuristicLab.PluginInfrastructure;
     
    3536  public sealed class PermutationEncoding : Encoding<IPermutationCreator> {
    3637    #region encoding parameters
    37     [Storable]
    3838    private IFixedValueParameter<IntValue> lengthParameter;
    3939    public IFixedValueParameter<IntValue> LengthParameter {
     
    4141      set {
    4242        if (value == null) throw new ArgumentNullException("Length parameter must not be null.");
     43        if (value.Value == null) throw new ArgumentNullException("Length parameter value must not be null.");
    4344        if (lengthParameter == value) return;
     45
     46        if (lengthParameter != null) Parameters.Remove(lengthParameter);
    4447        lengthParameter = value;
     48        Parameters.Add(lengthParameter);
    4549        OnLengthParameterChanged();
    4650      }
    4751    }
    4852
    49     [Storable]
    5053    private IFixedValueParameter<PermutationType> permutationTypeParameter;
    5154    public IFixedValueParameter<PermutationType> PermutationTypeParameter {
     
    5356      set {
    5457        if (value == null) throw new ArgumentNullException("Permutation type parameter must not be null.");
     58        if (value.Value == null) throw new ArgumentNullException("Permutation type parameter value must not be null.");
    5559        if (permutationTypeParameter == value) return;
     60
     61        if (permutationTypeParameter != null) Parameters.Remove(permutationTypeParameter);
    5662        permutationTypeParameter = value;
     63        Parameters.Add(permutationTypeParameter);
    5764        OnPermutationTypeParameterChanged();
    5865      }
    59     }
    60 
    61     public override IEnumerable<IValueParameter> Parameters {
    62       get { return new IValueParameter[] { LengthParameter, PermutationTypeParameter }; }
    6366    }
    6467    #endregion
     
    9295    public PermutationEncoding(string name, int length, PermutationTypes type)
    9396      : base(name) {
    94       Length = length;
    95       Type = type;
     97      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     98      PermutationTypeParameter = new FixedValueParameter<PermutationType>(Name + "Type", new PermutationType(type));
    9699
    97100      SolutionCreator = new RandomPermutationCreator();
     
    101104
    102105    private void OnLengthParameterChanged() {
    103       RegisterParameterEvents();
     106      RegisterLengthParameterEvents();
    104107      ConfigureOperators(Operators);
    105108    }
    106109
    107110    private void OnPermutationTypeParameterChanged() {
    108       RegisterParameterEvents();
     111      RegisterPermutationTypeParameterEvents();
    109112      ConfigureOperators(Operators);
    110113    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Encodings/RealEncoding.cs

    r11587 r11588  
    3737  public sealed class RealEncoding : Encoding<IRealVectorCreator> {
    3838    #region Encoding Parameters
    39     [Storable]
    4039    private IFixedValueParameter<IntValue> lengthParameter;
    4140    public IFixedValueParameter<IntValue> LengthParameter {
     
    4342      set {
    4443        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.");
    4545        if (lengthParameter == value) return;
     46
     47        if (lengthParameter != null) Parameters.Remove(lengthParameter);
    4648        lengthParameter = value;
     49        Parameters.Add(lengthParameter);
    4750        OnLengthParameterChanged();
    4851      }
    4952    }
    5053
    51     [Storable]
    5254    private IValueParameter<DoubleMatrix> boundsParameter;
    5355    public IValueParameter<DoubleMatrix> BoundsParameter {
     
    5658        if (value == null) throw new ArgumentNullException("Bounds parameter must not be null.");
    5759        if (boundsParameter == value) return;
     60
     61        if (boundsParameter != null) Parameters.Remove(boundsParameter);
    5862        boundsParameter = value;
     63        Parameters.Add(boundsParameter);
    5964        OnBoundsParameterChanged();
    6065      }
    61     }
    62 
    63     public override IEnumerable<IValueParameter> Parameters {
    64       get { return new IValueParameter[] { LengthParameter, BoundsParameter }; }
    6566    }
    6667    #endregion
     
    99100      bounds[0, 1] = max;
    100101
    101       lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
    102       boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);
     102      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     103      BoundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);
    103104
    104105      SolutionCreator = new UniformRandomRealVectorCreator();
     
    118119        bounds[i, 1] = max[i];
    119120      }
    120       lengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
    121       boundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);
     121      LengthParameter = new FixedValueParameter<IntValue>(Name + "Length", new IntValue(length));
     122      BoundsParameter = new ValueParameter<DoubleMatrix>(Name + "Bounds", bounds);
    122123
    123124      SolutionCreator = new UniformRandomRealVectorCreator();
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Interfaces/IEncoding.cs

    r11587 r11588  
    2626
    2727namespace HeuristicLab.Problems.Programmable {
    28   public interface IEncoding : INamedItem {
     28  public interface IEncoding : IParameterizedNamedItem {
    2929    ISolutionCreator SolutionCreator { get; set; }
    3030
    31     IEnumerable<IValueParameter> Parameters { get; }
    3231    IEnumerable<IOperator> Operators { get; }
    3332    //event EventHandler ParameterConfigurationChanged;
Note: See TracChangeset for help on using the changeset viewer.