Ignore:
Timestamp:
07/20/16 14:02:36 (5 years ago)
Author:
gkronber
Message:

#1966: refactoring of bin packing implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs

    r13032 r14128  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Encodings.PermutationEncoding;
    2627using HeuristicLab.Optimization;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3940      return new ExhaustiveSwap2MoveGenerator(this, cloner);
    4041    }
    41     public static IEnumerable<Swap2Move> Generate(PackingSequenceEncoding PackingSequence, int nrOfBins) {
    42       for (int i = 0; i < PackingSequence.PackingSequence.Length - 1; i++)
    43         for (int j = i + 1; j < PackingSequence.PackingSequence.Length; j++) {
     42    public static IEnumerable<Swap2Move> Generate(Permutation packingSequence, int nrOfBins) {
     43      for (int i = 0; i < packingSequence.Length - 1; i++)
     44        for (int j = i + 1; j < packingSequence.Length; j++) {
    4445          if (j != i)
    45             yield return new Swap2Move(i, j, PackingSequence);
     46            yield return new Swap2Move(i, j, packingSequence);
    4647        }
    4748    }
    4849
    49     public static Swap2Move[] Apply(PackingSequenceEncoding PackingSequence) {
     50    public static Swap2Move[] Apply(Permutation packingSequence) {
    5051      int nrOfBins = 0;
    51       foreach (int binNr in PackingSequence.PackingSequence) {
     52      foreach (int binNr in packingSequence) {
    5253        if (binNr > nrOfBins)
    5354          nrOfBins = binNr;
     
    5556      nrOfBins++;
    5657
    57       int totalMoves = (PackingSequence.PackingSequence.Length * (PackingSequence.PackingSequence.Length - 1)) / 2;
     58      int totalMoves = (packingSequence.Length * (packingSequence.Length - 1)) / 2;
    5859      Swap2Move[] moves = new Swap2Move[totalMoves];
    5960      int count = 0;
    60       foreach (Swap2Move move in Generate(PackingSequence, nrOfBins)) {
     61      foreach (Swap2Move move in Generate(packingSequence, nrOfBins)) {
    6162        moves[count++] = move;
    6263      }
     
    6465    }
    6566
    66     protected override Swap2Move[] GenerateMoves(PackingSequenceEncoding PackingSequence) {
    67       return Apply(PackingSequence);
     67    protected override Swap2Move[] GenerateMoves(Permutation packingSequence) {
     68      return Apply(packingSequence);
    6869    }
    6970  }
Note: See TracChangeset for help on using the changeset viewer.