Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/20 18:16:58 (4 years ago)
Author:
abeham
Message:

#2521: refactoring in progress

Location:
branches/2521_ProblemRefactoring
Files:
1 added
3 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEncoding.cs

    r17567 r17587  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.ComponentModel;
    2524using System.Linq;
    2625using HEAL.Attic;
    2726using HeuristicLab.Common;
    2827using HeuristicLab.Core;
    29 using HeuristicLab.Data;
    3028using HeuristicLab.Optimization;
    31 using HeuristicLab.Parameters;
    3229using HeuristicLab.PluginInfrastructure;
    3330
     
    3532  [Item("BinaryVectorEncoding", "Describes a binary vector encoding.")]
    3633  [StorableType("889C5E1A-3FBF-4AB3-AB2E-199A781503B5")]
    37   public sealed class BinaryVectorEncoding : Encoding<BinaryVector>, INotifyPropertyChanged {
    38     #region Encoding Parameters
    39     [Storable] public IValueParameter<IntValue> LengthParameter { get; private set; }
    40     #endregion
    41 
    42     public int Length {
    43       get { return LengthParameter.Value.Value; }
    44       set {
    45         if (Length == value) return;
    46         LengthParameter.Value = new IntValue(value, @readonly: LengthParameter.Value.ReadOnly);
    47       }
    48     }
     34  public sealed class BinaryVectorEncoding : VectorEncoding<BinaryVector> {
    4935
    5036    [StorableConstructor]
     
    5339    private void AfterDeserialization() {
    5440      DiscoverOperators();
    55       RegisterEventHandlers();
    5641    }
    5742    public override IDeepCloneable Clone(Cloner cloner) { return new BinaryVectorEncoding(this, cloner); }
    58     private BinaryVectorEncoding(BinaryVectorEncoding original, Cloner cloner)
    59       : base(original, cloner) {
    60       LengthParameter = cloner.Clone(original.LengthParameter);
    61       RegisterEventHandlers();
    62     }
    63 
     43    private BinaryVectorEncoding(BinaryVectorEncoding original, Cloner cloner) : base(original, cloner) { }
    6444    public BinaryVectorEncoding() : this("BinaryVector", 10) { }
    6545    public BinaryVectorEncoding(string name) : this(name, 10) { }
    6646    public BinaryVectorEncoding(int length) : this("BinaryVector", length) { }
    6747    public BinaryVectorEncoding(string name, int length)
    68       : base(name) {
    69       Parameters.Add(LengthParameter = new ValueParameter<IntValue>(Name + ".Length", new IntValue(length)) { ReadOnly = true });
    70      
     48      : base(name, length) {     
    7149      SolutionCreator = new RandomBinaryVectorCreator();
     50
    7251      DiscoverOperators();
    73 
    74       RegisterEventHandlers();
    75     }
    76 
    77     private void RegisterEventHandlers() {
    78       IntValueParameterChangeHandler.Create(LengthParameter, () => OnPropertyChanged(nameof(Length)));
    7952    }
    8053
     
    153126    }
    154127    #endregion
    155 
    156     public event PropertyChangedEventHandler PropertyChanged;
    157     private void OnPropertyChanged(string property) {
    158       PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
    159     }
    160128  }
    161129}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs

    r17567 r17587  
    3434  [Item("IntegerVectorEncoding", "Describes an integer vector encoding.")]
    3535  [StorableType("15D6E55E-C39F-4784-8350-14A0FD47CF0E")]
    36   public sealed class IntegerVectorEncoding : Encoding<IntegerVector> {
    37     #region Encoding Parameters
    38     [Storable]
    39     private IFixedValueParameter<IntValue> lengthParameter;
    40     public IFixedValueParameter<IntValue> LengthParameter {
    41       get { return lengthParameter; }
    42       set {
    43         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.");
    45         if (lengthParameter == value) return;
    46 
    47         if (lengthParameter != null) Parameters.Remove(lengthParameter);
    48         lengthParameter = value;
    49         Parameters.Add(lengthParameter);
    50         OnLengthParameterChanged();
    51       }
    52     }
    53 
    54     [Storable]
    55     private IValueParameter<IntMatrix> boundsParameter;
    56     public IValueParameter<IntMatrix> BoundsParameter {
    57       get { return boundsParameter; }
    58       set {
    59         if (value == null) throw new ArgumentNullException("Bounds parameter must not be null.");
    60         if (boundsParameter == value) return;
    61 
    62         if (boundsParameter != null) Parameters.Remove(boundsParameter);
    63         boundsParameter = value;
    64         Parameters.Add(boundsParameter);
    65         OnBoundsParameterChanged();
    66       }
    67     }
    68     #endregion
    69 
    70     public int Length {
    71       get { return LengthParameter.Value.Value; }
    72       set { LengthParameter.Value.Value = value; }
    73     }
     36  public sealed class IntegerVectorEncoding : VectorEncoding<IntegerVector> {
     37    [Storable] public IValueParameter<IntMatrix> BoundsParameter { get; private set; }
     38
    7439    public IntMatrix Bounds {
    7540      get { return BoundsParameter.Value; }
    76       set { BoundsParameter.Value = value; }
     41      set {
     42        if (value == null) throw new ArgumentNullException("Bounds must not be null.");
     43        if (Bounds == value) return;
     44        BoundsParameter.Value = value;
     45      }
    7746    }
    7847
     
    8150    [StorableHook(HookType.AfterDeserialization)]
    8251    private void AfterDeserialization() {
    83       RegisterParameterEvents();
    8452      DiscoverOperators();
     53      RegisterEventHandlers();
    8554    }
    8655
    8756    private IntegerVectorEncoding(IntegerVectorEncoding original, Cloner cloner)
    8857      : base(original, cloner) {
    89       lengthParameter = cloner.Clone(original.lengthParameter);
    90       boundsParameter = cloner.Clone(original.boundsParameter);
    91       RegisterParameterEvents();
     58      BoundsParameter = cloner.Clone(original.BoundsParameter);
     59      RegisterEventHandlers();
    9260    }
    9361    public override IDeepCloneable Clone(Cloner cloner) { return new IntegerVectorEncoding(this, cloner); }
     
    9866    public IntegerVectorEncoding(int length) : this("integerVector", length) { }
    9967    public IntegerVectorEncoding(string name, int length, int min = int.MinValue, int max = int.MaxValue, int? step = null)
    100       : base(name) {
     68      : base(name, length) {
    10169      if (min >= max) throw new ArgumentException("min must be less than max", "min");
    10270      if (step.HasValue && step.Value <= 0) throw new ArgumentException("step must be greater than zero or null", "step");
     
    10775      if (step.HasValue) bounds[0, 2] = step.Value;
    10876
    109       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    110       boundsParameter = new ValueParameter<IntMatrix>(Name + ".Bounds", bounds);
    111       Parameters.Add(lengthParameter);
    112       Parameters.Add(boundsParameter);
     77      BoundsParameter = new ValueParameter<IntMatrix>(Name + ".Bounds", bounds);
     78      Parameters.Add(BoundsParameter);
    11379
    11480      SolutionCreator = new UniformRandomIntegerVectorCreator();
    115       RegisterParameterEvents();
    11681      DiscoverOperators();
     82      RegisterEventHandlers();
    11783    }
    11884    public IntegerVectorEncoding(string name, int length, IList<int> min, IList<int> max, IList<int> step = null)
    119       : base(name) {
     85      : base(name, length) {
    12086      if (min.Count == 0) throw new ArgumentException("Bounds must be given for the integer parameters.");
    12187      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
     
    13096      }
    13197
    132       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    133       boundsParameter = new ValueParameter<IntMatrix>(Name + ".Bounds", bounds);
    134       Parameters.Add(lengthParameter);
    135       Parameters.Add(boundsParameter);
     98      BoundsParameter = new ValueParameter<IntMatrix>(Name + ".Bounds", bounds);
     99      Parameters.Add(BoundsParameter);
    136100
    137101      SolutionCreator = new UniformRandomIntegerVectorCreator();
    138       RegisterParameterEvents();
    139102      DiscoverOperators();
    140     }
    141 
    142     private void OnLengthParameterChanged() {
    143       RegisterLengthParameterEvents();
    144       ConfigureOperators(Operators);
    145     }
    146     private void OnBoundsParameterChanged() {
    147       RegisterBoundsParameterEvents();
    148       ConfigureOperators(Operators);
    149     }
    150 
    151     private void RegisterParameterEvents() {
    152       RegisterLengthParameterEvents();
    153       RegisterBoundsParameterEvents();
    154     }
    155     private void RegisterLengthParameterEvents() {
    156       LengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    157       LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    158     }
    159     private void RegisterBoundsParameterEvents() {
    160       BoundsParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    161       boundsParameter.Value.ToStringChanged += (o, s) => ConfigureOperators(Operators);
     103      RegisterEventHandlers();
     104    }
     105
     106    private void RegisterEventHandlers() {
     107      IntMatrixParameterChangeHandler.Create(BoundsParameter, () => {
     108        ConfigureOperators(Operators);
     109        OnBoundsChanged();
     110      });
    162111    }
    163112
     
    271220    }
    272221    #endregion
     222
     223    protected override void OnLengthChanged() {
     224      ConfigureOperators(Operators);
     225      base.OnLengthChanged();
     226    }
     227
     228    public event EventHandler BoundsChanged;
     229    private void OnBoundsChanged() {
     230      BoundsChanged?.Invoke(this, EventArgs.Empty);
     231    }
    273232  }
    274233}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3837    public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
    3938    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    40     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     39    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
    4140
    4241    public int Dimension {
    4342      get { return DimensionRefParameter.Value.Value; }
    4443      set { DimensionRefParameter.Value.Value = value; }
     44    }
     45
     46    public IntMatrix Bounds {
     47      get { return BoundsRefParameter.Value; }
     48      set { BoundsRefParameter.Value = value; }
    4549    }
    4650
     
    5660      BestResultParameter = cloner.Clone(original.BestResultParameter);
    5761      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     62      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
    5863      RegisterEventHandlers();
    5964    }
     
    6469      Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));
    6570      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
     71      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounds of the integer vector problem.", Encoding.BoundsParameter));
    6672
    6773      Operators.Add(new HammingSimilarityCalculator());
     
    94100
    95101    private void RegisterEventHandlers() {
    96       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    97     }
    98 
    99     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    100       DimensionOnChanged();
     102      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     103      IntMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
    101104    }
    102105
    103106    protected virtual void DimensionOnChanged() { }
     107
     108    protected virtual void BoundsOnChanged() { }
    104109  }
    105110}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3938    public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }
    4039    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    41     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    4240    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
    43     public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter;
    4441
    4542    public int Dimension {
    4643      get { return DimensionRefParameter.Value.Value; }
    47       set { DimensionRefParameter.Value.Value = value; }
     44      protected set { DimensionRefParameter.Value.Value = value; }
    4845    }
    4946
    5047    public IntMatrix Bounds {
    5148      get { return BoundsRefParameter.Value; }
    52       set { BoundsRefParameter.Value = value; }
     49      protected set { BoundsRefParameter.Value = value; }
    5350    }
    5451
     
    103100
    104101    private void RegisterEventHandlers() {
    105       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    106       BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    107     }
    108 
    109     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    110       DimensionOnChanged();
    111     }
    112 
    113     private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
    114       BoundsOnChanged();
     102      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     103      IntMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
    115104    }
    116105
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageEncoding.cs

    r17567 r17587  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    28 using HeuristicLab.Data;
    2928using HeuristicLab.Optimization;
    30 using HeuristicLab.Parameters;
    3129using HeuristicLab.PluginInfrastructure;
    3230
     
    3432  [Item("Linear Linkage Encoding", "Describes a linear linkage (LLE) encoding.")]
    3533  [StorableType("7AE11F39-E6BD-4FC7-8112-0A5EDCBFBDB6")]
    36   public sealed class LinearLinkageEncoding : Encoding<LinearLinkage> {
    37     #region encoding parameters
    38     [Storable]
    39     private IFixedValueParameter<IntValue> lengthParameter;
    40     public IFixedValueParameter<IntValue> LengthParameter {
    41       get { return lengthParameter; }
    42       set {
    43         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.");
    45         if (lengthParameter == value) return;
    46 
    47         if (lengthParameter != null) Parameters.Remove(lengthParameter);
    48         lengthParameter = value;
    49         Parameters.Add(lengthParameter);
    50         OnLengthParameterChanged();
    51       }
    52     }
    53     #endregion
    54 
    55     public int Length {
    56       get { return LengthParameter.Value.Value; }
    57       set { LengthParameter.Value.Value = value; }
    58     }
     34  public sealed class LinearLinkageEncoding : VectorEncoding<LinearLinkage> {
    5935
    6036    [StorableConstructor]
     
    6238    [StorableHook(HookType.AfterDeserialization)]
    6339    private void AfterDeserialization() {
    64       RegisterParameterEvents();
    6540      DiscoverOperators();
    6641    }
    6742
    6843    public override IDeepCloneable Clone(Cloner cloner) { return new LinearLinkageEncoding(this, cloner); }
    69     private LinearLinkageEncoding(LinearLinkageEncoding original, Cloner cloner)
    70       : base(original, cloner) {
    71       lengthParameter = cloner.Clone(original.lengthParameter);
    72       RegisterParameterEvents();
    73     }
    74 
     44    private LinearLinkageEncoding(LinearLinkageEncoding original, Cloner cloner) : base(original, cloner) { }
    7545
    7646    public LinearLinkageEncoding() : this("LLE", 10) { }
     
    7848    public LinearLinkageEncoding(int length) : this("LLE", length) { }
    7949    public LinearLinkageEncoding(string name, int length)
    80       : base(name) {
    81       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    82       Parameters.Add(lengthParameter);
    83 
     50      : base(name, length) {
    8451      SolutionCreator = new RandomLinearLinkageCreator();
    85       RegisterParameterEvents();
    8652      DiscoverOperators();
    87     }
    88 
    89     private void OnLengthParameterChanged() {
    90       RegisterLengthParameterEvents();
    91       ConfigureOperators(Operators);
    92     }
    93 
    94     private void RegisterParameterEvents() {
    95       RegisterLengthParameterEvents();
    96     }
    97     private void RegisterLengthParameterEvents() {
    98       LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    9953    }
    10054
     
    167121    }
    168122    #endregion
    169 
    170123  }
    171124}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageMultiObjectiveProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    9089
    9190    private void RegisterEventHandlers() {
    92       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    93     }
    94 
    95     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    96       DimensionOnChanged();
     91      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
    9792    }
    9893
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3736  public abstract class LinearLinkageProblem : SingleObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
    3837    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    39     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    4038
    4139    public int Dimension {
     
    9088
    9189    private void RegisterEventHandlers() {
    92       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    93     }
    94 
    95     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    96       DimensionOnChanged();
     90      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
    9791    }
    9892
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding.Views/3.3/HeuristicLab.Encodings.PermutationEncoding.Views-3.3.csproj

    r16723 r17587  
    116116  </ItemGroup>
    117117  <ItemGroup>
    118     <Compile Include="PermutationTypeView.cs">
    119       <SubType>UserControl</SubType>
    120     </Compile>
    121     <Compile Include="PermutationTypeView.Designer.cs">
    122       <DependentUpon>PermutationTypeView.cs</DependentUpon>
    123     </Compile>
    124118    <Compile Include="PermutationView.cs">
    125119      <SubType>UserControl</SubType>
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding.Views/3.3/PermutationView.Designer.cs

    r17226 r17587  
    1919 */
    2020#endregion
     21
     22using HeuristicLab.Data.Views;
    2123
    2224namespace HeuristicLab.Encodings.PermutationEncoding.Views {
     
    4547    /// </summary>
    4648    private void InitializeComponent() {
    47       this.permutationTypeView = new HeuristicLab.Encodings.PermutationEncoding.Views.PermutationTypeView();
     49      this.permutationTypeView = new HeuristicLab.Data.Views.EnumValueView<PermutationTypes>();
    4850      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4951      this.SuspendLayout();
     
    8385    #endregion
    8486
    85     private PermutationTypeView permutationTypeView;
     87    private EnumValueView<PermutationTypes> permutationTypeView;
    8688
    8789  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding.Views/3.3/PermutationView.cs

    r17226 r17587  
    5858        permutationTypeView.Content = null;
    5959      } else {
    60         permutationTypeView.Content = new PermutationType(Content.PermutationType);
     60        permutationTypeView.Content = new Data.EnumValue<PermutationTypes>(Content.PermutationType);
    6161        permutationTypeView.Content.ValueChanged += new System.EventHandler(PermutationTypeView_ValueChanged);
    6262      }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Creators/RandomPermutationCreator.cs

    r17226 r17587  
    4848      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
    4949    }
    50     public IValueParameter<PermutationType> PermutationTypeParameter {
    51       get { return (IValueParameter<PermutationType>)Parameters["PermutationType"]; }
     50    public IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter {
     51      get { return (IValueParameter<EnumValue<PermutationTypes>>)Parameters["PermutationType"]; }
    5252    }
    5353
     
    6565      Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the new random permutation."));
    6666      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The new random permutation."));
    67       Parameters.Add(new ValueParameter<PermutationType>("PermutationType", "The type of the permutation.", new PermutationType(PermutationTypes.RelativeUndirected)));
     67      Parameters.Add(new ValueParameter<EnumValue<PermutationTypes>>("PermutationType", "The type of the permutation.", new EnumValue<PermutationTypes>(PermutationTypes.RelativeUndirected)));
    6868    }
    6969
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj

    r16948 r17587  
    207207    <Compile Include="PermutationCrossover.cs" />
    208208    <Compile Include="Permutation.cs" />
    209     <Compile Include="PermutationType.cs" />
    210209    <Compile Include="PermutationTypes.cs" />
    211210    <Compile Include="Plugin.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationCreator.cs

    r17226 r17587  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
    25 using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Encodings.PermutationEncoding {
     
    3232  public interface IPermutationCreator : IPermutationSolutionOperator, ISolutionCreator<Permutation> {
    3333    IValueLookupParameter<IntValue> LengthParameter { get; }
    34     IValueParameter<PermutationType> PermutationTypeParameter { get; }
     34    IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter { get; }
    3535  }
    3636}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEncoding.cs

    r17567 r17587  
    3434  [Item("PermutationEncoding", "Describes a permutation encoding.")]
    3535  [StorableType("E30E7507-44BA-4021-8F56-C3FC5569A6FE")]
    36   public sealed class PermutationEncoding : Encoding<Permutation> {
     36  public sealed class PermutationEncoding : VectorEncoding<Permutation> {
    3737    #region encoding parameters
    38     [Storable]
    39     private IFixedValueParameter<IntValue> lengthParameter;
    40     public IFixedValueParameter<IntValue> LengthParameter {
    41       get { return lengthParameter; }
     38    [Storable] public IValueParameter<EnumValue<PermutationTypes>> PermutationTypeParameter { get; private set; }
     39    public PermutationTypes Type {
     40      get { return PermutationTypeParameter.Value.Value; }
    4241      set {
    43         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.");
    45         if (lengthParameter == value) return;
    46 
    47         if (lengthParameter != null) Parameters.Remove(lengthParameter);
    48         lengthParameter = value;
    49         Parameters.Add(lengthParameter);
    50         OnLengthParameterChanged();
    51       }
    52     }
    53 
    54     [Storable]
    55     private IFixedValueParameter<PermutationType> permutationTypeParameter;
    56     public IFixedValueParameter<PermutationType> PermutationTypeParameter {
    57       get { return permutationTypeParameter; }
    58       set {
    59         if (value == null) throw new ArgumentNullException("Permutation type parameter must not be null.");
    60         if (value.Value == null) throw new ArgumentNullException("Permutation type parameter value must not be null.");
    61         if (permutationTypeParameter == value) return;
    62 
    63         if (permutationTypeParameter != null) Parameters.Remove(permutationTypeParameter);
    64         permutationTypeParameter = value;
    65         Parameters.Add(permutationTypeParameter);
    66         OnPermutationTypeParameterChanged();
     42        if (Type == value) return;
     43        PermutationTypeParameter.Value.Value = value;
    6744      }
    6845    }
    6946    #endregion
    70 
    71     public int Length {
    72       get { return LengthParameter.Value.Value; }
    73       set { LengthParameter.Value.Value = value; }
    74     }
    75 
    76     public PermutationTypes Type {
    77       get { return PermutationTypeParameter.Value.Value; }
    78       set { PermutationTypeParameter.Value.Value = value; }
    79     }
    8047
    8148    [StorableConstructor]
     
    8350    [StorableHook(HookType.AfterDeserialization)]
    8451    private void AfterDeserialization() {
     52      DiscoverOperators();
    8553      RegisterParameterEvents();
    86       DiscoverOperators();
    8754    }
    8855
     
    9057    private PermutationEncoding(PermutationEncoding original, Cloner cloner)
    9158      : base(original, cloner) {
    92       lengthParameter = cloner.Clone(original.lengthParameter);
    93       permutationTypeParameter = cloner.Clone(original.permutationTypeParameter);
     59      PermutationTypeParameter = cloner.Clone(original.PermutationTypeParameter);
    9460      RegisterParameterEvents();
    9561    }
     
    10066    public PermutationEncoding(int length) : this("Permutation", length, PermutationTypes.Absolute) { }
    10167    public PermutationEncoding(string name, int length, PermutationTypes type)
    102       : base(name) {
    103       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    104       permutationTypeParameter = new FixedValueParameter<PermutationType>(Name + ".Type", new PermutationType(type));
    105       Parameters.Add(lengthParameter);
    106       Parameters.Add(permutationTypeParameter);
     68      : base(name, length) {
     69      PermutationTypeParameter = new ValueParameter<EnumValue<PermutationTypes>>(Name + ".Type", new EnumValue<PermutationTypes>(type));
     70      Parameters.Add(PermutationTypeParameter);
    10771
    10872      SolutionCreator = new RandomPermutationCreator();
     73      DiscoverOperators();
    10974      RegisterParameterEvents();
    110       DiscoverOperators();
    111     }
    112 
    113     private void OnLengthParameterChanged() {
    114       RegisterLengthParameterEvents();
    115       ConfigureOperators(Operators);
    116     }
    117 
    118     private void OnPermutationTypeParameterChanged() {
    119       RegisterPermutationTypeParameterEvents();
    120       ConfigureOperators(Operators);
    12175    }
    12276
    12377    private void RegisterParameterEvents() {
    124       RegisterLengthParameterEvents();
    125       RegisterPermutationTypeParameterEvents();
    126     }
    127     private void RegisterLengthParameterEvents() {
    128       LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    129     }
    130     private void RegisterPermutationTypeParameterEvents() {
    131       PermutationTypeParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
     78      EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeParameter, () => {
     79        ConfigureOperators(Operators);
     80        OnTypeChanged();
     81      });
    13282    }
    13383
     
    239189    }
    240190    #endregion
     191
     192    public event EventHandler TypeChanged;
     193    private void OnTypeChanged() {
     194      TypeChanged?.Invoke(this, EventArgs.Empty);
     195    }
    241196  }
    242197}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3635  public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem<PermutationEncoding, Permutation> {
    3736    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    38     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     37    [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; }
    3938
    4039    public int Dimension {
    4140      get { return DimensionRefParameter.Value.Value; }
    4241      set { DimensionRefParameter.Value.Value = value; }
     42    }
     43
     44    public PermutationTypes Type {
     45      get { return PermutationTypeRefParameter.Value.Value; }
     46      set { PermutationTypeRefParameter.Value.Value = value; }
    4347    }
    4448
     
    5357      : base(original, cloner) {
    5458      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     59      PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter);
    5560      RegisterEventHandlers();
    5661    }
     
    6065      EncodingParameter.ReadOnly = true;
    6166      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
     67      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
    6268
    6369      Operators.Add(new HammingSimilarityCalculator());
     
    8995
    9096    private void RegisterEventHandlers() {
    91       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    92     }
    93 
    94     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    95       DimensionOnChanged();
     97      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     98      EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeRefParameter, TypeOnChanged);
    9699    }
    97100
    98101    protected virtual void DimensionOnChanged() { }
     102
     103    protected virtual void TypeOnChanged() { }
    99104  }
    100105}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3736  public abstract class PermutationProblem : SingleObjectiveProblem<PermutationEncoding, Permutation> {
    3837    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    39     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     38    [Storable] protected ReferenceParameter<EnumValue<PermutationTypes>> PermutationTypeRefParameter { get; private set; }
    4039
    4140    public int Dimension {
    4241      get { return DimensionRefParameter.Value.Value; }
    4342      set { DimensionRefParameter.Value.Value = value; }
     43    }
     44
     45    public PermutationTypes Type {
     46      get { return PermutationTypeRefParameter.Value.Value; }
     47      set { PermutationTypeRefParameter.Value.Value = value; }
    4448    }
    4549
     
    5458      : base(original, cloner) {
    5559      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     60      PermutationTypeRefParameter = cloner.Clone(original.PermutationTypeRefParameter);
    5661      RegisterEventHandlers();
    5762    }
     
    6166      EncodingParameter.ReadOnly = true;
    6267      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    63 
     68      Parameters.Add(PermutationTypeRefParameter = new ReferenceParameter<EnumValue<PermutationTypes>>("Type", "The type of the permutation.", Encoding.PermutationTypeParameter));
    6469      Operators.Add(new HammingSimilarityCalculator());
    6570      Operators.Add(new QualitySimilarityCalculator());
     
    8994
    9095    private void RegisterEventHandlers() {
    91       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    92     }
    93 
    94     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    95       DimensionOnChanged();
     96      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     97      EnumValueParameterChangeHandler<PermutationTypes>.Create(PermutationTypeRefParameter, TypeOnChanged);
    9698    }
    9799
    98100    protected virtual void DimensionOnChanged() { }
     101
     102    protected virtual void TypeOnChanged() { }
    99103  }
    100104}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEncoding.cs

    r17571 r17587  
    3434  [Item("RealVectorEncoding", "Describes a real vector encoding.")]
    3535  [StorableType("155FFE02-931F-457D-AC95-A0389B0BFECD")]
    36   public sealed class RealVectorEncoding : Encoding<RealVector> {
    37     #region Encoding Parameters
    38     [Storable]
    39     private IFixedValueParameter<IntValue> lengthParameter;
    40     public IFixedValueParameter<IntValue> LengthParameter {
    41       get { return lengthParameter; }
    42       set {
    43         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.");
    45         if (lengthParameter == value) return;
    46 
    47         if (lengthParameter != null) Parameters.Remove(lengthParameter);
    48         lengthParameter = value;
    49         Parameters.Add(lengthParameter);
    50         OnLengthParameterChanged();
    51       }
    52     }
    53     [Storable]
    54     private IValueParameter<DoubleMatrix> boundsParameter;
    55     public IValueParameter<DoubleMatrix> BoundsParameter {
    56       get { return boundsParameter; }
     36  public sealed class RealVectorEncoding : VectorEncoding<RealVector> {
     37    [Storable] public IValueParameter<DoubleMatrix> BoundsParameter { get; private set; }
     38
     39    public DoubleMatrix Bounds {
     40      get { return BoundsParameter.Value; }
    5741      set {
    5842        if (value == null) throw new ArgumentNullException("Bounds parameter must not be null.");
    59         if (boundsParameter == value) return;
    60 
    61         if (boundsParameter != null) Parameters.Remove(boundsParameter);
    62         boundsParameter = value;
    63         Parameters.Add(boundsParameter);
    64         OnBoundsParameterChanged();
    65       }
    66     }
    67     #endregion
    68 
    69     public int Length {
    70       get { return LengthParameter.Value.Value; }
    71       set { LengthParameter.Value.Value = value; }
    72     }
    73     public DoubleMatrix Bounds {
    74       get { return BoundsParameter.Value; }
    75       set { BoundsParameter.Value = value; }
     43        if (Bounds == value) return;
     44        BoundsParameter.Value = value;
     45      }
    7646    }
    7747
     
    8050    [StorableHook(HookType.AfterDeserialization)]
    8151    private void AfterDeserialization() {
    82       RegisterParameterEvents();
    8352      DiscoverOperators();
     53      RegisterParameterEvents();
    8454    }
    8555
     
    8757    private RealVectorEncoding(RealVectorEncoding original, Cloner cloner)
    8858      : base(original, cloner) {
    89       lengthParameter = cloner.Clone(original.lengthParameter);
    90       boundsParameter = cloner.Clone(original.boundsParameter);
     59      BoundsParameter = cloner.Clone(original.BoundsParameter);
    9160      RegisterParameterEvents();
    9261    }
     
    9665    public RealVectorEncoding(int length) : this("RealVector", length) { }
    9766    public RealVectorEncoding(string name, int length, double min = -1000, double max = 1000)
    98       : base(name) {
     67      : base(name, length) {
    9968      if (min >= max) throw new ArgumentException("min must be less than max", "min");
    10069
     
    10372      bounds[0, 1] = max;
    10473
    105       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length)) { ReadOnly = true };
    106       boundsParameter = new ValueParameter<DoubleMatrix>(Name + ".Bounds", bounds) { ReadOnly = true };
    107       Parameters.Add(lengthParameter);
    108       Parameters.Add(boundsParameter);
     74      BoundsParameter = new ValueParameter<DoubleMatrix>(Name + ".Bounds", bounds);
     75      Parameters.Add(BoundsParameter);
    10976
    11077      SolutionCreator = new UniformRandomRealVectorCreator();
     
    11481
    11582    public RealVectorEncoding(string name, int length, IList<double> min, IList<double> max)
    116       : base(name) {
     83      : base(name, length) {
    11784      if (min.Count == 0) throw new ArgumentException("Bounds must be given for the real parameters.");
    11885      if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min");
     
    12491        bounds[i, 1] = max[i];
    12592      }
    126       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    127       boundsParameter = new ValueParameter<DoubleMatrix>(Name + ".Bounds", bounds);
    128       Parameters.Add(lengthParameter);
    129       Parameters.Add(boundsParameter);
     93      BoundsParameter = new ValueParameter<DoubleMatrix>(Name + ".Bounds", bounds);
     94      Parameters.Add(BoundsParameter);
    13095
    13196      SolutionCreator = new UniformRandomRealVectorCreator();
    132       RegisterParameterEvents();
    13397      DiscoverOperators();
    134     }
    135 
    136     private void OnLengthParameterChanged() {
    137       RegisterLengthParameterEvents();
    138       ConfigureOperators(Operators);
    139     }
    140     private void OnBoundsParameterChanged() {
    141       RegisterBoundsParameterEvents();
    142       ConfigureOperators(Operators);
     98      RegisterParameterEvents();
    14399    }
    144100
    145101    private void RegisterParameterEvents() {
    146       RegisterLengthParameterEvents();
    147       RegisterBoundsParameterEvents();
    148     }
    149     private void RegisterLengthParameterEvents() {
    150       LengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    151       LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
    152     }
    153     private void RegisterBoundsParameterEvents() {
    154       BoundsParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    155       boundsParameter.Value.ToStringChanged += (o, s) => ConfigureOperators(Operators);
     102      DoubleMatrixParameterChangeHandler.Create(BoundsParameter, () => {
     103        ConfigureOperators(Operators);
     104        OnBoundsChanged();
     105      });
    156106    }
    157107
     
    316266    }
    317267    #endregion
     268
     269    protected override void OnLengthChanged() {
     270      ConfigureOperators(Operators);
     271      base.OnLengthChanged();
     272    }
     273
     274    public event EventHandler BoundsChanged;
     275    private void OnBoundsChanged() {
     276      BoundsChanged?.Invoke(this, EventArgs.Empty);
     277    }
    318278  }
    319279}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorMultiObjectiveProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3635  public abstract class RealVectorMultiObjectiveProblem : MultiObjectiveProblem<RealVectorEncoding, RealVector> {
    3736    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    38     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    3937    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
    40     public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
    4138
    4239    public int Dimension {
     
    4744    public DoubleMatrix Bounds {
    4845      get { return BoundsRefParameter.Value; }
    49       set { BoundsParameter.Value = value; }
     46      set { BoundsRefParameter.Value = value; }
    5047    }
    5148
     
    9996
    10097    private void RegisterEventHandlers() {
    101       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    102       BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    103     }
    104 
    105     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    106       DimensionOnChanged();
    107     }
    108 
    109     private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
    110       BoundsOnChanged();
     98      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     99      DoubleMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
    111100    }
    112101
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs

    r17544 r17587  
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HEAL.Attic;
     
    3736  public abstract class RealVectorProblem : SingleObjectiveProblem<RealVectorEncoding, RealVector> {
    3837    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    39     public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    4038    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
    41     public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
    4239
    4340    public int Dimension {
     
    4845    public DoubleMatrix Bounds {
    4946      get { return BoundsRefParameter.Value; }
    50       set { BoundsParameter.Value = value; }
     47      set { BoundsRefParameter.Value = value; }
    5148    }
    5249
     
    9996
    10097    private void RegisterEventHandlers() {
    101       DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    102       BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    103     }
    104 
    105     private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
    106       DimensionOnChanged();
    107     }
    108 
    109     private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
    110       BoundsOnChanged();
     98      IntValueParameterChangeHandler.Create(DimensionRefParameter, DimensionOnChanged);
     99      DoubleMatrixParameterChangeHandler.Create(BoundsRefParameter, BoundsOnChanged);
    111100    }
    112101
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r17577 r17587  
    160160    <Compile Include="BasicProblems\SingleObjectiveProblem.cs" />
    161161    <Compile Include="BasicProblems\SolutionContext.cs" />
     162    <Compile Include="BasicProblems\VectorEncoding.cs" />
    162163    <Compile Include="Interfaces\ICharacteristicCalculator.cs" />
    163164    <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ParameterChangeHandler.cs

    r17546 r17587  
    3939  }
    4040
    41   public class ParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem>
     41  public class ValueTypeValueParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem>
    4242    where TValue : struct
    4343    where TItem : ValueTypeValue<TValue> {
    4444    private ValueTypeValue<TValue> last;
    4545
    46     protected ParameterChangeHandler(IValueParameter<TItem> parameter, Action handler)
     46    protected ValueTypeValueParameterChangeHandler(IValueParameter<TItem> parameter, Action handler)
    4747      : base(parameter, handler) {
    4848      last = parameter.Value;
     
    6363    }
    6464
    65     public static ParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler)
    66       => new ParameterChangeHandler<TItem, TValue>(parameter, handler);
    67   }
    68 
    69   public class BoolValueParameterChangeHandler : ParameterChangeHandler<BoolValue, bool> {
     65    public static ValueTypeValueParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler)
     66      => new ValueTypeValueParameterChangeHandler<TItem, TValue>(parameter, handler);
     67  }
     68  public class ValueTypeArrayParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem>
     69    where TValue : struct
     70    where TItem : ValueTypeArray<TValue> {
     71    private ValueTypeArray<TValue> last;
     72
     73    protected ValueTypeArrayParameterChangeHandler(IValueParameter<TItem> parameter, Action handler)
     74      : base(parameter, handler) {
     75      last = parameter.Value;
     76      if (last != null && !last.ReadOnly)
     77        last.ToStringChanged += ParameterValueOnValueChanged;
     78    }
     79
     80    protected override void ParameterOnValueChanged(object sender, EventArgs e) {
     81      if (last != null) last.ToStringChanged -= ParameterValueOnValueChanged;
     82      last = ((IValueParameter<TItem>)sender).Value;
     83      if (last != null && !last.ReadOnly)
     84        last.ToStringChanged += ParameterValueOnValueChanged;
     85      base.ParameterOnValueChanged(sender, e);
     86    }
     87
     88    protected void ParameterValueOnValueChanged(object sender, EventArgs e) {
     89      handler();
     90    }
     91
     92    public static ValueTypeArrayParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler)
     93      => new ValueTypeArrayParameterChangeHandler<TItem, TValue>(parameter, handler);
     94  }
     95
     96  public class ValueTypeMatrixParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem>
     97    where TValue : struct
     98    where TItem : ValueTypeMatrix<TValue> {
     99    private ValueTypeMatrix<TValue> last;
     100
     101    protected ValueTypeMatrixParameterChangeHandler(IValueParameter<TItem> parameter, Action handler)
     102      : base(parameter, handler) {
     103      last = parameter.Value;
     104      if (last != null && !last.ReadOnly)
     105        last.ToStringChanged += ParameterValueOnValueChanged;
     106    }
     107
     108    protected override void ParameterOnValueChanged(object sender, EventArgs e) {
     109      if (last != null) last.ToStringChanged -= ParameterValueOnValueChanged;
     110      last = ((IValueParameter<TItem>)sender).Value;
     111      if (last != null && !last.ReadOnly)
     112        last.ToStringChanged += ParameterValueOnValueChanged;
     113      base.ParameterOnValueChanged(sender, e);
     114    }
     115
     116    protected void ParameterValueOnValueChanged(object sender, EventArgs e) {
     117      handler();
     118    }
     119
     120    public static ValueTypeMatrixParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler)
     121      => new ValueTypeMatrixParameterChangeHandler<TItem, TValue>(parameter, handler);
     122  }
     123
     124  public class BoolValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<BoolValue, bool> {
    70125    private BoolValueParameterChangeHandler(IValueParameter<BoolValue> parameter, Action handler) : base(parameter, handler) { }
    71126    public static new BoolValueParameterChangeHandler Create(IValueParameter<BoolValue> parameter, Action handler)
    72127      => new BoolValueParameterChangeHandler(parameter, handler);
    73128  }
    74   public class IntValueParameterChangeHandler : ParameterChangeHandler<IntValue, int> {
     129  public class IntValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<IntValue, int> {
    75130    private IntValueParameterChangeHandler(IValueParameter<IntValue> parameter, Action handler) : base(parameter, handler) { }
    76131    public static new IntValueParameterChangeHandler Create(IValueParameter<IntValue> parameter, Action handler)
    77132      => new IntValueParameterChangeHandler(parameter, handler);
    78133  }
    79   public class DoubleValueParameterChangeHandler : ParameterChangeHandler<DoubleValue, double> {
     134  public class DoubleValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<DoubleValue, double> {
    80135    private DoubleValueParameterChangeHandler(IValueParameter<DoubleValue> parameter, Action handler) : base(parameter, handler) { }
    81136    public static new DoubleValueParameterChangeHandler Create(IValueParameter<DoubleValue> parameter, Action handler)
    82137      => new DoubleValueParameterChangeHandler(parameter, handler);
    83138  }
    84   public class PercentValueParameterChangeHandler : ParameterChangeHandler<PercentValue, double> {
     139  public class PercentValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<PercentValue, double> {
    85140    private PercentValueParameterChangeHandler(IValueParameter<PercentValue> parameter, Action handler) : base(parameter, handler) { }
    86141    public static new PercentValueParameterChangeHandler Create(IValueParameter<PercentValue> parameter, Action handler)
    87142      => new PercentValueParameterChangeHandler(parameter, handler);
    88143  }
    89   public class DateTimeValueParameterChangeHandler : ParameterChangeHandler<DateTimeValue, DateTime> {
     144  public class DateTimeValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<DateTimeValue, DateTime> {
    90145    private DateTimeValueParameterChangeHandler(IValueParameter<DateTimeValue> parameter, Action handler) : base(parameter, handler) { }
    91146    public static new DateTimeValueParameterChangeHandler Create(IValueParameter<DateTimeValue> parameter, Action handler)
    92147      => new DateTimeValueParameterChangeHandler(parameter, handler);
    93148  }
    94   public class TimeSpanValueParameterChangeHandler : ParameterChangeHandler<TimeSpanValue, TimeSpan> {
     149  public class TimeSpanValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<TimeSpanValue, TimeSpan> {
    95150    private TimeSpanValueParameterChangeHandler(IValueParameter<TimeSpanValue> parameter, Action handler) : base(parameter, handler) { }
    96151    public static new TimeSpanValueParameterChangeHandler Create(IValueParameter<TimeSpanValue> parameter, Action handler)
    97152      => new TimeSpanValueParameterChangeHandler(parameter, handler);
    98153  }
    99   public class EnumValueParameterChangeHandler<TEnum> : ParameterChangeHandler<EnumValue<TEnum>, TEnum> where TEnum : struct, IComparable {
     154  public class EnumValueParameterChangeHandler<TEnum> : ValueTypeValueParameterChangeHandler<EnumValue<TEnum>, TEnum> where TEnum : struct, IComparable {
    100155    private EnumValueParameterChangeHandler(IValueParameter<EnumValue<TEnum>> parameter, Action handler) : base(parameter, handler) { }
    101156    public static new EnumValueParameterChangeHandler<TEnum> Create(IValueParameter<EnumValue<TEnum>> parameter, Action handler)
    102157      => new EnumValueParameterChangeHandler<TEnum>(parameter, handler);
    103158  }
     159  public class BoolArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<BoolArray, bool> {
     160    private BoolArrayParameterChangeHandler(IValueParameter<BoolArray> parameter, Action handler) : base(parameter, handler) { }
     161    public static new BoolArrayParameterChangeHandler Create(IValueParameter<BoolArray> parameter, Action handler)
     162      => new BoolArrayParameterChangeHandler(parameter, handler);
     163  }
     164  public class IntArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<IntArray, int> {
     165    private IntArrayParameterChangeHandler(IValueParameter<IntArray> parameter, Action handler) : base(parameter, handler) { }
     166    public static new IntArrayParameterChangeHandler Create(IValueParameter<IntArray> parameter, Action handler)
     167      => new IntArrayParameterChangeHandler(parameter, handler);
     168  }
     169  public class DoubleArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<DoubleArray, double> {
     170    private DoubleArrayParameterChangeHandler(IValueParameter<DoubleArray> parameter, Action handler) : base(parameter, handler) { }
     171    public static new DoubleArrayParameterChangeHandler Create(IValueParameter<DoubleArray> parameter, Action handler)
     172      => new DoubleArrayParameterChangeHandler(parameter, handler);
     173  }
     174  public class BoolMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<BoolMatrix, bool> {
     175    private BoolMatrixParameterChangeHandler(IValueParameter<BoolMatrix> parameter, Action handler) : base(parameter, handler) { }
     176    public static new BoolMatrixParameterChangeHandler Create(IValueParameter<BoolMatrix> parameter, Action handler)
     177      => new BoolMatrixParameterChangeHandler(parameter, handler);
     178  }
     179  public class IntMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<IntMatrix, int> {
     180    private IntMatrixParameterChangeHandler(IValueParameter<IntMatrix> parameter, Action handler) : base(parameter, handler) { }
     181    public static new IntMatrixParameterChangeHandler Create(IValueParameter<IntMatrix> parameter, Action handler)
     182      => new IntMatrixParameterChangeHandler(parameter, handler);
     183  }
     184  public class DoubleMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<DoubleMatrix, double> {
     185    private DoubleMatrixParameterChangeHandler(IValueParameter<DoubleMatrix> parameter, Action handler) : base(parameter, handler) { }
     186    public static new DoubleMatrixParameterChangeHandler Create(IValueParameter<DoubleMatrix> parameter, Action handler)
     187      => new DoubleMatrixParameterChangeHandler(parameter, handler);
     188  }
    104189  public class StringValueParameterChangeHandler : ParameterChangeHandler<StringValue> { // StringValue does not derive from ValueTypeValue
    105190    private StringValue last;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

    r17544 r17587  
    124124      Parameters.Add(new FixedValueParameter<DoubleArray>(ReferencePointParameterName, "The reference point for hypervolume calculations on this problem", new DoubleArray(TestFunction.ReferencePoint(Objectives))));
    125125
    126       BoundsParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives));
     126      BoundsRefParameter.Value = new DoubleMatrix(TestFunction.Bounds(Objectives));
    127127    }
    128128
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17571 r17587  
    7070
    7171      BestKnownQuality = TestFunction.BestKnownQuality;
    72 
     72      Bounds = (DoubleMatrix)TestFunction.Bounds.Clone();
     73      Dimension = TestFunction.MinimumProblemSize;
     74      BestKnownSolutionParameter.Value = TestFunction.GetBestKnownSolution(Dimension);
    7375      InitializeOperators();
    7476      RegisterEventHandlers();
     
    118120                                                           TestFunctionParameter.Value) {
    119121          BestKnownRealVector = bestKnownSolution,
    120           Bounds = BoundsParameter.Value
     122          Bounds = BoundsRefParameter.Value
    121123        };
    122124        results.Add(new Result("Best Solution", solution));
     
    200202        op.RealVectorParameter.ActualName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName;
    201203        op.RealVectorParameter.Hidden = true;
    202         op.BoundsParameter.ActualName = BoundsParameter.Name;
     204        op.BoundsParameter.ActualName = BoundsRefParameter.Name;
    203205        op.BoundsParameter.Hidden = true;
    204206      }
     
    207209        op.RealVectorParameter.ActualName = ((IRealVectorSolutionOperator)Encoding.SolutionCreator).RealVectorParameter.ActualName;
    208210        op.RealVectorParameter.Hidden = true;
    209         op.BoundsParameter.ActualName = BoundsParameter.Name;
     211        op.BoundsParameter.ActualName = BoundsRefParameter.Name;
    210212        op.BoundsParameter.Hidden = true;
    211213      }
Note: See TracChangeset for help on using the changeset viewer.