Free cookie consent management tool by TermsFeed Policy Generator

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

#2762:

  • Implemented review comments
  • Fixed ResidualSpaceBestFitExtremePointPermutationDecoder by sorting from smallest to largest (merit function should be minimized)
  • Some restructuring of the methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs

    r15182 r15229  
    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    }
    152     public override bool ExtremePointBasedPacking(int itemID, IList<PackingItem> items, bool stackingConstraints) {
    153       var item = items[itemID];
    154       var positionFound = FindExtremePointForItem(item, false, stackingConstraints);
    155       if (positionFound != null) {
    156         PackItem(itemID, item, positionFound);
    157         return true;
    158       }
    159       return false;
    160     }
    161148   
    162149    public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
Note: See TracChangeset for help on using the changeset viewer.