Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/17 23:45:08 (7 years ago)
Author:
abeham
Message:

#2817:

  • Added checkbox to control showing extreme points in visualization
    • Automatically determine size of extreme point cubes
  • Fixed some bugs in extreme point generation
File:
1 edited

Legend:

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

    r15306 r15307  
    125125      sourcePoint = new Vector3D(position.X, position.Y, position.Z + newDepth);
    126126      if (sourcePoint.X < BinShape.Width && sourcePoint.Y < BinShape.Height && sourcePoint.Z < BinShape.Depth) {
     127        // Projecting onto the XZ-plane
     128        var below = ProjectDown(sourcePoint);
     129        var residualSpace = CalculateResidualSpace(below);
     130        if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) {
     131          // add only if the projected point's residual space is not a sub-space
     132          // of another extreme point's residual space
     133          var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z);
     134          AddExtremePoint(belowPoint);
     135        }
    127136        // Projecting onto the YZ-plane
    128137        var left = ProjectLeft(sourcePoint);
    129         var residualSpace = CalculateResidualSpace(left);
     138        residualSpace = CalculateResidualSpace(left);
    130139        if (!IsWithinResidualSpaceOfAnotherExtremePoint(left, residualSpace)) {
    131140          // add only if the projected point's residual space is not a sub-space
     
    134143          AddExtremePoint(leftPoint);
    135144        }
    136         // Projecting onto the XZ-plane
    137         var below = ProjectDown(sourcePoint);
    138         residualSpace = CalculateResidualSpace(below);
    139         if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) {
    140           // add only if the projected point's residual space is not a sub-space
    141           // of another extreme point's residual space
    142           var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z);
    143           AddExtremePoint(belowPoint);
    144         }
    145145      }
    146146    }
     
    148148    private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> residualSpace) {
    149149      var eps = ExtremePoints.Where(x => pos.IsInside(x, ResidualSpace[x]));
    150       return eps.Any(x => ResidualSpace[x].Item1 >= pos.X - x.X + residualSpace.Item1
    151           && ResidualSpace[x].Item2 >= pos.Y - x.Y + residualSpace.Item2
    152           && ResidualSpace[x].Item3 >= pos.Z - x.Z + residualSpace.Item3);
     150      return eps.Any(x => IsWithinResidualSpaceOfAnotherExtremePoint(pos, residualSpace, x, ResidualSpace[x]));
     151    }
     152    private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> rsPos, PackingPosition ep, Tuple<int, int, int> rsEp) {
     153      return rsEp.Item1 >= pos.X - ep.X + rsPos.Item1
     154          && rsEp.Item2 >= pos.Y - ep.Y + rsPos.Item2
     155          && rsEp.Item3 >= pos.Z - ep.Z + rsPos.Item3;
    153156    }
    154157
    155158    private bool AddExtremePoint(PackingPosition pos) {
    156159      if (ExtremePoints.Add(pos)) {
    157         ResidualSpace.Add(pos, Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z));
     160        var rs = Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z);
     161        ResidualSpace.Add(pos, rs);
     162        // Check if existing extreme points are shadowed by the new point
     163        // That is, their residual space fit entirely into the residual space of the new point
     164        foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) {
     165          if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) {
     166            ExtremePoints.Remove(ep);
     167            ResidualSpace.Remove(ep);
     168          }
     169        }
    158170        return true;
    159171      }
Note: See TracChangeset for help on using the changeset viewer.