Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/07/13 15:35:12 (11 years ago)
Author:
jhelm
Message:

#1966: Fixed a bug which caused the stacking-contraint to be wrongly enforced; Did some cleanup;

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs

    r9596 r9598  
    105105    }
    106106
     107
     108    public int PointOccupation(D position) {
     109      foreach (var ipEntry in ItemPositions) {
     110        if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position))
     111          return ipEntry.Key;
     112      }
     113      return -1;
     114    }
    107115    public bool IsPointOccupied(D position) {
    108116      foreach (var ipEntry in ItemPositions) {
     
    110118          return true;
    111119      }
    112 
    113120      return false;
    114121    }
    115122    public bool IsPositionFeasible(I currentItem, D position) {
    116       //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the item does not collide with another already packed item
     123      //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item
    117124      if (!BinMeasures.Encloses(position, currentItem))
    118125        return false;
     
    127134    public abstract int ShortestPossibleSideFromPoint (D position);
    128135    public abstract bool IsStaticStable (I item, D position);
    129    
    130     //public bool IsPositionFeasible1(I currentItem, D position) {
    131     //  if (!BinMeasures.Encloses(position, currentItem))
    132     //    return false;
    133 
    134     //  return OccupiedPoints.IsPositionFeasible (currentItem, position);
    135     //}
    136136  }   
    137137}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking2D.cs

    r9596 r9598  
    6262      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) {
    6363        //Traversing down the y-axis       
    64         while (sourcePointX.Y > 0 && !IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1))) {
     64        while (sourcePointX.Y > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1)))) {
    6565          sourcePointX.Y--;
    6666        }
     
    7575      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) {
    7676        //Traversing down the x-axis 
    77         while (sourcePointY.X > 0 && !IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y))) {
     77        while (sourcePointY.X > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y)))) {
    7878          sourcePointY.X--;
    7979        }
     
    166166    }
    167167
    168 
    169168    public override int ShortestPossibleSideFromPoint(TwoDimensionalPacking position) {
    170169      int shortestSide = int.MaxValue;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking3D.cs

    r9596 r9598  
    6161      var sourcePointX = new ThreeDimensionalPacking(0, position.X + newWidth, position.Y, position.Z);
    6262      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {
    63         //Traversing down the y-axis                                                                           
    64         int currentYValue = sourcePointX.Y;
    65         while (currentYValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, currentYValue, sourcePointX.Z))) {
    66           currentYValue--;
    67         }
    68         ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, currentYValue, sourcePointX.Z));
    69 
    70         //Traversing down the z-axis
    71         int currentZValue = sourcePointX.Z;
    72         while (currentZValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, sourcePointX.Y, currentZValue - 1))) {
    73           currentZValue--;
    74         }
    75         ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, currentZValue));
     63        //Traversing down the y-axis           
     64        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
     65        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown (current))) {
     66          current = ThreeDimensionalPacking.MoveDown(current);
     67        }
     68        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     69        while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     70          current = ThreeDimensionalPacking.MoveLeft(current);
     71        }
     72        ExtremePoints.Add(current);
     73
     74        //Traversing down the z-axis                 
     75        current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
     76        while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack (current))) {
     77          current = ThreeDimensionalPacking.MoveBack(current);
     78        }
     79        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     80        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     81          current = ThreeDimensionalPacking.MoveDown(current);
     82        }
     83        ExtremePoints.Add(current);
    7684      }
    7785
     
    8290      var sourcePointY = new ThreeDimensionalPacking(0, position.X, position.Y + newItem.Height, position.Z);
    8391      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {
    84         //Traversing down the x-axis 
    85         int currentXValue = sourcePointY.X;
    86         while (currentXValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointY.Y, sourcePointY.Z))) {
    87           currentXValue--;
    88         }
    89         ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointY.Y, sourcePointY.Z));
    90 
    91         //Traversing down the z-axis
    92         int currentZValue = sourcePointY.Z;
    93         while (currentZValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointY.X, sourcePointY.Y, currentZValue - 1))) {
    94           currentZValue--;
    95         }
    96         ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, currentZValue));
     92        //Traversing down the x-axis         
     93        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
     94        while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     95          current = ThreeDimensionalPacking.MoveLeft(current);
     96        }
     97        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     98        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     99          current = ThreeDimensionalPacking.MoveDown(current);
     100        }
     101        ExtremePoints.Add(current);
     102
     103        //Traversing down the z-axis                                                                   
     104        current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
     105        while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
     106          current = ThreeDimensionalPacking.MoveBack(current);
     107        }
     108        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     109        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     110          current = ThreeDimensionalPacking.MoveDown(current);
     111        }
     112        ExtremePoints.Add(current);
    97113      }
    98114
     
    104120      var sourcePointZ = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z + newDepth);
    105121      if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {
    106         //Traversing down the x-axis 
    107         int currentXValue = sourcePointZ.X;
    108         while (currentXValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointZ.Y, sourcePointZ.Z))) {
    109           currentXValue--;
    110         }
    111         ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointZ.Y, sourcePointZ.Z));
    112 
    113         //Traversing down the y-axis                                                                           
    114         int currentYValue = sourcePointZ.Y;
    115         while (currentYValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointZ.X, currentYValue, sourcePointZ.Z))) {
    116           currentYValue--;
    117         }
    118         ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointZ.X, currentYValue, sourcePointZ.Z));
     122        //Traversing down the x-axis                                                                             
     123        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
     124        while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     125          current = ThreeDimensionalPacking.MoveLeft(current);
     126        }
     127        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     128        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     129          current = ThreeDimensionalPacking.MoveDown(current);
     130        }
     131        ExtremePoints.Add(current);
     132
     133        //Traversing down the y-axis                                                                     
     134        current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
     135        while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     136          current = ThreeDimensionalPacking.MoveDown(current);
     137        }
     138        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     139        while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     140          current = ThreeDimensionalPacking.MoveLeft(current);
     141        }
     142        ExtremePoints.Add(current);
    119143      }
    120144
     
    122146        OrderBy(ep => ep.Z).
    123147        ThenBy(ep => ep.X).
    124         ThenBy(ep => ep.Y).
    125         ThenBy(ep => ShortestPossibleSideFromPoint(ep)));
     148        ThenBy(ep => ep.Y)//.ThenBy(ep => ShortestPossibleSideFromPoint(ep))
     149        );
    126150    }
    127151
     
    136160      int epIndex = 0;
    137161      while (epIndex < ExtremePoints.Count && (
    138         !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex)) || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex)))
     162        !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex))
     163        || !IsSupportedByAtLeastOnePoint(item, ExtremePoints.ElementAt(epIndex))
     164        || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex)))
     165        || (stackingConstraints && !IsWeightSupported(item, ExtremePoints.ElementAt(epIndex)))
    139166      )) { epIndex++; }
    140167
     
    146173      return null;
    147174    }
     175
    148176    public override ThreeDimensionalPacking FindPositionBySliding(CuboidPackingItem measures, bool rotated) {
    149177      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
     
    217245      }
    218246    }
    219    
    220 
    221     [Storable]
    222     private bool depthWasDoubled = false;
    223     public void DoubleDepth() {
    224       if (!depthWasDoubled) {
    225         var oldDepth = BinMeasures.Depth;
    226         BinMeasures.Depth = BinMeasures.Depth * 2;
    227         //OccupiedPoints.ChangeBinMeasures(BinMeasures);
    228         depthWasDoubled = true;
    229       }
    230     }
    231 
     247                                                   
    232248    public override int ShortestPossibleSideFromPoint(ThreeDimensionalPacking position) {
    233249
     
    265281
    266282      if (IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z))
    267         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width - 1, position.Y - 1, position.Z))
    268         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth - 1))
    269         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1)))
     283        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z))
     284        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth))
     285        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z + item.Depth)))
    270286        return true;
    271287
     
    290306      return false;
    291307    }
     308
     309
     310    [Storable]
     311    private bool depthWasDoubled = false;
     312    public void DoubleDepth() {
     313      if (!depthWasDoubled) {
     314        var oldDepth = BinMeasures.Depth;
     315        BinMeasures.Depth = BinMeasures.Depth * 2;
     316        //OccupiedPoints.ChangeBinMeasures(BinMeasures);
     317        depthWasDoubled = true;
     318      }
     319    }
     320         
     321    public bool IsSupportedByAtLeastOnePoint(CuboidPackingItem item, ThreeDimensionalPacking position) {
     322      if (position.Y == 0)
     323        return true;
     324
     325      int y = position.Y - 1;
     326      for (int x = position.X; x < position.X + item.Width; x++)
     327        for (int z = position.Z; z < position.Z + item.Depth; z++)
     328          if (IsPointOccupied(new ThreeDimensionalPacking(0, x, y, z)))
     329            return true;
     330     
     331      return false;
     332    }
     333    public bool IsWeightSupported(CuboidPackingItem item, ThreeDimensionalPacking ep) {
     334      if (ep.Y == 0)
     335        return true;
     336
     337      if (ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
     338        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z))].SupportsStacking(item)
     339        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item)
     340        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item))
     341        return true;
     342
     343      return false;
     344    }
    292345  }
    293346}
Note: See TracChangeset for help on using the changeset viewer.