Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/14/17 15:31:22 (6 years ago)
Author:
rhanghof
Message:

#2817

  • Added some unit tests
  • Enhanced the documentation
File:
1 edited

Legend:

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

    r15462 r15471  
    6767    #region New methods for bin packer class
    6868
     69    /// <summary>
     70    /// Puts a given item into the bin packing at the given position.
     71    /// </summary>
     72    /// <param name="itemID">Offset in the internal item array</param>
     73    /// <param name="item">Item</param>
     74    /// <param name="position">Position of the item in the bin packing</param>
    6975    public override void PackItem(int itemID, PackingItem item, PackingPosition position) {
    7076      Items[itemID] = item;
     
    107113      AddExtremePoint(ep2);
    108114      AddExtremePoint(ep3);
    109 
    110       /*
    111       ExtremePoints.Add(ep1);
    112       ExtremePoints.Add(ep2);
    113       ExtremePoints.Add(ep3);
    114 
    115       var rs1 = CalculateResidualSpace(CreateRs(ep1));
    116       var rs2 = CalculateResidualSpace(CreateRs(ep2));
    117       var rs3 = CalculateResidualSpace(CreateRs(ep3));
    118       ResidualSpace.Add(ep1, rs1);
    119       ResidualSpace.Add(ep2, rs2);
    120       ResidualSpace.Add(ep3, rs3);*/
    121     }
    122 
    123 
    124     /*private bool AddExtremePoint(PackingPosition position) {
    125       if ()
    126 
    127       return true;
    128     }
    129 
    130    
    131     private bool AddExtremePoint(PackingPosition pos) {
    132       if (ExtremePoints.Add(pos)) {
    133         var rs = CalculateResidualSpace(new Vector3D(pos));
    134         ResidualSpace.Add(pos, rs);
    135         // Check if existing extreme points are shadowed by the new point
    136         // That is, their residual space fit entirely into the residual space of the new point
    137         foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) {
    138           if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) {
    139             ExtremePoints.Remove(ep);
    140             ResidualSpace.Remove(ep);
    141           }
    142         }
    143         return true;
    144       }
    145       return false;
    146     }*/
    147 
    148 
     115    }
     116       
    149117    private Tuple<int, int, int> CalculateResidualSpace(Vector3D pos) {
    150118      var itemPos = Items.Select(x => new { Item = x.Value, Position = Positions[x.Key] });
     
    164132        }
    165133      }
    166 
    167      
    168134     
    169135      if (limit.X - pos.X <= 0 || limit.Y - pos.Y <= 0  || limit.Z - pos.Z <= 0) {
    170136        return Tuple.Create(0, 0, 0);
    171       }
    172 
    173 
     137      }     
    174138      return Tuple.Create(limit.X - pos.X, limit.Y - pos.Y, limit.Z - pos.Z);
    175139    }
     
    491455    }
    492456
     457    /// <summary>
     458    /// Returns true if all values of a given tuple are not zero
     459    /// </summary>
     460    /// <param name="rs">Tuple with three integer values which represents a residual space</param>
     461    /// <returns></returns>
    493462    private bool IsNonZero(Tuple<int, int, int> rs) {
    494463      return rs.Item1 > 0 && rs.Item2 > 0 && rs.Item3 > 0;
    495464    }
    496465
     466    /// <summary>
     467    ///
     468    /// </summary>
     469    /// <param name="pos"></param>
     470    /// <param name="residualSpace"></param>
     471    /// <returns></returns>
    497472    private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> residualSpace) {
    498473      var eps = ExtremePoints.Where(x => !pos.Equals(x) && pos.IsInside(x, ResidualSpace[x]));
     
    505480    }
    506481
     482    /// <summary>
     483    /// Adds an extrem point to the extreme point collection of the bin packing.
     484    /// </summary>
     485    /// <param name="pos">Position of the new extreme point</param>
     486    /// <returns>Retruns true if the extreme point could be added</returns>
    507487    private bool AddExtremePoint(PackingPosition pos) {
    508488      if (ExtremePoints.Add(pos)) {
    509489        var rs = CalculateResidualSpace(new Vector3D(pos));
    510490        ResidualSpace.Add(pos, rs);
    511         // Check if existing extreme points are shadowed by the new point
    512         // That is, their residual space fit entirely into the residual space of the new point
     491        // Check if the existing extreme points are shadowed by the new point
     492        // This is, their residual space fit entirely into the residual space of the new point
    513493        foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) {
    514494          if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) {
     
    521501      return false;
    522502    }
    523 
    524     private Tuple<int, int, int> CalculateResidualSpace1(Vector3D pos) {
    525       var itemPos = Items.Select(x => new { Item = x.Value, Position = Positions[x.Key] });
    526       var rightLimit = ProjectRight(pos);
    527       var upLimit = ProjectUp(pos);
    528       var forwardLimit = ProjectForward(pos);
    529       return Tuple.Create(rightLimit.X - pos.X, upLimit.Y - pos.Y, forwardLimit.Z - pos.Z);
    530     }
    531 
     503       
    532504    #region Projections
    533505
     
    719691
    720692
     693    /// <summary>
     694    /// Updates the resiual space for a packing item.
     695    /// </summary>
     696    /// <param name="item"></param>
     697    /// <param name="pos"></param>
    721698    public void UpdateResidualSpace(PackingItem item, PackingPosition pos) {
    722699      foreach (var ep in ExtremePoints.ToList()) {
Note: See TracChangeset for help on using the changeset viewer.