Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/12/16 19:54:35 (8 years ago)
Author:
gkronber
Message:

#1966: renamed *PackingDimension -> PackingPosition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/BinPacking3D.cs

    r14046 r14048  
    3030  [Item("BinPacking3D", "Represents a single-bin packing for a 3D bin-packing problem.")]
    3131  [StorableClass]
    32   public class BinPacking3D : BinPacking<ThreeDimensionalPacking, CuboidPackingShape, CuboidPackingItem> {
     32  public class BinPacking3D : BinPacking<PackingPosition, CuboidPackingShape, CuboidPackingItem> {
    3333
    3434    public BinPacking3D(CuboidPackingShape binMeasures)
    3535      : base(binMeasures) {
    36       ExtremePoints = new SortedSet<ThreeDimensionalPacking>(new EPComparer3D());
     36      ExtremePoints = new SortedSet<PackingPosition>(new EPComparer3D());
    3737      ExtremePoints.Add(binMeasures.Origin);
    3838    }
     
    4242      : base(original, cloner) {
    4343      this.depthWasDoubled = original.depthWasDoubled;
    44       this.ExtremePoints = new SortedSet<ThreeDimensionalPacking>(original.ExtremePoints, new EPComparer3D());
     44      this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints, new EPComparer3D());
    4545    }
    4646    public override IDeepCloneable Clone(Cloner cloner) {
     
    4848    }
    4949
    50     protected override void GenerateNewExtremePointsForNewItem(CuboidPackingItem newItem, ThreeDimensionalPacking position) {
     50    protected override void GenerateNewExtremePointsForNewItem(CuboidPackingItem newItem, PackingPosition position) {
    5151      int newWidth = position.Rotated ? newItem.Depth : newItem.Width;
    5252      int newDepth = position.Rotated ? newItem.Width : newItem.Depth;
    5353
    5454      //Find ExtremePoints beginning from sourcepointX
    55       var sourcePointX = new ThreeDimensionalPacking(0, position.X + newWidth, position.Y, position.Z);
     55      var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y, position.Z);
    5656      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {
    5757        //Traversing down the y-axis 
    58         ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
    59         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    60           current = ThreeDimensionalPacking.MoveDown(current);
    61         }
    62         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    63         while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    64           current = ThreeDimensionalPacking.MoveLeft(current);
     58        PackingPosition current = new PackingPosition(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
     59        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     60          current = PackingPosition.MoveDown(current);
     61        }
     62        ExtremePoints.Add((PackingPosition)current.Clone());
     63        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
     64          current = PackingPosition.MoveLeft(current);
    6565        }
    6666        ExtremePoints.Add(current);
    6767
    6868        //Traversing down the z-axis
    69         current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
    70         while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
    71           current = ThreeDimensionalPacking.MoveBack(current);
    72         }
    73         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    74         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    75           current = ThreeDimensionalPacking.MoveDown(current);
     69        current = new PackingPosition(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
     70        while (current.Z > 0 && !IsPointOccupied(PackingPosition.MoveBack(current))) {
     71          current = PackingPosition.MoveBack(current);
     72        }
     73        ExtremePoints.Add((PackingPosition)current.Clone());
     74        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     75          current = PackingPosition.MoveDown(current);
    7676        }
    7777        ExtremePoints.Add(current);
     
    8282
    8383      //Find ExtremePoints beginning from sourcepointY
    84       var sourcePointY = new ThreeDimensionalPacking(0, position.X, position.Y + newItem.Height, position.Z);
     84      var sourcePointY = new PackingPosition(0, position.X, position.Y + newItem.Height, position.Z);
    8585      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {
    8686        //Traversing down the x-axis         
    87         ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
    88         while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    89           current = ThreeDimensionalPacking.MoveLeft(current);
    90         }
    91         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    92         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    93           current = ThreeDimensionalPacking.MoveDown(current);
     87        PackingPosition current = new PackingPosition(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
     88        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
     89          current = PackingPosition.MoveLeft(current);
     90        }
     91        ExtremePoints.Add((PackingPosition)current.Clone());
     92        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     93          current = PackingPosition.MoveDown(current);
    9494        }
    9595        ExtremePoints.Add(current);
    9696
    9797        //Traversing down the z-axis                                                                   
    98         current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
    99         while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
    100           current = ThreeDimensionalPacking.MoveBack(current);
    101         }
    102         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    103         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    104           current = ThreeDimensionalPacking.MoveDown(current);
     98        current = new PackingPosition(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
     99        while (current.Z > 0 && !IsPointOccupied(PackingPosition.MoveBack(current))) {
     100          current = PackingPosition.MoveBack(current);
     101        }
     102        ExtremePoints.Add((PackingPosition)current.Clone());
     103        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     104          current = PackingPosition.MoveDown(current);
    105105        }
    106106        ExtremePoints.Add(current);
     
    112112
    113113      //Find ExtremePoints beginning from sourcepointZ
    114       var sourcePointZ = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z + newDepth);
     114      var sourcePointZ = new PackingPosition(0, position.X, position.Y, position.Z + newDepth);
    115115      if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {
    116116        //Traversing down the x-axis                                                                             
    117         ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
    118         while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    119           current = ThreeDimensionalPacking.MoveLeft(current);
    120         }
    121         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    122         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    123           current = ThreeDimensionalPacking.MoveDown(current);
     117        PackingPosition current = new PackingPosition(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
     118        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
     119          current = PackingPosition.MoveLeft(current);
     120        }
     121        ExtremePoints.Add((PackingPosition)current.Clone());
     122        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     123          current = PackingPosition.MoveDown(current);
    124124        }
    125125        ExtremePoints.Add(current);
    126126
    127127        //Traversing down the y-axis                                                                     
    128         current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
    129         while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    130           current = ThreeDimensionalPacking.MoveDown(current);
    131         }
    132         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    133         while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    134           current = ThreeDimensionalPacking.MoveLeft(current);
     128        current = new PackingPosition(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
     129        while (current.Y > 0 && !IsPointOccupied(PackingPosition.MoveDown(current))) {
     130          current = PackingPosition.MoveDown(current);
     131        }
     132        ExtremePoints.Add((PackingPosition)current.Clone());
     133        while (current.X > 0 && !IsPointOccupied(PackingPosition.MoveLeft(current))) {
     134          current = PackingPosition.MoveLeft(current);
    135135        }
    136136        ExtremePoints.Add(current);
     
    146146    }
    147147
    148     public override ThreeDimensionalPacking FindExtremePointForItem(CuboidPackingItem measures, bool rotated, bool stackingConstraints) {
     148    public override PackingPosition FindExtremePointForItem(CuboidPackingItem measures, bool rotated, bool stackingConstraints) {
    149149
    150150      CuboidPackingItem item = new CuboidPackingItem(
     
    164164      if (epIndex < ExtremePoints.Count) {
    165165        var origPoint = ExtremePoints.ElementAt(epIndex);
    166         var result = new ThreeDimensionalPacking(origPoint.AssignedBin, origPoint.X, origPoint.Y, origPoint.Z, rotated);
     166        var result = new PackingPosition(origPoint.AssignedBin, origPoint.X, origPoint.Y, origPoint.Z, rotated);
    167167        return result;
    168168      }
     
    170170    }
    171171
    172     public override ThreeDimensionalPacking FindPositionBySliding(CuboidPackingItem measures, bool rotated) {
     172    public override PackingPosition FindPositionBySliding(CuboidPackingItem measures, bool rotated) {
    173173      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
    174       ThreeDimensionalPacking currentPosition = new ThreeDimensionalPacking(0,
     174      PackingPosition currentPosition = new PackingPosition(0,
    175175        BinMeasures.Width - (rotated ? measures.Depth : measures.Width),
    176176        BinMeasures.Height - measures.Height,
    177177        BinMeasures.Depth - (rotated ? measures.Width : measures.Depth), rotated);
    178178      //Slide the item as far as possible to the bottom
    179       while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveDown(currentPosition))
    180         || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition))
    181         || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
     179      while (IsPositionFeasible(measures, PackingPosition.MoveDown(currentPosition))
     180        || IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition))
     181        || IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
    182182        //Slide the item as far as possible to the left
    183         while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition))
    184       || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
     183        while (IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition))
     184      || IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
    185185          //Slide the item as far as possible to the back
    186           while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
    187             currentPosition = ThreeDimensionalPacking.MoveBack(currentPosition);
     186          while (IsPositionFeasible(measures, PackingPosition.MoveBack(currentPosition))) {
     187            currentPosition = PackingPosition.MoveBack(currentPosition);
    188188          }
    189           if (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition)))
    190             currentPosition = ThreeDimensionalPacking.MoveLeft(currentPosition);
    191         }
    192         if (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveDown(currentPosition)))
    193           currentPosition = ThreeDimensionalPacking.MoveDown(currentPosition);
     189          if (IsPositionFeasible(measures, PackingPosition.MoveLeft(currentPosition)))
     190            currentPosition = PackingPosition.MoveLeft(currentPosition);
     191        }
     192        if (IsPositionFeasible(measures, PackingPosition.MoveDown(currentPosition)))
     193          currentPosition = PackingPosition.MoveDown(currentPosition);
    194194      }
    195195
     
    242242    }
    243243
    244     public override int ShortestPossibleSideFromPoint(ThreeDimensionalPacking position) {
     244    public override int ShortestPossibleSideFromPoint(PackingPosition position) {
    245245
    246246      int shortestSide = int.MaxValue;
     
    252252        return shortestSide;
    253253
    254       ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
    255       while (current.X < width && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveRight(current); }
     254      PackingPosition current = new PackingPosition(0, position.X, position.Y, position.Z);
     255      while (current.X < width && IsPointOccupied(current)) { current = PackingPosition.MoveRight(current); }
    256256      if (current.X - position.X < shortestSide)
    257257        shortestSide = current.X - position.X;
    258258
    259259
    260       current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
    261       while (current.Y < height && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveUp(current); }
     260      current = new PackingPosition(0, position.X, position.Y, position.Z);
     261      while (current.Y < height && IsPointOccupied(current)) { current = PackingPosition.MoveUp(current); }
    262262      if (current.Y - position.Y < shortestSide)
    263263        shortestSide = current.Y - position.Y;
    264264
    265265
    266       current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
    267       while (current.Z < depth && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveFront(current); }
     266      current = new PackingPosition(0, position.X, position.Y, position.Z);
     267      while (current.Z < depth && IsPointOccupied(current)) { current = PackingPosition.MoveFront(current); }
    268268      if (current.Z - position.Z < shortestSide)
    269269        shortestSide = current.Z - position.Z;
     
    271271      return shortestSide;
    272272    }
    273     public override bool IsStaticStable(CuboidPackingItem item, ThreeDimensionalPacking position) {
     273    public override bool IsStaticStable(CuboidPackingItem item, PackingPosition position) {
    274274      //Static stability is given, if item is placed on the ground
    275275      if (position.Y == 0)
    276276        return true;
    277277
    278       if (IsPointOccupied(new ThreeDimensionalPacking(0, position.X, position.Y - 1, position.Z))
    279         && IsPointOccupied(new ThreeDimensionalPacking(0, position.X + item.Width - 1, position.Y - 1, position.Z))
    280         && IsPointOccupied(new ThreeDimensionalPacking(0, position.X, position.Y - 1, position.Z + item.Depth - 1))
    281         && IsPointOccupied(new ThreeDimensionalPacking(0, position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1)))
     278      if (IsPointOccupied(new PackingPosition(0, position.X, position.Y - 1, position.Z))
     279        && IsPointOccupied(new PackingPosition(0, position.X + item.Width - 1, position.Y - 1, position.Z))
     280        && IsPointOccupied(new PackingPosition(0, position.X, position.Y - 1, position.Z + item.Depth - 1))
     281        && IsPointOccupied(new PackingPosition(0, position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1)))
    282282        return true;
    283283
     
    304304
    305305    [Storable]
    306     private bool depthWasDoubled = false;
     306    private bool depthWasDoubled = false; // TODO ???
    307307    public void DoubleDepth() {
    308308      if (!depthWasDoubled) {
     
    314314    }
    315315
    316     public bool IsSupportedByAtLeastOnePoint(CuboidPackingItem item, ThreeDimensionalPacking position) {
     316    public bool IsSupportedByAtLeastOnePoint(CuboidPackingItem item, PackingPosition position) {
    317317      if (position.Y == 0)
    318318        return true;
     
    321321      for (int x = position.X; x < position.X + item.Width; x++)
    322322        for (int z = position.Z; z < position.Z + item.Depth; z++)
    323           if (IsPointOccupied(new ThreeDimensionalPacking(0, x, y, z)))
     323          if (IsPointOccupied(new PackingPosition(0, x, y, z)))
    324324            return true;
    325325
    326326      return false;
    327327    }
    328     public bool IsWeightSupported(CuboidPackingItem item, ThreeDimensionalPacking ep) {
     328    public bool IsWeightSupported(CuboidPackingItem item, PackingPosition ep) {
    329329      if (ep.Y == 0)
    330330        return true;
    331331
    332       if (ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
    333         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)
    334         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)
    335         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))
     332      if (ItemMeasures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
     333        && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)
     334        && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)
     335        && ItemMeasures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))
    336336        return true;
    337337
     
    345345      }
    346346    }
    347     protected override void AddNewItemToOccupationLayers(int itemID, CuboidPackingItem measures, ThreeDimensionalPacking position) {
     347    protected override void AddNewItemToOccupationLayers(int itemID, CuboidPackingItem measures, PackingPosition position) {
    348348      int z1 = position.Z / 10;
    349349      int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
     
    352352        OccupationLayers[i].Add(itemID);
    353353    }
    354     protected override List<int> GetLayerItemIDs(ThreeDimensionalPacking position) {
     354    protected override List<int> GetLayerItemIDs(PackingPosition position) {
    355355      return OccupationLayers[position.Z / 10];
    356356    }
    357     protected override List<int> GetLayerItemIDs(CuboidPackingItem measures, ThreeDimensionalPacking position) {
     357    protected override List<int> GetLayerItemIDs(CuboidPackingItem measures, PackingPosition position) {
    358358      List<int> result = new List<int>();
    359359      int z1 = position.Z / 10;
     
    366366    }
    367367  }
    368   public class EPComparer3D : IComparer<ThreeDimensionalPacking> {
    369     public int Compare(ThreeDimensionalPacking a, ThreeDimensionalPacking b) {
     368  public class EPComparer3D : IComparer<PackingPosition> {
     369    public int Compare(PackingPosition a, PackingPosition b) {
    370370      int result = a.Z.CompareTo(b.Z);
    371371      if (result == 0)
Note: See TracChangeset for help on using the changeset viewer.