Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/17 15:25:11 (7 years ago)
Author:
abeham
Message:

#2762: integrated bin packing extension into trunk

Location:
trunk/sources/HeuristicLab.Problems.BinPacking
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.BinPacking

  • trunk/sources/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs

    r14916 r15230  
    8888      };
    8989
    90       int epIndex = 0;
    91       while (epIndex < ExtremePoints.Count && (!IsPositionFeasible(rotatedItem, ExtremePoints.ElementAt(epIndex)))) { epIndex++; }
    92 
    93       if (epIndex < ExtremePoints.Count) {
    94         var currentPoint = ExtremePoints.ElementAt(epIndex);
    95 
    96         var result = new PackingPosition(currentPoint.AssignedBin, currentPoint.X, currentPoint.Y, rotated);
     90      var ep = ExtremePoints.Where(x => IsPositionFeasible(rotatedItem, x, stackingConstraints)).FirstOrDefault();
     91      if (ep != null) {
     92        var result = new PackingPosition(ep.AssignedBin, ep.X, ep.Y, rotated);
    9793        return result;
    9894      }
    9995      return null;
    10096    }
    101     public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
     97    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated, bool stackingConstraints) {
    10298      PackingPosition currentPosition = new PackingPosition(0,
    10399        BinShape.Width - (rotated ? item.Height : item.Width),
    104100        BinShape.Height - (rotated ? item.Width : item.Height), rotated);
    105101      //Slide the item as far as possible to the left
    106       while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
    107         || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))) {
     102      while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
     103        || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) {
    108104        //Slide the item as far as possible to the bottom
    109         while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))) {
     105        while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) {
    110106          currentPosition = PackingPosition.MoveDown(currentPosition);
    111107        }
    112         if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)))
     108        if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints))
    113109          currentPosition = PackingPosition.MoveLeft(currentPosition);
    114110      }
    115111
    116       return IsPositionFeasible(item, currentPosition) ? currentPosition : null;
    117     }
    118 
    119     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) {
     112      return IsPositionFeasible(item, currentPosition, stackingConstraints) ? currentPosition : null;
     113    }
     114
     115    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) {
    120116      var temp = new List<int>(sequence);
    121117      for (int i = 0; i < temp.Count; i++) {
    122118        var item = items[temp[i]];
    123         var position = FindPositionBySliding(item, false);
     119        var position = FindPositionBySliding(item, false, stackingConstraints);
    124120        if (position != null) {
    125121          PackItem(temp[i], item, position);
     
    128124      }
    129125    }
    130     public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) {
     126    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints) {
    131127      var temp = new List<int>(sequence);
    132128      for (int i = 0; i < temp.Count; i++) {
    133129        var item = items[temp[i]];
    134         var position = FindPositionBySliding(item, rotationArray[temp[i]]);
     130        var position = FindPositionBySliding(item, rotationArray[temp[i]], stackingConstraints);
    135131        if (position != null) {
    136132          PackItem(temp[i], item, position);
     
    150146      }
    151147    }
     148   
    152149    public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
    153150      var temp = new List<int>(sequence);
     
    186183      throw new NotSupportedException();
    187184    }
    188 
    189185    protected override void InitializeOccupationLayers() {
    190186      for (int i = 0; i * 10 <= BinShape.Width; i += 1) {
Note: See TracChangeset for help on using the changeset viewer.