Changeset 14154 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/BinPacking2D.cs
- Timestamp:
- 07/21/16 15:08:21 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/BinPacking2D.cs
r14151 r14154 32 32 public class BinPacking2D : BinPacking.BinPacking<PackingPosition, PackingShape, PackingItem> { 33 33 34 public BinPacking2D(PackingShape bin Measures)35 : base(bin Measures) {34 public BinPacking2D(PackingShape binShape) 35 : base(binShape) { 36 36 ExtremePoints = new SortedSet<PackingPosition>(new EPComparer2D()); 37 ExtremePoints.Add(binMeasures.Origin); 38 } 37 ExtremePoints.Add(binShape.Origin); 38 InitializeOccupationLayers(); 39 } 40 39 41 [StorableConstructor] 40 42 protected BinPacking2D(bool deserializing) : base(deserializing) { } 41 43 protected BinPacking2D(BinPacking2D original, Cloner cloner) 42 44 : base(original, cloner) { 43 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints , new EPComparer2D());45 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer2D()); 44 46 } 45 47 public override IDeepCloneable Clone(Cloner cloner) { … … 54 56 //Find ExtremePoints beginning from sourcepointX 55 57 var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y); 56 if (sourcePointX.X < Bin Measures.Width && sourcePointX.Y < BinMeasures.Height) {58 if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height) { 57 59 //Traversing down the y-axis 58 60 var newPoint = new PackingPosition(0, sourcePointX.X, sourcePointX.Y - 1); … … 66 68 //Find ExtremePoints beginning from sourcepointY 67 69 var sourcePointY = new PackingPosition(0, position.X, position.Y + newHeight); 68 if (sourcePointY.X < Bin Measures.Width && sourcePointY.Y < BinMeasures.Height) {70 if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height) { 69 71 //Traversing down the x-axis 70 72 var newPoint = new PackingPosition(0, sourcePointY.X - 1, sourcePointY.Y); … … 96 98 public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) { 97 99 PackingPosition currentPosition = new PackingPosition(0, 98 Bin Measures.Width - (rotated ? item.Height : item.Width),99 Bin Measures.Height - (rotated ? item.Width : item.Height), rotated);100 BinShape.Width - (rotated ? item.Height : item.Width), 101 BinShape.Height - (rotated ? item.Width : item.Height), rotated); 100 102 //Slide the item as far as possible to the left 101 103 while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)) … … 159 161 public override int ShortestPossibleSideFromPoint(PackingPosition position) { 160 162 int shortestSide = int.MaxValue; 161 int width = Bin Measures.Width;162 int height = Bin Measures.Height;163 int width = BinShape.Width; 164 int height = BinShape.Height; 163 165 164 166 if (position.X >= width || position.Y >= height) … … 182 184 } 183 185 184 185 186 protected override void InitializeOccupationLayers() { 186 for (int i = 0; i * 10 <= Bin Measures.Width; i += 1) {187 for (int i = 0; i * 10 <= BinShape.Width; i += 1) { 187 188 OccupationLayers[i] = new List<int>(); 188 189 } 189 190 } 190 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) { 191 192 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) { 191 193 int x1 = position.X / 10; 192 int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;194 int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10; 193 195 194 196 for (int i = x1; i <= x2; i++) … … 198 200 return OccupationLayers[position.X / 10]; 199 201 } 200 protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {202 protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) { 201 203 List<int> result = new List<int>(); 202 204 int x1 = position.X / 10; 203 int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;205 int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10; 204 206 205 207 for (int i = x1; i <= x2; i++)
Note: See TracChangeset
for help on using the changeset viewer.