Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/13/19 15:21:54 (6 years ago)
Author:
abeham
Message:

#2521: Added and modified encoding-specific abstract base classes

Location:
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3
Files:
2 edited

Legend:

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

    r16876 r16948  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
    30 using HeuristicLab.Data;
    3130using HeuristicLab.Optimization;
    32 using HeuristicLab.Parameters;
    3331
    3432namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     
    3836      get { return Encoding.Length; }
    3937      set { Encoding.Length = value; }
    40     }
    41 
    42     private IFixedValueParameter<IntValue> LengthParameter {
    43       get { return (IFixedValueParameter<IntValue>)Parameters["Length"]; }
    4438    }
    4539
     
    5650    }
    5751
    58     protected BinaryVectorMultiObjectiveProblem() : base(new BinaryVectorEncoding()) {
    59       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
    60       Parameters.Add(lengthParameter);
    61       Encoding.LengthParameter = lengthParameter;
     52    protected BinaryVectorMultiObjectiveProblem() : this(new BinaryVectorEncoding() { Length = 10 }) { }
     53    protected BinaryVectorMultiObjectiveProblem(BinaryVectorEncoding encoding) : base(encoding) {
     54      EncodingParameter.ReadOnly = true;
    6255
    6356      Operators.Add(new HammingSimilarityCalculator());
     
    7568    protected override void OnEncodingChanged() {
    7669      base.OnEncodingChanged();
    77       Encoding.LengthParameter = LengthParameter;
    7870      Parameterize();
    7971    }
     
    8779
    8880    private void RegisterEventHandlers() {
    89       LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     81      Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
    9082    }
    9183
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r16814 r16948  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
    30 using HeuristicLab.Data;
    3130using HeuristicLab.Optimization;
    3231using HeuristicLab.Optimization.Operators;
    33 using HeuristicLab.Parameters;
    3432
    3533namespace HeuristicLab.Encodings.BinaryVectorEncoding {
     
    3937      get { return Encoding.Length; }
    4038      set { Encoding.Length = value; }
    41     }
    42 
    43     private IFixedValueParameter<IntValue> LengthParameter {
    44       get { return (IFixedValueParameter<IntValue>)Parameters["Length"]; }
    4539    }
    4640
     
    5751    }
    5852
    59     protected BinaryVectorProblem() : base(new BinaryVectorEncoding()) {
    60       var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
    61       Parameters.Add(lengthParameter);
    62       Encoding.LengthParameter = lengthParameter;
     53    protected BinaryVectorProblem() : this(new BinaryVectorEncoding() { Length = 10 }) { }
     54    protected BinaryVectorProblem(BinaryVectorEncoding encoding) : base(encoding) {
     55      EncodingParameter.ReadOnly = true;
    6356
    6457      Operators.Add(new HammingSimilarityCalculator());
     
    7568      var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;
    7669
    77       if (!results.ContainsKey("Best Solution")) {
    78         results.Add(new Result("Best Solution", typeof(BinaryVector)));
    79       }
    80       results["Best Solution"].Value = (IItem)best.Clone();
     70      results.AddOrUpdateResult("Best Solution", (IItem)best.Clone());
    8171    }
    8272
    8373    protected override void OnEncodingChanged() {
    8474      base.OnEncodingChanged();
    85       Encoding.LengthParameter = LengthParameter;
    8675      Parameterize();
    8776    }
     
    9584
    9685    private void RegisterEventHandlers() {
    97       LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     86      Encoding.LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
    9887    }
    9988
Note: See TracChangeset for help on using the changeset viewer.