Free cookie consent management tool by TermsFeed Policy Generator

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

#1966: refactoring of bin packing implementation

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2
Files:
4 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  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/StochasticSwap2MoveGenerator.cs

    r13032 r14128  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Encodings.PermutationEncoding;
    2728using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
     
    5859    }
    5960
    60     public static Swap2Move[] Apply(PackingSequenceEncoding PackingSequence, IRandom random, int sampleSize) {
     61    public static Swap2Move[] Apply(Permutation packingSequence, IRandom random, int sampleSize) {
    6162
    6263      int nrOfBins = 0;
    63       foreach (int binNr in PackingSequence.PackingSequence) {
     64      foreach (int binNr in packingSequence) {
    6465        if (binNr > nrOfBins)
    6566          nrOfBins = binNr;
     
    6768      nrOfBins++;
    6869      var generatedMoves = new List<Swap2Move>();
    69       var moves = new List<Swap2Move>(ExhaustiveSwap2MoveGenerator.Generate(PackingSequence, nrOfBins));
     70      var moves = new List<Swap2Move>(ExhaustiveSwap2MoveGenerator.Generate(packingSequence, nrOfBins));
    7071      int moveCount = moves.Count;
    7172      for (int i = 0; i < sampleSize; i++) {
     
    7677    }
    7778
    78     protected override Swap2Move[] GenerateMoves(PackingSequenceEncoding SwapSequence) {
     79    protected override Swap2Move[] GenerateMoves(Permutation packingSequence) {
    7980      IRandom random = RandomParameter.ActualValue;
    80       return Apply(SwapSequence, random, SampleSizeParameter.ActualValue.Value);
     81      return Apply(packingSequence, random, SampleSizeParameter.ActualValue.Value);
    8182    }
    8283  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/Swap2Move.cs

    r14046 r14128  
    3232  [Item("Swap2 Move", "A move on a Sequence vector that is specified by two group-assignment-indexes.")]
    3333  [StorableClass]
    34   public class Swap2Move : SequenceMove, IPackingMove {
     34  public class Swap2Move : SequenceMove, IPackingMove<Permutation> {
    3535    [Storable]
    3636    public int Index1 { get; protected set; }
     
    4545      this.Index2 = original.Index2;
    4646    }
    47     public Swap2Move(int index1, int index2, PackingSequenceEncoding PackingSequence)
    48       : base(PackingSequence) {
     47    public Swap2Move(int index1, int index2, Permutation packingSequence)
     48      : base(packingSequence) {
    4949      Index1 = index1;
    5050      Index2 = index2;
     
    5555    }
    5656
    57     public override IPackingSolutionEncoding GetSolutionAfterMove() {
    58       PackingSequenceEncoding newSolution = new PackingSequenceEncoding();
    59       newSolution.PackingSequence = (Permutation)PackingSequence.PackingSequence.Clone(new Cloner());
    60       newSolution.PackingSequence[Index1] = PackingSequence.PackingSequence[Index2];
    61       newSolution.PackingSequence[Index2] = PackingSequence.PackingSequence[Index1];
     57    public override Permutation GetSolutionAfterMove() {
     58      Permutation newSolution = (Permutation)PackingSequence.Clone(new Cloner());
     59      newSolution[Index1] = PackingSequence[Index2];
     60      newSolution[Index2] = PackingSequence[Index1];
    6261      return newSolution;
    6362    }
     
    6867
    6968    public override SequenceMoveAttribute GetAttribute(double quality) {
    70       return new Swap2MoveAttribute(Index1, Index2, PackingSequence.PackingSequence[Index1], PackingSequence.PackingSequence[Index2], quality);
     69      return new Swap2MoveAttribute(Index1, Index2, PackingSequence[Index1], PackingSequence[Index2], quality);
    7170    }
    7271
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/Swap2MoveGenerator.cs

    r14046 r14128  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Encodings.PermutationEncoding;
    2526using HeuristicLab.Operators;
    2627using HeuristicLab.Optimization;
     
    3637      get { return false; }
    3738    }
    38     public ILookupParameter<PackingSequenceEncoding> PackingSequenceParameter {
    39       get { return (ILookupParameter<PackingSequenceEncoding>)Parameters["PackingSequence"]; }
     39    public ILookupParameter<Permutation> PackingSequenceParameter {
     40      get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; }
    4041    }
    41     public ILookupParameter<IPackingMove> PackingMoveParameter {
    42       get { return (LookupParameter<IPackingMove>)Parameters["PackingMove"]; }
     42    public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter {
     43      get { return (LookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; }
    4344    }
    4445    protected ScopeParameter CurrentScopeParameter {
     
    5152    public Swap2MoveGenerator()
    5253      : base() {
    53       Parameters.Add(new LookupParameter<PackingSequenceEncoding>("PackingSequence", "The Sequence vector for which moves should be generated."));
    54       Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The moves that should be generated in subscopes."));
     54      Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The Sequence vector for which moves should be generated."));
     55      Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The moves that should be generated in subscopes."));
    5556      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    5657    }
    5758
    5859    public override IOperation Apply() {
    59       PackingSequenceEncoding ps = PackingSequenceParameter.ActualValue;
     60      Permutation ps = PackingSequenceParameter.ActualValue;
    6061      Swap2Move[] moves = GenerateMoves(ps);
    6162      Scope[] moveScopes = new Scope[moves.Length];
     
    6869    }
    6970
    70     protected abstract Swap2Move[] GenerateMoves(PackingSequenceEncoding PackingSequence);
     71    protected abstract Swap2Move[] GenerateMoves(Permutation packingSequence);
    7172  }
    7273}
Note: See TracChangeset for help on using the changeset viewer.