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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.