Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/16 15:08:21 (8 years ago)
Author:
gkronber
Message:

#1966: refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/BinPacking2D.cs

    r14151 r14154  
    3232  public class BinPacking2D : BinPacking.BinPacking<PackingPosition, PackingShape, PackingItem> {
    3333
    34     public BinPacking2D(PackingShape binMeasures)
    35       : base(binMeasures) {
     34    public BinPacking2D(PackingShape binShape)
     35      : base(binShape) {
    3636      ExtremePoints = new SortedSet<PackingPosition>(new EPComparer2D());
    37       ExtremePoints.Add(binMeasures.Origin);
    38     }
     37      ExtremePoints.Add(binShape.Origin);
     38      InitializeOccupationLayers();
     39    }
     40
    3941    [StorableConstructor]
    4042    protected BinPacking2D(bool deserializing) : base(deserializing) { }
    4143    protected BinPacking2D(BinPacking2D original, Cloner cloner)
    4244      : base(original, cloner) {
    43       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints, new EPComparer2D());
     45      this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer2D());
    4446    }
    4547    public override IDeepCloneable Clone(Cloner cloner) {
     
    5456      //Find ExtremePoints beginning from sourcepointX
    5557      var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y);
    56       if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) {
     58      if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height) {
    5759        //Traversing down the y-axis       
    5860        var newPoint = new PackingPosition(0, sourcePointX.X, sourcePointX.Y - 1);
     
    6668      //Find ExtremePoints beginning from sourcepointY
    6769      var sourcePointY = new PackingPosition(0, position.X, position.Y + newHeight);
    68       if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) {
     70      if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height) {
    6971        //Traversing down the x-axis 
    7072        var newPoint = new PackingPosition(0, sourcePointY.X - 1, sourcePointY.Y);
     
    9698    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
    9799      PackingPosition currentPosition = new PackingPosition(0,
    98         BinMeasures.Width - (rotated ? item.Height : item.Width),
    99         BinMeasures.Height - (rotated ? item.Width : item.Height), rotated);
     100        BinShape.Width - (rotated ? item.Height : item.Width),
     101        BinShape.Height - (rotated ? item.Width : item.Height), rotated);
    100102      //Slide the item as far as possible to the left
    101103      while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
     
    159161    public override int ShortestPossibleSideFromPoint(PackingPosition position) {
    160162      int shortestSide = int.MaxValue;
    161       int width = BinMeasures.Width;
    162       int height = BinMeasures.Height;
     163      int width = BinShape.Width;
     164      int height = BinShape.Height;
    163165
    164166      if (position.X >= width || position.Y >= height)
     
    182184    }
    183185
    184 
    185186    protected override void InitializeOccupationLayers() {
    186       for (int i = 0; i * 10 <= BinMeasures.Width; i += 1) {
     187      for (int i = 0; i * 10 <= BinShape.Width; i += 1) {
    187188        OccupationLayers[i] = new List<int>();
    188189      }
    189190    }
    190     protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) {
     191
     192    protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) {
    191193      int x1 = position.X / 10;
    192       int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     194      int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10;
    193195
    194196      for (int i = x1; i <= x2; i++)
     
    198200      return OccupationLayers[position.X / 10];
    199201    }
    200     protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {
     202    protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) {
    201203      List<int> result = new List<int>();
    202204      int x1 = position.X / 10;
    203       int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     205      int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10;
    204206
    205207      for (int i = x1; i <= x2; i++)
Note: See TracChangeset for help on using the changeset viewer.