Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/13/17 12:25:57 (7 years ago)
Author:
abeham
Message:

#2820: fixed bugs

File:
1 edited

Legend:

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

    r15276 r15325  
    6464    }
    6565
    66     public override void PackItem(int itemID, PackingItem item, PackingPosition position) {
     66    public override void PackItem(int itemID, PackingItem item, PackingPosition position) {// base call is deliberately omitted, because UpdateResidualSpace needs to be fitted in before
     67      // base call is deliberately omitted, because UpdateResidualSpace needs to be fitted in before
     68      Items[itemID] = item;
     69      Positions[itemID] = position;
     70      ExtremePoints.Remove(position);
    6771      ResidualSpace.Remove(position);
    68       base.PackItem(itemID, item, position);
     72      UpdateResidualSpace(item, position);
     73      foreach (int id in Items.Select(x => x.Key))
     74        GenerateNewExtremePointsForNewItem(Items[id], Positions[id]);
     75
     76      AddNewItemToOccupationLayers(itemID, item, position);
    6977    }
    7078
     
    237245        if (positionFound != null) {
    238246          PackItem(itemID, item, positionFound);
    239           if (Items.Count > 1)
    240             UpdateResidualSpace(item, positionFound);
    241247          sequence.Remove(itemID);
    242248        }
     
    350356    public void UpdateResidualSpace(PackingItem item, PackingPosition pos) {
    351357      foreach (var ep in ExtremePoints) {
    352         if (ep.Z >= pos.Z && ep.Z <= pos.Z + item.Depth) {
    353           if (ep.X <= pos.X && ep.Y > pos.Y && ep.Y < pos.Y + item.Height) {
     358        var rs = ResidualSpace[ep];
     359        var depth = pos.Rotated ? item.Width : item.Depth;
     360        var width = pos.Rotated ? item.Depth : item.Width;
     361        if (ep.Z >= pos.Z && ep.Z < pos.Z + depth) {
     362          if (ep.X <= pos.X && ep.Y >= pos.Y && ep.Y < pos.Y + item.Height) {
    354363            var diff = pos.X - ep.X;
    355             var newRSX = ResidualSpace[ep].Item1 < diff ? ResidualSpace[ep].Item1 : diff;
    356             ResidualSpace[ep] = Tuple.Create(newRSX, ResidualSpace[ep].Item2, ResidualSpace[ep].Item3);
     364            var newRSX = Math.Min(rs.Item1, diff);
     365            ResidualSpace[ep] = Tuple.Create(newRSX, rs.Item2, rs.Item3);
    357366          }
    358           if (ep.Y <= pos.Y && ep.X > pos.X && ep.X < pos.X + item.Width) {
     367          if (ep.Y <= pos.Y && ep.X >= pos.X && ep.X < pos.X + width) {
    359368            var diff = pos.Y - ep.Y;
    360             var newRSY = ResidualSpace[ep].Item2 < diff ? ResidualSpace[ep].Item2 : diff;
    361             ResidualSpace[ep] = Tuple.Create(ResidualSpace[ep].Item1, newRSY, ResidualSpace[ep].Item3);
     369            var newRSY = Math.Min(rs.Item2, diff);
     370            ResidualSpace[ep] = Tuple.Create(rs.Item1, newRSY, rs.Item3);
    362371          }
    363372        }
    364         if (ep.Z <= pos.Z && 
    365           ep.Y > pos.Y && ep.Y < pos.Y + item.Height &&
    366           ep.X > pos.X && ep.X < pos.X + item.Width) {
    367             var diff = pos.Z - ep.Z;
    368             var newRSZ = ResidualSpace[ep].Item3 < diff ? ResidualSpace[ep].Item3 : diff;
    369             ResidualSpace[ep] = Tuple.Create(ResidualSpace[ep].Item1, ResidualSpace[ep].Item2, newRSZ);
     373        if (ep.Z <= pos.Z &&
     374          ep.Y >= pos.Y && ep.Y < pos.Y + item.Height &&
     375          ep.X >= pos.X && ep.X < pos.X + width) {
     376          var diff = pos.Z - ep.Z;
     377          var newRSZ = Math.Min(rs.Item3, diff);
     378          ResidualSpace[ep] = Tuple.Create(rs.Item1, rs.Item2, newRSZ);
    370379        }
    371380      }
Note: See TracChangeset for help on using the changeset viewer.