Changeset 17544


Ignore:
Timestamp:
05/18/20 18:55:08 (2 weeks ago)
Author:
abeham
Message:

#2521: worked on refactoring, worked a lot on binary encoding / problems

Location:
branches/2521_ProblemRefactoring
Files:
30 edited

Legend:

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

    r17226 r17544  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Linq;
     26using HEAL.Attic;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
     
    2830using HeuristicLab.Optimization;
    2931using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    3132using HeuristicLab.PluginInfrastructure;
    3233
     
    3435  [Item("BinaryVectorEncoding", "Describes a binary vector encoding.")]
    3536  [StorableType("889C5E1A-3FBF-4AB3-AB2E-199A781503B5")]
    36   public sealed class BinaryVectorEncoding : Encoding<BinaryVector> {
     37  public sealed class BinaryVectorEncoding : Encoding<BinaryVector>, INotifyPropertyChanged {
    3738    #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     }
     39    [Storable] public IValueParameter<IntValue> LengthParameter { get; private set; }
    5340    #endregion
    5441
    5542    public int Length {
    5643      get { return LengthParameter.Value.Value; }
    57       set { LengthParameter.Value.Value = value; }
     44      set {
     45        if (Length == value) return;
     46        LengthParameter.ForceValue(new IntValue(value, @readonly: LengthParameter.Value.ReadOnly));
     47      }
    5848    }
    5949
     
    6252    [StorableHook(HookType.AfterDeserialization)]
    6353    private void AfterDeserialization() {
    64       RegisterParameterEvents();
    6554      DiscoverOperators();
     55      RegisterEventHandlers();
    6656    }
    6757    public override IDeepCloneable Clone(Cloner cloner) { return new BinaryVectorEncoding(this, cloner); }
    6858    private BinaryVectorEncoding(BinaryVectorEncoding original, Cloner cloner)
    6959      : base(original, cloner) {
    70       lengthParameter = cloner.Clone(original.lengthParameter);
    71       RegisterParameterEvents();
     60      LengthParameter = cloner.Clone(original.LengthParameter);
     61      RegisterEventHandlers();
    7262    }
    7363
     
    7767    public BinaryVectorEncoding(string name, int length)
    7868      : base(name) {
    79       lengthParameter = new FixedValueParameter<IntValue>(Name + ".Length", new IntValue(length));
    80       Parameters.Add(lengthParameter);
     69      Parameters.Add(LengthParameter = new ValueParameter<IntValue>(Name + ".Length", new IntValue(length, @readonly: true)) { ReadOnly = true });
     70     
     71      SolutionCreator = new RandomBinaryVectorCreator();
     72      DiscoverOperators();
    8173
    82       SolutionCreator = new RandomBinaryVectorCreator();
    83       RegisterParameterEvents();
    84       DiscoverOperators();
     74      RegisterEventHandlers();
    8575    }
    8676
    87     private void OnLengthParameterChanged() {
    88       RegisterLengthParameterEvents();
    89       ConfigureOperators(Operators);
    90     }
    91     private void RegisterParameterEvents() {
    92       RegisterLengthParameterEvents();
    93     }
    94     private void RegisterLengthParameterEvents() {
    95       LengthParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);
    96       LengthParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);
     77    private void RegisterEventHandlers() {
     78      LengthParameter.ValueChanged += (_, __) => {
     79        if (!LengthParameter.Value.ReadOnly) LengthParameter.Value.ValueChanged += (___, ____) => OnPropertyChanged(nameof(Length));
     80        OnPropertyChanged(nameof(Length));
     81      };
    9782    }
    9883
    9984    #region Operator Discovery
    10085    private static readonly IEnumerable<Type> encodingSpecificOperatorTypes;
     86
    10187    static BinaryVectorEncoding() {
    10288      encodingSpecificOperatorTypes = new List<Type>() {
     
    169155    }
    170156    #endregion
     157
     158    public event PropertyChangedEventHandler PropertyChanged;
     159    private void OnPropertyChanged(string property) {
     160      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
     161    }
    171162  }
    172163}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs

    r17522 r17544  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2829using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    2931
    3032namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     
    3335    [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }
    3436    public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; } }
     37    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     38    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    3539
    36     public int Length {
    37       get { return Encoding.Length; }
    38       set { Encoding.Length = value; }
     40    public int Dimension {
     41      get { return DimensionRefParameter.Value.Value; }
     42      set { DimensionRefParameter.Value.Value = value; }
    3943    }
    4044
     
    4953      : base(original, cloner) {
    5054      BestResultParameter = cloner.Clone(original.BestResultParameter);
     55      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5156      RegisterEventHandlers();
    5257    }
     
    5661      EncodingParameter.ReadOnly = true;
    5762      Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<BinaryVector>>("Best Pareto Front", "The best Pareto front found."));
     63      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
    5864
    5965      Operators.Add(new HammingSimilarityCalculator());
     
    8692
    8793    private void RegisterEventHandlers() {
    88       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     94      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    8995    }
    9096
    91     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     97    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     98      DimensionOnChanged();
     99    }
     100
     101    protected virtual void DimensionOnChanged() { }
    92102  }
    93103}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r17522 r17544  
    2121#endregion
    2222
    23 using System;
    2423using System.Linq;
    2524using HEAL.Attic;
     
    2726using HeuristicLab.Common;
    2827using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2929using HeuristicLab.Optimization;
    3030using HeuristicLab.Optimization.Operators;
     31using HeuristicLab.Parameters;
    3132
    3233namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     
    3435  public abstract class BinaryVectorProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    3536    [Storable] protected IResultParameter<ISingleObjectiveSolutionContext<BinaryVector>> BestResultParameter { get; private set; }
    36     public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult { get { return BestResultParameter; } }
     37    public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult => BestResultParameter;
     38    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3739
    38     public int Length {
     40    public int Dimension {
    3941      get { return Encoding.Length; }
    4042      set { Encoding.Length = value; }
     
    5153      : base(original, cloner) {
    5254      BestResultParameter = cloner.Clone(original.BestResultParameter);
     55      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5356      RegisterEventHandlers();
    5457    }
     
    5861      EncodingParameter.ReadOnly = true;
    5962      Parameters.Add(BestResultParameter = new ResultParameter<ISingleObjectiveSolutionContext<BinaryVector>>("Best Solution", "The best solution."));
     63      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the binary vector problem.", Encoding.LengthParameter));
    6064
    6165      Operators.Add(new HammingSimilarityCalculator());
     
    7478    }
    7579
    76     protected override void OnEncodingChanged() {
    77       base.OnEncodingChanged();
    78       Parameterize();
    79     }
    80 
    8180    private void Parameterize() {
    8281      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
     
    8786
    8887    private void RegisterEventHandlers() {
    89       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     88      Encoding.PropertyChanged += (sender, args) => {
     89        if (args.PropertyName == nameof(Encoding.Length))
     90          DimensionOnChanged();
     91      };
    9092    }
    9193
    92     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     94    protected virtual void DimensionOnChanged() { }
    9395  }
    9496}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs

    r17522 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
     32using HeuristicLab.Parameters;
    3133
    3234namespace HeuristicLab.Encodings.IntegerVectorEncoding {
     
    3537    [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
    3638    public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
     39    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     40    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    3741
    38     public int Length {
    39       get { return Encoding.Length; }
    40       set { Encoding.Length = value; }
     42    public int Dimension {
     43      get { return DimensionRefParameter.Value.Value; }
     44      set { DimensionRefParameter.Value.Value = value; }
    4145    }
    4246
     
    5155      : base(original, cloner) {
    5256      BestResultParameter = cloner.Clone(original.BestResultParameter);
     57      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5358      RegisterEventHandlers();
    5459    }
     
    5863      EncodingParameter.ReadOnly = true;
    5964      Parameters.Add(BestResultParameter = new ResultParameter<ParetoFrontScatterPlot<IntegerVector>>("Best Pareto Front", "The best Pareto front found."));
     65      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
    6066
    6167      Operators.Add(new HammingSimilarityCalculator());
     
    8894
    8995    private void RegisterEventHandlers() {
    90       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     96      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    9197    }
    9298
    93     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     99    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     100      DimensionOnChanged();
     101    }
     102
     103    protected virtual void DimensionOnChanged() { }
    94104  }
    95105}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17522 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Optimization.Operators;
     33using HeuristicLab.Parameters;
    3234
    3335namespace HeuristicLab.Encodings.IntegerVectorEncoding {
     
    3638    [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; }
    3739    public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }
     40    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     41    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     42    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
     43    public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter;
    3844
    39     public int Length {
    40       get { return Encoding.Length; }
    41       set { Encoding.Length = value; }
     45    public int Dimension {
     46      get { return DimensionRefParameter.Value.Value; }
     47      set { DimensionRefParameter.Value.Value = value; }
     48    }
     49
     50    public IntMatrix Bounds {
     51      get { return BoundsRefParameter.Value; }
     52      set { BoundsRefParameter.Value = value; }
    4253    }
    4354
     
    5263      : base(original, cloner) {
    5364      BestResultParameter = cloner.Clone(original.BestResultParameter);
     65      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     66      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
    5467      RegisterEventHandlers();
    5568    }
     
    5972      EncodingParameter.ReadOnly = true;
    6073      Parameters.Add(BestResultParameter = new ResultParameter<IntegerVector>("Best Solution", "The best solution."));
     74      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the integer vector problem.", Encoding.LengthParameter));
     75      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounding box and step sizes of the values.", Encoding.BoundsParameter));
    6176
    6277      Operators.Add(new HammingSimilarityCalculator());
     
    88103
    89104    private void RegisterEventHandlers() {
    90       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     105      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
     106      BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    91107    }
    92108
    93     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     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();
     115    }
     116
     117    protected virtual void DimensionOnChanged() { }
     118
     119    protected virtual void BoundsOnChanged() { }
    94120  }
    95121}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageMultiObjectiveProblem.cs

    r17230 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
     32using HeuristicLab.Parameters;
    3133
    3234namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    3335  [StorableType("ad8b6097-a26b-440c-bfd4-92e5ecf17894")]
    3436  public abstract class LinearLinkageMultiObjectiveProblem : MultiObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
    35     public int Length {
    36       get { return Encoding.Length; }
    37       set { Encoding.Length = value; }
     37    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     38    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     39
     40    public int Dimension {
     41      get { return DimensionRefParameter.Value.Value; }
     42      set { DimensionRefParameter.Value.Value = value; }
    3843    }
    3944
     
    4752    protected LinearLinkageMultiObjectiveProblem(LinearLinkageMultiObjectiveProblem original, Cloner cloner)
    4853      : base(original, cloner) {
     54      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    4955      RegisterEventHandlers();
    5056    }
     
    5359    protected LinearLinkageMultiObjectiveProblem(LinearLinkageEncoding encoding) : base(new LinearLinkageEncoding()) {
    5460      EncodingParameter.ReadOnly = true;
     61      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter));
     62
    5563
    5664      Operators.Add(new HammingSimilarityCalculator());
     
    8290
    8391    private void RegisterEventHandlers() {
    84       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     92      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    8593    }
    8694
    87     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     95    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     96      DimensionOnChanged();
     97    }
     98
     99    protected virtual void DimensionOnChanged() { }
    88100  }
    89101}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageProblem.cs

    r16950 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Optimization.Operators;
     33using HeuristicLab.Parameters;
    3234
    3335namespace HeuristicLab.Encodings.LinearLinkageEncoding {
    3436  [StorableType("fb4cfc7c-dc7c-4da6-843f-0dad7d3d7981")]
    3537  public abstract class LinearLinkageProblem : SingleObjectiveProblem<LinearLinkageEncoding, LinearLinkage> {
    36     public int Length {
    37       get { return Encoding.Length; }
    38       set { Encoding.Length = value; }
     38    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     39    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     40
     41    public int Dimension {
     42      get { return DimensionRefParameter.Value.Value; }
     43      set { DimensionRefParameter.Value.Value = value; }
    3944    }
    4045
     
    4853    protected LinearLinkageProblem(LinearLinkageProblem original, Cloner cloner)
    4954      : base(original, cloner) {
     55      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5056      RegisterEventHandlers();
    5157    }
     
    5460    protected LinearLinkageProblem(LinearLinkageEncoding encoding) : base(encoding) {
    5561      EncodingParameter.ReadOnly = true;
     62      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the linear linkage problem.", Encoding.LengthParameter));
    5663
    5764      Operators.Add(new HammingSimilarityCalculator());
     
    8390
    8491    private void RegisterEventHandlers() {
    85       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     92      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    8693    }
    8794
    88     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     95    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     96      DimensionOnChanged();
     97    }
     98
     99    protected virtual void DimensionOnChanged() { }
    89100  }
    90101}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationMultiObjectiveProblem.cs

    r17230 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
     32using HeuristicLab.Parameters;
    3133
    3234namespace HeuristicLab.Encodings.PermutationEncoding {
    3335  [StorableType("7bc5215b-c181-40d0-a758-d7c19a356e18")]
    3436  public abstract class PermutationMultiObjectiveProblem : MultiObjectiveProblem<PermutationEncoding, Permutation> {
    35     public int Length {
    36       get { return Encoding.Length; }
    37       set { Encoding.Length = value; }
    38     }
     37    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     38    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    3939
    40     public PermutationTypes Type {
    41       get { return Encoding.Type; }
    42       set { Encoding.Type = value; }
     40    public int Dimension {
     41      get { return DimensionRefParameter.Value.Value; }
     42      set { DimensionRefParameter.Value.Value = value; }
    4343    }
    4444
     
    5252    protected PermutationMultiObjectiveProblem(PermutationMultiObjectiveProblem original, Cloner cloner)
    5353      : base(original, cloner) {
     54      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5455      RegisterEventHandlers();
    5556    }
     
    5859    protected PermutationMultiObjectiveProblem(PermutationEncoding encoding) : base(encoding) {
    5960      EncodingParameter.ReadOnly = true;
     61      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    6062
    6163      Operators.Add(new HammingSimilarityCalculator());
     
    8789
    8890    private void RegisterEventHandlers() {
    89       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
    90       Encoding.PermutationTypeParameter.Value.ValueChanged += TypeParameter_ValueChanged;
     91      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    9192    }
    9293
    93     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
    94     protected virtual void TypeParameter_ValueChanged(object sender, EventArgs e) { }
     94    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     95      DimensionOnChanged();
     96    }
     97
     98    protected virtual void DimensionOnChanged() { }
    9599  }
    96100}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationProblem.cs

    r16950 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Optimization.Operators;
     33using HeuristicLab.Parameters;
    3234
    3335namespace HeuristicLab.Encodings.PermutationEncoding {
    3436  [StorableType("aceff7a2-0666-4055-b698-6ea3628713b6")]
    3537  public abstract class PermutationProblem : SingleObjectiveProblem<PermutationEncoding, Permutation> {
    36     public int Length {
    37       get { return Encoding.Length; }
    38       set { Encoding.Length = value; }
    39     }
     38    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     39    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
    4040
    41     public PermutationTypes Type {
    42       get { return Encoding.Type; }
    43       set { Encoding.Type = value; }
     41    public int Dimension {
     42      get { return DimensionRefParameter.Value.Value; }
     43      set { DimensionRefParameter.Value.Value = value; }
    4444    }
    4545
     
    5353    protected PermutationProblem(PermutationProblem original, Cloner cloner)
    5454      : base(original, cloner) {
     55      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
    5556      RegisterEventHandlers();
    5657    }
     
    5960    protected PermutationProblem(PermutationEncoding encoding) : base(encoding) {
    6061      EncodingParameter.ReadOnly = true;
     62      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the permutation problem.", Encoding.LengthParameter));
    6163
    6264      Operators.Add(new HammingSimilarityCalculator());
     
    8789
    8890    private void RegisterEventHandlers() {
    89       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
    90       Encoding.PermutationTypeParameter.Value.ValueChanged += TypeParameter_ValueChanged;
     91      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
    9192    }
    9293
    93     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
    94     protected virtual void TypeParameter_ValueChanged(object sender, EventArgs e) { }
     94    private void DimensionParameter_Value_ValueChanged(object sender, EventArgs e) {
     95      DimensionOnChanged();
     96    }
     97
     98    protected virtual void DimensionOnChanged() { }
    9599  }
    96100}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorMultiObjectiveProblem.cs

    r17230 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
     32using HeuristicLab.Parameters;
    3133
    3234namespace HeuristicLab.Encodings.RealVectorEncoding {
    3335  [StorableType("135697c1-1b2b-46b6-a518-1c6efae09475")]
    3436  public abstract class RealVectorMultiObjectiveProblem : MultiObjectiveProblem<RealVectorEncoding, RealVector> {
    35     public int Length {
    36       get { return Encoding.Length; }
    37       set { Encoding.Length = value; }
     37    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     38    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     39    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
     40    public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
     41
     42    public int Dimension {
     43      get { return DimensionRefParameter.Value.Value; }
     44      set { DimensionRefParameter.Value.Value = value; }
     45    }
     46
     47    public DoubleMatrix Bounds {
     48      get { return BoundsRefParameter.Value; }
     49      set { BoundsParameter.Value = value; }
    3850    }
    3951
     
    4759    protected RealVectorMultiObjectiveProblem(RealVectorMultiObjectiveProblem original, Cloner cloner)
    4860      : base(original, cloner) {
     61      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     62      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
    4963      RegisterEventHandlers();
    5064    }
     
    5367    protected RealVectorMultiObjectiveProblem(RealVectorEncoding encoding) : base(encoding) {
    5468      EncodingParameter.ReadOnly = true;
     69      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter));
     70      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter));
     71
    5572
    5673      Operators.Add(new HammingSimilarityCalculator());
     
    8299
    83100    private void RegisterEventHandlers() {
    84       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     101      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
     102      BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    85103    }
    86104
    87     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     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();
     111    }
     112
     113    protected virtual void DimensionOnChanged() { }
     114
     115    protected virtual void BoundsOnChanged() { }
    88116  }
    89117}
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorProblem.cs

    r16950 r17544  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Optimization.Operators;
     33using HeuristicLab.Parameters;
    3234
    3335namespace HeuristicLab.Encodings.RealVectorEncoding {
    3436  [StorableType("7860a955-af16-459a-9cd8-51667e06d38e")]
    3537  public abstract class RealVectorProblem : SingleObjectiveProblem<RealVectorEncoding, RealVector> {
    36     public int Length {
    37       get { return Encoding.Length; }
    38       set { Encoding.Length = value; }
     38    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
     39    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     40    [Storable] protected ReferenceParameter<DoubleMatrix> BoundsRefParameter { get; private set; }
     41    public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
     42
     43    public int Dimension {
     44      get { return DimensionRefParameter.Value.Value; }
     45      set { DimensionRefParameter.Value.Value = value; }
     46    }
     47
     48    public DoubleMatrix Bounds {
     49      get { return BoundsRefParameter.Value; }
     50      set { BoundsParameter.Value = value; }
    3951    }
    4052
     
    4860    protected RealVectorProblem(RealVectorProblem original, Cloner cloner)
    4961      : base(original, cloner) {
     62      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     63      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
    5064      RegisterEventHandlers();
    5165    }
     
    5468    protected RealVectorProblem(RealVectorEncoding encoding) : base(encoding) {
    5569      EncodingParameter.ReadOnly = true;
     70      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the real vector problem.", Encoding.LengthParameter));
     71      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the values.", Encoding.BoundsParameter));
    5672
    5773      Operators.Add(new HammingSimilarityCalculator());
     
    8399
    84100    private void RegisterEventHandlers() {
    85       Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     101      DimensionRefParameter.Value.ValueChanged += DimensionParameter_Value_ValueChanged;
     102      BoundsRefParameter.ValueChanged += BoundsParameter_ValueChanged;
    86103    }
    87104
    88     protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
     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();
     111    }
     112
     113    protected virtual void DimensionOnChanged() { }
     114
     115    protected virtual void BoundsOnChanged() { }
    89116  }
    90117}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveStepTrapProblem.cs

    r17226 r17544  
    2222#endregion
    2323
     24using System;
    2425using HEAL.Attic;
    2526using HeuristicLab.Common;
     
    3435  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)]
    3536  public class DeceptiveStepTrapProblem : DeceptiveTrapProblem {
    36     [StorableConstructor]
    37     protected DeceptiveStepTrapProblem(StorableConstructorFlag _) : base(_) { }
    38     protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
    39       : base(original, cloner) {
    40       RegisterParameterEvents();
    41     }
    42     public override IDeepCloneable Clone(Cloner cloner) {
    43       return new DeceptiveStepTrapProblem(this, cloner);
    44     }
    45 
    46     private const string StepSizeParameterName = "Step Size";
    47 
    48     public IFixedValueParameter<IntValue> StepSizeParameter {
    49       get { return (IFixedValueParameter<IntValue>)Parameters[StepSizeParameterName]; }
    50     }
     37    [Storable] private int offset = -1;
     38    [Storable] public IFixedValueParameter<IntValue> StepSizeParameter { get; private set; }
    5139
    5240    public int StepSize {
     
    5644
    5745    public DeceptiveStepTrapProblem() : base() {
    58       Parameters.Add(new FixedValueParameter<IntValue>(StepSizeParameterName, "", new IntValue(2)));
     46      Parameters.Add(StepSizeParameter = new FixedValueParameter<IntValue>("Step Size", "", new IntValue(2)));
     47      offset = (TrapSize - StepSize) % StepSize;
     48
    5949      RegisterParameterEvents();
    6050    }
     51
     52    protected override int TrapMaximum {
     53      get { return (offset + TrapSize) / StepSize; }
     54    }
     55
     56    protected override int Score(BinaryVector individual, int trapIndex, int trapSize) {
     57      int partial = base.Score(individual, trapIndex, trapSize);
     58      // introduce plateaus using integer division
     59      return (offset + partial) / StepSize;
     60    }
     61
     62    [StorableConstructor]
     63    protected DeceptiveStepTrapProblem(StorableConstructorFlag _) : base(_) { }
    6164
    6265    [StorableHook(HookType.AfterDeserialization)]
     
    6467      RegisterParameterEvents();
    6568    }
     69    protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
     70      : base(original, cloner) {
     71      offset = original.offset;
     72      StepSizeParameter = cloner.Clone(original.StepSizeParameter);
     73
     74      RegisterParameterEvents();
     75    }
     76    public override IDeepCloneable Clone(Cloner cloner) {
     77      return new DeceptiveStepTrapProblem(this, cloner);
     78    }
    6679
    6780    private void RegisterParameterEvents() {
    68       TrapSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
    69       StepSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
     81      StepSizeParameter.Value.ValueChanged += StepSizeOnChanged;
    7082    }
    7183
    72 
    73     private int offset = -1;
    74     private int Offset {
    75       get {
    76         if (offset == -1) offset = (TrapSize - StepSize) % StepSize;
    77         return offset;
    78       }
     84    protected override void TrapSizeOnChanged(object sender, EventArgs e) {
     85      base.TrapSizeOnChanged(sender, e);
     86      offset = (TrapSize - StepSize) % StepSize;
    7987    }
    8088
    81     protected override int TrapMaximum {
    82       get { return (Offset + TrapSize) / StepSize; }
    83     }
    84 
    85     protected override int Score(BinaryVector individual, int trapIndex, int trapSize) {
    86       int partial = base.Score(individual, trapIndex, trapSize);
    87       // introduce plateaus using integer division
    88       return (Offset + partial) / StepSize;
     89    private void StepSizeOnChanged(object sender, EventArgs e) {
     90      offset = (TrapSize - StepSize) % StepSize;
    8991    }
    9092  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r17382 r17544  
    3737  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)]
    3838  public class DeceptiveTrapProblem : BinaryVectorProblem {
    39     [StorableConstructor]
    40     protected DeceptiveTrapProblem(StorableConstructorFlag _) : base(_) { }
    41     protected DeceptiveTrapProblem(DeceptiveTrapProblem original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
    44     public override IDeepCloneable Clone(Cloner cloner) {
    45       return new DeceptiveTrapProblem(this, cloner);
    46     }
    47 
    48     private const string TrapSizeParameterName = "Trap Size";
    49 
    50     public IFixedValueParameter<IntValue> TrapSizeParameter {
    51       get { return (IFixedValueParameter<IntValue>)Parameters[TrapSizeParameterName]; }
    52     }
     39    [Storable] public IFixedValueParameter<IntValue> TrapSizeParameter { get; private set; }
     40    [Storable] public IFixedValueParameter<IntValue> NumberOfTrapsParameter { get; private set; }
    5341
    5442    public int TrapSize {
    5543      get { return TrapSizeParameter.Value.Value; }
    5644      set { TrapSizeParameter.Value.Value = value; }
     45    }
     46
     47    public int NumberOfTraps {
     48      get { return NumberOfTrapsParameter.Value.Value; }
     49      set { NumberOfTrapsParameter.Value.Value = value; }
    5750    }
    5851
     
    6356    public DeceptiveTrapProblem() : base() {
    6457      Maximization = true;
    65       Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7)));
    66       Encoding.Length = 49;
     58      Parameters.Add(TrapSizeParameter = new FixedValueParameter<IntValue>("Trap Size", "", new IntValue(7)));
     59      Parameters.Add(NumberOfTrapsParameter = new FixedValueParameter<IntValue>("Number of Traps", "", new IntValue(7)));
     60      Dimension = TrapSize * NumberOfTraps;
     61
     62      RegisterEventHandlers();
    6763    }
    6864
     
    8379
    8480    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
    85       if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length.");
     81      if (individual.Length != Dimension) throw new ArgumentException("The individual has not the correct length.");
    8682      int total = 0;
    8783      var trapSize = TrapSize;
     
    9288      return new SingleObjectiveEvaluationResult(quality);
    9389    }
     90
     91    [StorableConstructor]
     92    protected DeceptiveTrapProblem(StorableConstructorFlag _) : base(_) { }
     93    [StorableHook(HookType.AfterDeserialization)]
     94    private void AfterDeserialization() {
     95      RegisterEventHandlers();
     96    }
     97    protected DeceptiveTrapProblem(DeceptiveTrapProblem original, Cloner cloner)
     98      : base(original, cloner) {
     99      TrapSizeParameter = cloner.Clone(original.TrapSizeParameter);
     100      NumberOfTrapsParameter = cloner.Clone(original.NumberOfTrapsParameter);
     101
     102      RegisterEventHandlers();
     103    }
     104    public override IDeepCloneable Clone(Cloner cloner) {
     105      return new DeceptiveTrapProblem(this, cloner);
     106    }
     107
     108    private void RegisterEventHandlers() {
     109      TrapSizeParameter.Value.ValueChanged += TrapSizeOnChanged;
     110      NumberOfTrapsParameter.Value.ValueChanged += NumberOfTrapsOnChanged;
     111    }
     112
     113    protected virtual void TrapSizeOnChanged(object sender, EventArgs e) {
     114      Dimension = TrapSize * NumberOfTraps;
     115    }
     116
     117    private void NumberOfTrapsOnChanged(object sender, EventArgs e) {
     118      Dimension = TrapSize * NumberOfTraps;
     119    }
    94120  }
    95121}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs

    r17382 r17544  
    2727using HeuristicLab.Common;
    2828using HeuristicLab.Core;
     29using HeuristicLab.Data;
    2930using HeuristicLab.Encodings.BinaryVectorEncoding;
    3031using HeuristicLab.Optimization;
     
    3536  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 220)]
    3637  public class HIFFProblem : BinaryVectorProblem {
    37     [StorableConstructor]
    38     protected HIFFProblem(StorableConstructorFlag _) : base(_) { }
    39     protected HIFFProblem(HIFFProblem original, Cloner cloner)
    40       : base(original, cloner) {
    41     }
    42     public override IDeepCloneable Clone(Cloner cloner) {
    43       return new HIFFProblem(this, cloner);
    44     }
    4538
    4639    public HIFFProblem() : base() {
    4740      Maximization = true;
    48       Encoding.Length = 64;
     41      DimensionRefParameter.ForceValue(new IntValue(64, @readonly: false));
    4942    }
     43
    5044    // In the GECCO paper, Section 4.1
    5145    public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {
     
    8781      return new SingleObjectiveEvaluationResult(quality);
    8882    }
     83
     84    [StorableConstructor]
     85    protected HIFFProblem(StorableConstructorFlag _) : base(_) { }
     86    protected HIFFProblem(HIFFProblem original, Cloner cloner)
     87      : base(original, cloner) {
     88    }
     89    public override IDeepCloneable Clone(Cloner cloner) {
     90      return new HIFFProblem(this, cloner);
     91    }
    8992  }
    9093}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs

    r17382 r17544  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using System.Threading;
     
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.BinaryVectorEncoding;
    2929using HeuristicLab.Optimization;
     
    3737    public OneMaxProblem() : base() {
    3838      Maximization = true;
    39       Encoding.Length = 10;
    40       BestKnownQuality = Encoding.Length;
    41     }
    42 
    43     [StorableConstructor]
    44     protected OneMaxProblem(StorableConstructorFlag _) : base(_) { }
    45 
    46     protected OneMaxProblem(OneMaxProblem original, Cloner cloner) : base(original, cloner) { }
    47     public override IDeepCloneable Clone(Cloner cloner) {
    48       return new OneMaxProblem(this, cloner);
     39      DimensionRefParameter.ForceValue(new IntValue(10, @readonly: false));
     40      BestKnownQuality = Dimension;
    4941    }
    5042
     
    5446    }
    5547
    56     protected override void LengthParameter_ValueChanged(object sender, EventArgs e) {
    57       base.LengthParameter_ValueChanged(sender, e);
    58       BestKnownQuality = Length;
     48    [StorableConstructor]
     49    protected OneMaxProblem(StorableConstructorFlag _) : base(_) { }
     50    protected OneMaxProblem(OneMaxProblem original, Cloner cloner) : base(original, cloner) { }
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new OneMaxProblem(this, cloner);
     53    }
     54
     55    protected override void DimensionOnChanged() {
     56      base.DimensionOnChanged();
     57      BestKnownQuality = Dimension;
    5958    }
    6059  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/ExternalEvaluationProblemInstances.cs

    r16874 r17544  
    4141  [StorableType("4ea0ded8-4451-4011-b88e-4d0680721b01")]
    4242  public sealed class SingleObjectiveBinaryVectorExternalEvaluationProblem : ExternalEvaluationProblem<BinaryVectorEncoding, BinaryVector> {
     43    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     44    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     45
     46    public int Dimension {
     47      get => Encoding.Length;
     48      set => Encoding.Length = value;
     49    }
    4350
    4451    [StorableConstructor]
    4552    private SingleObjectiveBinaryVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    46     private SingleObjectiveBinaryVectorExternalEvaluationProblem(SingleObjectiveBinaryVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     53    private SingleObjectiveBinaryVectorExternalEvaluationProblem(SingleObjectiveBinaryVectorExternalEvaluationProblem original, Cloner cloner)
     54      : base(original, cloner) {
     55      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     56    }
    4757
    4858    public SingleObjectiveBinaryVectorExternalEvaluationProblem()
    4959      : base(new BinaryVectorEncoding()) {
    50       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    51       Parameters.Add(lengthParameter);
    52       Encoding.LengthParameter = lengthParameter;
     60      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     61      DimensionRefParameter.ForceValue(new IntValue(Dimension, @readonly: false));
    5362      // TODO: Add and parameterize additional operators,
    5463    }
     
    6473  [StorableType("46465e8c-11d8-4d02-8c45-de41a08db7fa")]
    6574  public sealed class SingleObjectiveIntegerVectorExternalEvaluationProblem : ExternalEvaluationProblem<IntegerVectorEncoding, IntegerVector> {
     75    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     76    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     77    [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter;
     78    public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter;
     79
     80    public int Dimension {
     81      get => DimensionRefParameter.Value.Value;
     82      set => DimensionRefParameter.Value.Value = value;
     83    }
     84
     85    public IntMatrix Bounds {
     86      get => BoundsRefParameter.Value;
     87      set => BoundsRefParameter.Value = value;
     88    }
    6689
    6790    [StorableConstructor]
    6891    private SingleObjectiveIntegerVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    69     private SingleObjectiveIntegerVectorExternalEvaluationProblem(SingleObjectiveIntegerVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     92    private SingleObjectiveIntegerVectorExternalEvaluationProblem(SingleObjectiveIntegerVectorExternalEvaluationProblem original, Cloner cloner)
     93      : base(original, cloner) {
     94      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     95      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     96    }
    7097
    7198    public SingleObjectiveIntegerVectorExternalEvaluationProblem()
    7299      : base(new IntegerVectorEncoding()) {
    73       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    74       Parameters.Add(lengthParameter);
    75       Encoding.LengthParameter = lengthParameter;
     100      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     101      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounding box and step size of the elements.", Encoding.BoundsParameter));
    76102      // TODO: Add and parameterize additional operators,
    77103    }
     
    87113  [StorableType("637f091f-6601-494e-bafb-2a8ea474210c")]
    88114  public sealed class SingleObjectiveRealVectorExternalEvaluationProblem : ExternalEvaluationProblem<RealVectorEncoding, RealVector> {
     115    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     116    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     117    [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter;
     118    public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
     119
     120    public int Dimension {
     121      get => DimensionRefParameter.Value.Value;
     122      set => DimensionRefParameter.Value.Value = value;
     123    }
     124
     125    public DoubleMatrix Bounds {
     126      get => BoundsRefParameter.Value;
     127      set => BoundsRefParameter.Value = value;
     128    }
    89129
    90130    [StorableConstructor]
    91131    private SingleObjectiveRealVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    92     private SingleObjectiveRealVectorExternalEvaluationProblem(SingleObjectiveRealVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     132    private SingleObjectiveRealVectorExternalEvaluationProblem(SingleObjectiveRealVectorExternalEvaluationProblem original, Cloner cloner)
     133      : base(original, cloner) {
     134      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     135      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     136    }
    93137
    94138    public SingleObjectiveRealVectorExternalEvaluationProblem()
    95139      : base(new RealVectorEncoding()) {
    96       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    97       Parameters.Add(lengthParameter);
    98       Encoding.LengthParameter = lengthParameter;
     140      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     141      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the elements.", Encoding.BoundsParameter));
    99142      // TODO: Add and parameterize additional operators,
    100143    }
     
    110153  [StorableType("ad9d45f8-b97e-49a7-b3d2-487d9a2cbdf9")]
    111154  public sealed class SingleObjectivePermutationExternalEvaluationProblem : ExternalEvaluationProblem<PermutationEncoding, Permutation> {
     155    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     156    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     157
     158    public int Dimension {
     159      get => DimensionRefParameter.Value.Value;
     160      set => DimensionRefParameter.Value.Value = value;
     161    }
    112162
    113163    [StorableConstructor]
    114164    private SingleObjectivePermutationExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    115     private SingleObjectivePermutationExternalEvaluationProblem(SingleObjectivePermutationExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     165    private SingleObjectivePermutationExternalEvaluationProblem(SingleObjectivePermutationExternalEvaluationProblem original, Cloner cloner)
     166      : base(original, cloner) {
     167      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     168    }
    116169
    117170    public SingleObjectivePermutationExternalEvaluationProblem()
    118171      : base(new PermutationEncoding()) {
    119       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the permutation.", new IntValue(10));
    120       Parameters.Add(lengthParameter);
    121       Encoding.LengthParameter = lengthParameter;
     172      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
    122173      // TODO: Add and parameterize additional operators,
    123174    }
     
    140191    public SingleObjectiveSymbolicExpressionTreeExternalEvaluationProblem()
    141192      : base(new SymbolicExpressionTreeEncoding()) {
     193      // TODO: Change to ReferenceParameter
    142194      var lengthParameter = new FixedValueParameter<IntValue>("TreeLength", "The total amount of nodes.", new IntValue(50));
    143195      Parameters.Add(lengthParameter);
     
    159211  [StorableType("945a35d9-89a8-4423-9ea0-21829ac68887")]
    160212  public sealed class SingleObjectiveLinearLinkageExternalEvaluationProblem : ExternalEvaluationProblem<LinearLinkageEncoding, LinearLinkage> {
     213    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     214    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     215
     216    public int Dimension {
     217      get => DimensionRefParameter.Value.Value;
     218      set => DimensionRefParameter.Value.Value = value;
     219    }
    161220
    162221    [StorableConstructor]
    163222    private SingleObjectiveLinearLinkageExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    164     private SingleObjectiveLinearLinkageExternalEvaluationProblem(SingleObjectiveLinearLinkageExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     223    private SingleObjectiveLinearLinkageExternalEvaluationProblem(SingleObjectiveLinearLinkageExternalEvaluationProblem original, Cloner cloner)
     224      : base(original, cloner) {
     225      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     226    }
    165227
    166228    public SingleObjectiveLinearLinkageExternalEvaluationProblem()
    167229      : base(new LinearLinkageEncoding()) {
    168       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    169       Parameters.Add(lengthParameter);
    170       Encoding.LengthParameter = lengthParameter;
     230      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
    171231      // TODO: Add and parameterize additional operators,
    172232    }
     
    199259  [StorableType("f14c7e88-b74d-4cad-ae55-83daf7b4c288")]
    200260  public sealed class MultiObjectiveBinaryVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<BinaryVectorEncoding, BinaryVector> {
     261    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     262    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     263
     264    public int Dimension {
     265      get => Encoding.Length;
     266      set => Encoding.Length = value;
     267    }
    201268
    202269    [StorableConstructor]
    203270    private MultiObjectiveBinaryVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    204     private MultiObjectiveBinaryVectorExternalEvaluationProblem(MultiObjectiveBinaryVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     271    private MultiObjectiveBinaryVectorExternalEvaluationProblem(MultiObjectiveBinaryVectorExternalEvaluationProblem original, Cloner cloner)
     272      : base(original, cloner) {
     273      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     274    }
    205275
    206276    public MultiObjectiveBinaryVectorExternalEvaluationProblem()
    207277      : base(new BinaryVectorEncoding()) {
    208       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    209       Parameters.Add(lengthParameter);
    210       Encoding.LengthParameter = lengthParameter;
     278      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     279      DimensionRefParameter.ForceValue(new IntValue(Dimension, @readonly: false));
    211280      // TODO: Add and parameterize additional operators,
    212281    }
     
    222291  [StorableType("90a82c2f-6c37-4ffd-8495-bee278c583d3")]
    223292  public sealed class MultiObjectiveIntegerVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<IntegerVectorEncoding, IntegerVector> {
     293    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     294    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     295    [Storable] private ReferenceParameter<IntMatrix> BoundsRefParameter;
     296    public IValueParameter<IntMatrix> BoundsParameter => BoundsRefParameter;
     297
     298    public int Dimension {
     299      get => DimensionRefParameter.Value.Value;
     300      set => DimensionRefParameter.Value.Value = value;
     301    }
     302
     303    public IntMatrix Bounds {
     304      get => BoundsRefParameter.Value;
     305      set => BoundsRefParameter.Value = value;
     306    }
    224307
    225308    [StorableConstructor]
    226309    private MultiObjectiveIntegerVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    227     private MultiObjectiveIntegerVectorExternalEvaluationProblem(MultiObjectiveIntegerVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     310    private MultiObjectiveIntegerVectorExternalEvaluationProblem(MultiObjectiveIntegerVectorExternalEvaluationProblem original, Cloner cloner)
     311      : base(original, cloner) {
     312      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     313      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     314    }
    228315
    229316    public MultiObjectiveIntegerVectorExternalEvaluationProblem()
    230317      : base(new IntegerVectorEncoding()) {
    231       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    232       Parameters.Add(lengthParameter);
    233       Encoding.LengthParameter = lengthParameter;
     318      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     319      Parameters.Add(BoundsRefParameter = new ReferenceParameter<IntMatrix>("Bounds", "The bounding box and step size of the elements.", Encoding.BoundsParameter));
    234320      // TODO: Add and parameterize additional operators,
    235321    }
     
    245331  [StorableType("38e1d068-d569-48c5-bad6-cbdd685b7c6b")]
    246332  public sealed class MultiObjectiveRealVectorExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<RealVectorEncoding, RealVector> {
     333    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     334    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     335    [Storable] private ReferenceParameter<DoubleMatrix> BoundsRefParameter;
     336    public IValueParameter<DoubleMatrix> BoundsParameter => BoundsRefParameter;
     337
     338    public int Dimension {
     339      get => DimensionRefParameter.Value.Value;
     340      set => DimensionRefParameter.Value.Value = value;
     341    }
     342
     343    public DoubleMatrix Bounds {
     344      get => BoundsRefParameter.Value;
     345      set => BoundsRefParameter.Value = value;
     346    }
    247347
    248348    [StorableConstructor]
    249349    private MultiObjectiveRealVectorExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    250     private MultiObjectiveRealVectorExternalEvaluationProblem(MultiObjectiveRealVectorExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     350    private MultiObjectiveRealVectorExternalEvaluationProblem(MultiObjectiveRealVectorExternalEvaluationProblem original, Cloner cloner)
     351      : base(original, cloner) {
     352      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     353      BoundsRefParameter = cloner.Clone(original.BoundsRefParameter);
     354    }
    251355
    252356    public MultiObjectiveRealVectorExternalEvaluationProblem()
    253357      : base(new RealVectorEncoding()) {
    254       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    255       Parameters.Add(lengthParameter);
    256       Encoding.LengthParameter = lengthParameter;
     358      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
     359      Parameters.Add(BoundsRefParameter = new ReferenceParameter<DoubleMatrix>("Bounds", "The bounding box of the elements.", Encoding.BoundsParameter));
    257360      // TODO: Add and parameterize additional operators,
    258361    }
     
    268371  [StorableType("f1b265b0-ac7c-4c36-b346-5b3f2c37694b")]
    269372  public sealed class MultiObjectivePermutationExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<PermutationEncoding, Permutation> {
     373    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     374    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     375
     376    public int Dimension {
     377      get => DimensionRefParameter.Value.Value;
     378      set => DimensionRefParameter.Value.Value = value;
     379    }
    270380
    271381    [StorableConstructor]
    272382    private MultiObjectivePermutationExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    273     private MultiObjectivePermutationExternalEvaluationProblem(MultiObjectivePermutationExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     383    private MultiObjectivePermutationExternalEvaluationProblem(MultiObjectivePermutationExternalEvaluationProblem original, Cloner cloner)
     384      : base(original, cloner) {
     385      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     386    }
    274387
    275388    public MultiObjectivePermutationExternalEvaluationProblem()
    276389      : base(new PermutationEncoding()) {
    277       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the permutation.", new IntValue(10));
    278       Parameters.Add(lengthParameter);
    279       Encoding.LengthParameter = lengthParameter;
     390      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
    280391      // TODO: Add and parameterize additional operators,
    281392    }
     
    298409    public MultiObjectiveSymbolicExpressionTreeExternalEvaluationProblem()
    299410      : base(new SymbolicExpressionTreeEncoding()) {
     411      // TODO: Change to ReferenceParameter
    300412      var lengthParameter = new FixedValueParameter<IntValue>("TreeLength", "The total amount of nodes.", new IntValue(50));
    301413      Parameters.Add(lengthParameter);
     
    317429  [StorableType("ed0c1129-651d-465f-87b0-f412f3e3b3d1")]
    318430  public sealed class MultiObjectiveLinearLinkageExternalEvaluationProblem : MultiObjectiveExternalEvaluationProblem<LinearLinkageEncoding, LinearLinkage> {
     431    [Storable] private ReferenceParameter<IntValue> DimensionRefParameter;
     432    public IValueParameter<IntValue> DimensionParameter => DimensionRefParameter;
     433
     434    public int Dimension {
     435      get => DimensionRefParameter.Value.Value;
     436      set => DimensionRefParameter.Value.Value = value;
     437    }
    319438
    320439    [StorableConstructor]
    321440    private MultiObjectiveLinearLinkageExternalEvaluationProblem(StorableConstructorFlag _) : base(_) { }
    322     private MultiObjectiveLinearLinkageExternalEvaluationProblem(MultiObjectiveLinearLinkageExternalEvaluationProblem original, Cloner cloner) : base(original, cloner) { }
     441    private MultiObjectiveLinearLinkageExternalEvaluationProblem(MultiObjectiveLinearLinkageExternalEvaluationProblem original, Cloner cloner)
     442      : base(original, cloner) {
     443      DimensionRefParameter = cloner.Clone(original.DimensionRefParameter);
     444    }
    323445
    324446    public MultiObjectiveLinearLinkageExternalEvaluationProblem()
    325447      : base(new LinearLinkageEncoding()) {
    326       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the vector.", new IntValue(10));
    327       Parameters.Add(lengthParameter);
    328       Encoding.LengthParameter = lengthParameter;
     448      Parameters.Add(DimensionRefParameter = new ReferenceParameter<IntValue>("Dimension", "The dimension of the vector.", Encoding.LengthParameter));
    329449      // TODO: Add and parameterize additional operators,
    330450    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17382 r17544  
    8383        imat[i, 1] = defaultInstance[i].Item2 - 1;
    8484      }
    85       Encoding.Length = defaultInstanceNodes;
     85      Dimension = defaultInstanceNodes;
    8686      AdjacencyListParameter.Value = imat;
    8787      BestKnownQualityParameter.Value = null;
     
    121121      if (FitnessFunction == FitnessFunction.Prioritized
    122122        && BestKnownColorsParameter.Value != null
    123         && Encoding.Length > 0) {
    124         var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(Encoding.Length)));
     123        && Dimension > 0) {
     124        var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(Dimension)));
    125125        // the value is e.g. 0.051 for 0 conflicts with 51 colors (and less than 1000 nodes)
    126126        BestKnownQuality = BestKnownColorsParameter.Value.Value * mag;
     
    247247
    248248    public void Load(GCPData data) {
    249       Encoding.Length = data.Nodes;
     249      Dimension = data.Nodes;
    250250      AdjacencyListParameter.Value = new IntMatrix(data.Adjacencies);
    251251      if (data.BestKnownColoring != null) {
     
    279279      instance.Name = Name;
    280280      instance.Description = Description;
    281       instance.Nodes = Encoding.Length;
     281      instance.Nodes = Dimension;
    282282      var adjList = AdjacencyListParameter.Value;
    283283      instance.Adjacencies = new int[adjList.Rows, 2];
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r17382 r17544  
    9191      Parameters.Add(new OptionalValueParameter<BinaryVector>("BestKnownSolution", "The best known solution of this Knapsack instance."));
    9292
     93      Dimension = Weights.Length;
    9394      InitializeRandomKnapsackInstance();
    9495
     
    125126      ValuesParameter.ValueChanged += ValuesParameter_ValueChanged;
    126127      ValuesParameter.Value.Reset += ValuesValue_Reset;
    127       // TODO: There is no even to detect if the parameter itself was changed
    128       Encoding.LengthParameter.ValueChanged += Encoding_LengthParameter_ValueChanged;
    129128    }
    130129
     
    144143      Parameterize();
    145144    }
     145    protected override void DimensionOnChanged() {
     146      base.DimensionOnChanged();
     147      if (Weights.Length != Dimension) {
     148        ((IStringConvertibleArray)WeightsParameter.Value).Length = Dimension;
     149      }
     150      if (Values.Length != Dimension) {
     151        ((IStringConvertibleArray)ValuesParameter.Value).Length = Dimension;
     152      }
     153      Parameterize();
     154    }
    146155    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    147156      Parameterize();
     
    157166      if (WeightsParameter.Value != null && ValuesParameter.Value != null) {
    158167        ((IStringConvertibleArray)ValuesParameter.Value).Length = Weights.Length;
    159         Encoding.Length = Weights.Length;
     168        Dimension = Weights.Length;
    160169      }
    161170      Parameterize();
     
    168177      if (WeightsParameter.Value != null && ValuesParameter.Value != null) {
    169178        ((IStringConvertibleArray)WeightsParameter.Value).Length = Values.Length;
    170         Encoding.Length = Values.Length;
    171       }
    172       Parameterize();
    173     }
    174     private void Encoding_LengthParameter_ValueChanged(object sender, EventArgs e) {
    175       if (Weights.Length != Encoding.Length) {
    176         ((IStringConvertibleArray)WeightsParameter.Value).Length = Encoding.Length;
    177       }
    178       if (Values.Length != Encoding.Length) {
    179         ((IStringConvertibleArray)ValuesParameter.Value).Length = Encoding.Length;
     179        Dimension = Values.Length;
    180180      }
    181181      Parameterize();
     
    271271
    272272      KnapsackCapacity = (int)Math.Round(0.7 * totalWeight);
     273      Dimension = Weights.Length;
    273274    }
    274275  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblem.cs

    r17530 r17544  
    243243
    244244    private void Parameterize() {
     245      if (Costs.Rows != Dimension) Dimension = Costs.Rows;
    245246      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
    246247        similarityCalculator.SolutionVariableName = Encoding.Name;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs

    r17382 r17544  
    232232    }
    233233
    234     protected override void LengthParameter_ValueChanged(object sender, EventArgs e) {
    235       NrOfFitnessComponentsParameter.Value = new IntValue(Length);
     234    protected override void DimensionOnChanged() {
     235      base.DimensionOnChanged();
     236      NrOfFitnessComponentsParameter.Value = new IntValue(Dimension);
    236237    }
    237238
     
    259260      if (InteractionInitializer != null)
    260261        GeneInteractionsParameter.Value = InteractionInitializer.InitializeInterations(
    261           Length,
     262          Dimension,
    262263          NrOfFitnessComponents.Value,
    263264          NrOfInteractions.Value, random);
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r17533 r17544  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.IO;
     
    7576      Parameters.Add(BestOrienteeringSolutionParameter = new ResultParameter<OrienteeringSolution>("Best Orienteering Solution", "The best so far solution found."));
    7677      Maximization = true;
     78      Dimension = OrienteeringProblemData.Cities;
    7779
    7880      InitializeOperators();
     
    145147    }
    146148
    147     protected override void OnEncodingChanged() {
    148       base.OnEncodingChanged();
    149       ParameterizeOperators();
     149    private void RegisterEventHandlers() {
     150      OrienteeringProblemDataParameter.ValueChanged += OrienteeringProblemDataParameterOnValueChanged;
     151    }
     152
     153    private void OrienteeringProblemDataParameterOnValueChanged(object sender, EventArgs e) {
     154      Dimension = OrienteeringProblemData.Cities;
    150155    }
    151156
     
    153158      base.OnEvaluatorChanged();
    154159      ParameterizeOperators();
     160    }
     161    protected override void DimensionOnChanged() {
     162      base.DimensionOnChanged();
     163      if (Dimension != OrienteeringProblemData.Cities)
     164        Dimension = OrienteeringProblemData.Cities;
    155165    }
    156166
     
    159169        OrienteeringProblemDataParameter = { ActualName = OrienteeringProblemDataParameter.Name }
    160170      };
    161 
    162171      Operators.Add(new OrienteeringLocalImprovementOperator() {
    163172        OrienteeringProblemDataParameter = { ActualName = OrienteeringProblemDataParameter.Name }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs

    r17533 r17544  
    7070
    7171      ProbabilisticTSPData = new ProbabilisticTSPData();
    72       Encoding.Length = ProbabilisticTSPData.Cities;
    73     }
    74 
    75     protected override void OnEncodingChanged() {
    76       base.OnEncodingChanged();
    77       Encoding.Length = ProbabilisticTSPData.Cities;
     72      Dimension = ProbabilisticTSPData.Cities;
    7873    }
    7974
     
    112107        throw new System.IO.InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates.");
    113108
    114       Encoding.Length = data.Dimension;
     109      Dimension = data.Dimension;
    115110      Name = data.Name;
    116111      Description = data.Description;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r17382 r17544  
    102102      LowerBoundParameter = cloner.Clone(original.LowerBoundParameter);
    103103      AverageQualityParameter = cloner.Clone(original.AverageQualityParameter);
    104       RegisterEventHandlers();
    105104    }
    106105    public QuadraticAssignmentProblem()
     
    133132
    134133      InitializeOperators();
    135       RegisterEventHandlers();
    136134    }
    137135
     
    155153    }
    156154
    157     [StorableHook(HookType.AfterDeserialization)]
    158     private void AfterDeserialization() {
    159       // BackwardsCompatibility3.3
    160       #region Backwards compatible code, remove with 3.4
    161       if (BestKnownSolutionsParameter == null)
    162         BestKnownSolutionsParameter = (IValueParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"];
    163       if (BestKnownSolutionParameter == null)
    164         BestKnownSolutionParameter = (IValueParameter<Permutation>)Parameters["BestKnownSolution"];
    165       if (WeightsParameter == null)
    166         WeightsParameter = (IValueParameter<DoubleMatrix>)Parameters["Weights"];
    167       if (DistancesParameter == null)
    168         DistancesParameter = (IValueParameter<DoubleMatrix>)Parameters["Distances"];
    169       if (LowerBoundParameter == null)
    170         LowerBoundParameter = (IValueParameter<DoubleValue>)Parameters["LowerBound"];
    171       if (AverageQualityParameter == null)
    172         AverageQualityParameter = (IValueParameter<DoubleValue>)Parameters["AverageQuality"];
    173       #endregion
    174       RegisterEventHandlers();
    175     }
    176 
    177155    #region Events
    178156    protected override void OnEncodingChanged() {
    179157      base.OnEncodingChanged();
    180       Encoding.Length = Weights.Rows;
     158      Dimension = Weights.Rows;
    181159      Parameterize();
    182160    }
     
    191169    #endregion
    192170
    193     private void RegisterEventHandlers() {
    194       Encoding.LengthParameter.Value.ValueChanged += EncodingLengthOnChanged;
    195     }
    196 
    197     private void EncodingLengthOnChanged(object sender, EventArgs e) {
    198       if (Encoding.Length != Weights.Rows) Encoding.Length = Weights.Rows;
     171    protected override void DimensionOnChanged() {
     172      base.DimensionOnChanged();
     173      if (Dimension != Weights.Rows) Dimension = Weights.Rows;
    199174    }
    200175
     
    354329      Weights = weights;
    355330      Distances = distances;
    356       Encoding.Length = weights.Rows;
     331      Dimension = weights.Rows;
    357332
    358333      BestKnownQualityParameter.Value = null;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/MultiObjectiveTestFunctionProblem.cs

    r17320 r17544  
    3737  public class MultiObjectiveTestFunctionProblem : RealVectorMultiObjectiveProblem, IProblemInstanceConsumer<MOTFData>, IMultiObjectiveProblemDefinition<RealVectorEncoding, RealVector> {
    3838    #region Parameter Properties
    39     public IFixedValueParameter<IntValue> ProblemSizeParameter {
    40       get { return (IFixedValueParameter<IntValue>)Parameters["ProblemSize"]; }
    41     }
    4239    public IFixedValueParameter<IntValue> ObjectivesParameter {
    4340      get { return (IFixedValueParameter<IntValue>)Parameters["Objectives"]; }
    44     }
    45     public IValueParameter<DoubleMatrix> BoundsParameter {
    46       get { return (IValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4741    }
    4842    public IValueParameter<IMultiObjectiveTestFunction> TestFunctionParameter {
     
    5246
    5347    #region Properties
    54     public int ProblemSize {
    55       get { return ProblemSizeParameter.Value.Value; }
    56       set { ProblemSizeParameter.Value.Value = value; }
    57     }
    5848    public new int Objectives {
    5949      get { return ObjectivesParameter.Value.Value; }
    6050      set { ObjectivesParameter.Value.Value = value; }
    61     }
    62     public DoubleMatrix Bounds {
    63       get { return BoundsParameter.Value; }
    64       set { BoundsParameter.Value = value; }
    6551    }
    6652    public IMultiObjectiveTestFunction TestFunction {
     
    8571
    8672    public MultiObjectiveTestFunctionProblem() : base() {
    87       Parameters.Add(new FixedValueParameter<IntValue>("ProblemSize", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(2)));
    8873      Parameters.Add(new FixedValueParameter<IntValue>("Objectives", "The dimensionality of the solution vector (number of objectives).", new IntValue(2)));
    89       Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -4, 4 } })));
    9074      Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca()));
    9175
    92       Encoding.LengthParameter = ProblemSizeParameter;
    93       Encoding.BoundsParameter = BoundsParameter;
    9476      BestKnownFrontParameter.Hidden = true;
    9577
     
    10183    private void RegisterEventHandlers() {
    10284      TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged;
    103       ProblemSizeParameter.Value.ValueChanged += ProblemSizeOnValueChanged;
    10485      ObjectivesParameter.Value.ValueChanged += ObjectivesOnValueChanged;
    10586    }
     
    156137    }
    157138
     139    protected override void DimensionOnChanged() {
     140      base.DimensionOnChanged();
     141      if (Dimension < TestFunction.MinimumSolutionLength || Dimension > TestFunction.MaximumSolutionLength)
     142        Dimension = Math.Min(TestFunction.MaximumSolutionLength, Math.Max(TestFunction.MinimumSolutionLength, Dimension));
     143      UpdateParameterValues();
     144    }
     145
    158146    private void TestFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
    159       ProblemSize = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(ProblemSize, TestFunction.MaximumSolutionLength));
     147      Dimension = Math.Max(TestFunction.MinimumSolutionLength, Math.Min(Dimension, TestFunction.MaximumSolutionLength));
    160148      Objectives = Math.Max(TestFunction.MinimumObjectives, Math.Min(Objectives, TestFunction.MaximumObjectives));
    161149      Parameters.Remove(ReferencePointParameterName);
     
    163151      UpdateParameterValues();
    164152      OnReset();
    165     }
    166 
    167     private void ProblemSizeOnValueChanged(object sender, EventArgs eventArgs) {
    168       ProblemSize = Math.Min(TestFunction.MaximumSolutionLength, Math.Max(TestFunction.MinimumSolutionLength, ProblemSize));
    169       UpdateParameterValues();
    170153    }
    171154
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17382 r17544  
    4242
    4343    #region Parameter Properties
    44     private IFixedValueParameter<IntValue> ProblemSizeParameter {
    45       get { return (IFixedValueParameter<IntValue>)Parameters["ProblemSize"]; }
    46     }
    47     private IValueParameter<DoubleMatrix> BoundsParameter {
    48       get { return (IValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
    49     }
    5044    public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
    5145      get { return (OptionalValueParameter<RealVector>)Parameters["BestKnownSolution"]; }
     
    5751
    5852    #region Properties
    59     public int ProblemSize {
    60       get { return ProblemSizeParameter.Value.Value; }
    61       set { ProblemSizeParameter.Value.Value = value; }
    62     }
    63     public DoubleMatrix Bounds {
    64       get { return BoundsParameter.Value; }
    65       set { BoundsParameter.Value = value; }
    66     }
    6753    public ISingleObjectiveTestFunction TestFunction {
    6854      get { return TestFunctionParameter.Value; }
     
    7965    public SingleObjectiveTestFunctionProblem()
    8066      : base(new RealVectorEncoding("Point")) {
    81       Parameters.Add(new FixedValueParameter<IntValue>("ProblemSize", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(2)));
    82       Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -100, 100 } })));
    8367      Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
    8468      Parameters.Add(new ValueParameter<ISingleObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Ackley()));
    8569      Maximization = TestFunction.Maximization;
    8670
    87       Encoding.LengthParameter = ProblemSizeParameter;
    88       Encoding.BoundsParameter = BoundsParameter;
    8971      BestKnownQuality = TestFunction.BestKnownQuality;
    9072
     
    10587      Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
    10688      TestFunctionParameter.ValueChanged += TestFunctionParameterOnValueChanged;
    107       ProblemSizeParameter.Value.ValueChanged += ProblemSizeOnValueChanged;
    108       BoundsParameter.ValueChanged += BoundsParameterOnValueChanged;
    10989    }
    11090
     
    156136      Parameterize();
    157137    }
     138    protected override void DimensionOnChanged() {
     139      base.DimensionOnChanged();
     140      if (Dimension < TestFunction.MinimumProblemSize || Dimension > TestFunction.MaximumProblemSize)
     141        Dimension = Math.Min(TestFunction.MaximumProblemSize, Math.Max(TestFunction.MinimumProblemSize, Dimension));
     142    }
     143    protected override void BoundsOnChanged() {
     144      base.BoundsOnChanged();
     145      Parameterize();
     146    }
    158147    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    159148      Parameterize();
    160149    }
    161150    private void TestFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
    162       var problemSizeChange = ProblemSize < TestFunction.MinimumProblemSize
    163                               || ProblemSize > TestFunction.MaximumProblemSize;
     151      var problemSizeChange = Dimension < TestFunction.MinimumProblemSize
     152                              || Dimension > TestFunction.MaximumProblemSize;
    164153      if (problemSizeChange) {
    165         ProblemSize = Math.Max(TestFunction.MinimumProblemSize, Math.Min(ProblemSize, TestFunction.MaximumProblemSize));
     154        Dimension = Math.Max(TestFunction.MinimumProblemSize, Math.Min(Dimension, TestFunction.MaximumProblemSize));
    166155      }
    167156      BestKnownQuality = TestFunction.BestKnownQuality;
    168157      Bounds = (DoubleMatrix)TestFunction.Bounds.Clone();
    169       var bestSolution = TestFunction.GetBestKnownSolution(ProblemSize);
     158      var bestSolution = TestFunction.GetBestKnownSolution(Dimension);
    170159      BestKnownSolutionParameter.Value = bestSolution;
    171160      Maximization = TestFunction.Maximization;
    172161
    173162      OnReset();
    174     }
    175     private void ProblemSizeOnValueChanged(object sender, EventArgs eventArgs) {
    176       if (ProblemSize < TestFunction.MinimumProblemSize
    177         || ProblemSize > TestFunction.MaximumProblemSize)
    178         ProblemSize = Math.Min(TestFunction.MaximumProblemSize, Math.Max(TestFunction.MinimumProblemSize, ProblemSize));
    179     }
    180     private void BoundsParameterOnValueChanged(object sender, EventArgs eventArgs) {
    181       Parameterize();
    182163    }
    183164    #endregion
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17525 r17544  
    7676     
    7777      TSPData = new EuclideanTSPData();
    78       Encoding.Length = TSPData.Cities;
     78      Dimension = TSPData.Cities;
    7979
    8080      InitializeOperators();
     
    140140        throw new System.IO.InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates.");
    141141
    142       Encoding.Length = data.Dimension;
     142      Dimension = data.Dimension;
    143143      Name = data.Name;
    144144      Description = data.Description;
     
    212212    protected override void OnEncodingChanged() {
    213213      base.OnEncodingChanged();
    214       Encoding.Length = TSPData.Cities;
     214      Dimension = TSPData.Cities;
    215215      ParameterizeOperators();
    216216    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/EsGriewankSampleTest.cs

    r17226 r17544  
    6464      SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
    6565
    66       problem.ProblemSize = 10;
     66      problem.Dimension = 10;
    6767      problem.TestFunction = new Griewank();
    6868      problem.Encoding.SolutionCreator = new UniformRandomRealVectorCreator();
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/OSESGriewankSampleTest.cs

    r17226 r17544  
    6363      SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
    6464
    65       problem.ProblemSize = 10;
     65      problem.Dimension = 10;
    6666      problem.TestFunction = new Griewank();
    6767      problem.Encoding.SolutionCreator = new UniformRandomRealVectorCreator();
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SimulatedAnnealingRastriginSampleTest.cs

    r17356 r17544  
    6262      problem.Bounds = new DoubleMatrix(new double[,] { { -5.12, 5.12 } });
    6363      problem.TestFunction= new Rastrigin();
    64       problem.ProblemSize = 2;
     64      problem.Dimension = 2;
    6565      problem.Encoding.SolutionCreator = new UniformRandomRealVectorCreator();
    6666      #endregion
  • branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3/ParameterlessPopulationPyramidTest.cs

    r17226 r17544  
    6060    public void P3DeceptiveTrap() {
    6161      var problem = new DeceptiveTrapProblem();
    62       problem.Length = 49;
     62      problem.NumberOfTraps = 7;
    6363      problem.TrapSize = 7;
    6464      DoRun(problem, 100, 123, 0.857142857142857, 50);
    6565      DoRun(problem, 9876, 123, 0.918367346938776, 981);
    6666      DoRun(problem, 20000, 987, 1, 19977);
    67       problem.Length = 700;
     67      problem.NumberOfTraps = 100;
    6868      DoRun(problem, 100000, 987, 0.941428571428571, 96901);
    6969    }
     
    7575    public void P3DeceptiveStepTrap() {
    7676      var problem = new DeceptiveStepTrapProblem();
    77       problem.Length = 49;
     77      problem.NumberOfTraps = 7;
    7878      problem.TrapSize = 7;
    7979      problem.StepSize = 2;
     
    8181      DoRun(problem, 9876, 123, 0.785714285714286, 3489);
    8282      DoRun(problem, 70000, 987, 1, 68292);
    83       problem.Length = 700;
     83      problem.NumberOfTraps = 100;
    8484      DoRun(problem, 100000, 987, 0.76, 58711);
    8585    }
     
    9191    public void P3HIFF() {
    9292      var problem = new HIFFProblem();
    93       problem.Length = 32;
     93      problem.Dimension = 32;
    9494      DoRun(problem, 50, 12345, 0.375, 26);
    9595      DoRun(problem, 1000, 12345, 1, 976);
    96       problem.Length = 512;
     96      problem.Dimension = 512;
    9797      DoRun(problem, 1000, 54321, 0.17361111111111, 440);
    9898      DoRun(problem, 130000, 54321, 1, 89214);
Note: See TracChangeset for help on using the changeset viewer.