Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/09/18 15:46:53 (7 years ago)
Author:
rhanghof
Message:

#2817:

  • Bugfixes for the line projection based extreme point creation
  • Bugfixes for the tests
Location:
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation
Files:
2 edited

Legend:

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

    r15554 r15585  
    2020
    2121    /// <summary>
    22     /// Updates the residual space for a given bin packing
     22    /// Updates the residual space for a given bin packing.
    2323    /// </summary>
    2424    /// <param name="binPacking"></param>
     
    2626    /// <param name="position"></param>
    2727    protected abstract void UpdateResidualSpace(BinPacking3D binPacking, PackingItem item, PackingPosition position);
     28
     29    /// <summary>
     30    /// Adds an extreme point to the bin packing.
     31    /// </summary>
     32    /// <param name="binPacking"></param>
     33    /// <param name="position"></param>
     34    /// <returns></returns>
    2835    protected abstract bool AddExtremePoint(BinPacking3D binPacking, PackingPosition position);
    2936
     
    214221
    215222    /// <summary>
    216     /// Returns true, if the given poisition and the related residual space is within the residual space of the given extreme point
    217     /// </summary>
    218     /// <param name="pos"></param>
     223    /// Returns true, if the given poisition (pos) and the related residual space is within any residual space of the given extreme point (ep).
     224    /// </summary>
     225    /// <param name="pos">Given poisition</param>
    219226    /// <param name="rsPos"></param>
    220     /// <param name="ep"></param>
     227    /// <param name="ep">Given extreme point</param>
    221228    /// <param name="rsEp"></param>
    222229    /// <returns></returns>
     
    226233
    227234    /// <summary>
    228     /// Returns true, if the given poisition and the related residual space is within the residual space of the given extreme point
    229     /// </summary>
    230     /// <param name="pos"></param>
     235    /// Returns true, if the given poisition (pos) and the related residual space is within the residual space of the given extreme point (ep).
     236    /// </summary>
     237    /// <param name="pos">Given poisition</param>
    231238    /// <param name="rsPos"></param>
    232     /// <param name="ep"></param>
     239    /// <param name="ep">Given extreme point</param>
    233240    /// <param name="rsEp"></param>
    234241    /// <returns></returns>
    235242    protected virtual bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, ResidualSpace rsPos, PackingPosition ep, ResidualSpace rsEp) {
     243      /*old implementation
    236244      return rsEp.Width >= pos.X - ep.X + rsPos.Width
    237245          && rsEp.Height >= pos.Y - ep.Y + rsPos.Height
    238           && rsEp.Depth >= pos.Z - ep.Z + rsPos.Depth;
     246          && rsEp.Depth >= pos.Z - ep.Z + rsPos.Depth;*/
     247
     248      var x = pos.X >= ep.X && pos.X + rsPos.Width <= ep.X + rsEp.Width;
     249      var y = pos.Y >= ep.Y && pos.Y + rsPos.Height <= ep.Y + rsEp.Height;
     250      var z = pos.Z >= ep.Z && pos.Z + rsPos.Depth <= ep.Z + rsEp.Depth;
     251
     252      return x && y && z;
    239253    }
    240254
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/LineProjectionBasedEPCreator.cs

    r15554 r15585  
    2323        GenerateNewExtremePointsForItem(binPacking, it, p);
    2424      }
    25     }
    26 
    27     /// <summary>
    28     /// Adds a new extreme point an the related residual spaces to a given bin packing.
    29     /// - The given position has to be valid.
    30     /// - The extreme point does not exist in the bin packing.
    31     /// - There must be at minimum one valid residual space. A residual space is invalid if the space is zero.
    32     /// </summary>
    33     /// <param name="binPacking"></param>
    34     /// <param name="position"></param>
    35     /// <returns>True = the given point and its related residual spaces were successfully added to the bin packing</returns>
    36     protected override bool AddExtremePoint(BinPacking3D binPacking, PackingPosition position) {
    37       if (position == null) {
    38         return false;
    39       }
    40 
    41       if (PointIsInAnyItem(binPacking, new Vector3D(position))) {
    42         return false;
    43       }
    44 
    45       if (binPacking.ExtremePoints.ContainsKey(position)) {
    46         return false;
    47       }
    48 
    49       var rs = CalculateResidualSpace(binPacking, new Vector3D(position));
    50 
    51       if (rs.Count() <= 0) {
    52         return false;
    53       }
    54 
    55       // todo
    56       /*
    57        ist der extrempunkt im residual space eines anderen muss ueberprueft werden:
    58           - ist der andere ep in der luft, kann auch dieser hinzugefuegt werden.
    59           - hat der andere ep ein item unterhalb, darf dieser nicht hinzugefuegt werden.
    60        -> neu methode basierend auf IsWithinResidualSpaceOfAnotherExtremePoint, die den ep oder rs zurueck gibt, der einen anderen rs einschließt.
    61           eventuell gehoert diese logik in den ResidualSpaceCreator.
    62       if (LiesOnAnyItem(binPacking, position)) {
    63         return false;
    64       }*/
    65 
    66       binPacking.ExtremePoints.Add(position, rs);
    67       return true;
    68     }
    69 
     25     
     26      // remove not needed extreme points.
     27      foreach (var extremePoint in binPacking.ExtremePoints.ToList()) {
     28        // check if a residual space can be removed
     29        foreach (var rs in extremePoint.Value.ToList()) {
     30          if (ResidualSpaceCanBeRemoved(binPacking, extremePoint.Key, rs)) {
     31            ((IList<ResidualSpace>)extremePoint.Value).Remove(rs);
     32          }
     33        }
     34        // if the current extreme point has no more residual spaces, it can be removed.
     35        if (((IList<ResidualSpace>)extremePoint.Value).Count <= 0) {
     36          binPacking.ExtremePoints.Remove(extremePoint);
     37        }
     38      }
     39    }
     40   
     41    /// <summary>
     42    /// Returns true if a given residual space can be removed.
     43    /// The given residual space can be removed if it is within another residual space and
     44    /// - neither the position of the other residual space and the current extreme point have an item below or
     45    /// - the current extreme point has an item below.
     46    /// </summary>
     47    /// <param name="binPacking"></param>
     48    /// <param name="position"></param>
     49    /// <param name="rs"></param>
     50    /// <returns></returns>
     51    private bool ResidualSpaceCanBeRemoved(BinPacking3D binPacking, PackingPosition position, ResidualSpace rs) {
     52      foreach (var extremePoint in binPacking.ExtremePoints) {
     53        if (position.Equals(extremePoint.Key)) {
     54          continue;
     55        }
     56        if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(position), rs, extremePoint.Key, extremePoint.Value)) {
     57          var itemBelowEp = LiesOnAnyItem(binPacking, extremePoint.Key);
     58          var itemBelowPos = LiesOnAnyItem(binPacking, position);
     59
     60          if (itemBelowEp || !itemBelowEp && !itemBelowPos) {
     61            return true;
     62          }         
     63        }
     64      }
     65      return false;
     66    }
     67   
     68    /// <summary>
     69    /// Returns true if the given position lies on an item or an the ground.
     70    /// </summary>
     71    /// <param name="binPacking"></param>
     72    /// <param name="position"></param>
     73    /// <returns></returns>
    7074    private bool LiesOnAnyItem(BinPacking3D binPacking, PackingPosition position) {
    7175      if (position.Y == 0) {
     
    8589
    8690      return items.Count() > 0;
     91    }
     92
     93
     94    /// <summary>
     95    /// Adds a new extreme point an the related residual spaces to a given bin packing.
     96    /// - The given position has to be valid.
     97    /// - The extreme point does not exist in the bin packing.
     98    /// - There must be at minimum one valid residual space. A residual space is invalid if the space is zero.
     99    /// </summary>
     100    /// <param name="binPacking"></param>
     101    /// <param name="position"></param>
     102    /// <returns>True = the given point and its related residual spaces were successfully added to the bin packing</returns>
     103    protected override bool AddExtremePoint(BinPacking3D binPacking, PackingPosition position) {
     104      if (position == null) {
     105        return false;
     106      }
     107
     108      if (PointIsInAnyItem(binPacking, new Vector3D(position))) {
     109        return false;
     110      }
     111
     112      if (binPacking.ExtremePoints.ContainsKey(position)) {
     113        return false;
     114      }
     115
     116      var rs = CalculateResidualSpace(binPacking, new Vector3D(position));
     117
     118      if (rs.Count() <= 0) {
     119        return false;
     120      }
     121
     122      binPacking.ExtremePoints.Add(position, rs);
     123      return true;
    87124    }
    88125
Note: See TracChangeset for help on using the changeset viewer.