[9593] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Common;
|
---|
| 30 | using HeuristicLab.Problems.BinPacking.Shapes;
|
---|
| 31 | using HeuristicLab.Problems.BinPacking.PackingItem;
|
---|
| 32 | using HeuristicLab.Problems.BinPacking.PackingBin;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.BinPacking.Dimensions {
|
---|
| 35 | [Item("Occupated Points 2D", "A datastructure holding all currently occupied points of a 2D packing-bin.")]
|
---|
| 36 | [StorableClass]
|
---|
[9596] | 37 | public class OccupiedPoints2D : OccupiedPoints<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> {
|
---|
[9593] | 38 |
|
---|
| 39 | [Storable]
|
---|
| 40 | private int[,] occupiedPoints { get; set; }
|
---|
| 41 |
|
---|
[9596] | 42 | public OccupiedPoints2D(RectangularPackingBin binMeasures) : base(binMeasures) {
|
---|
[9593] | 43 | occupiedPoints = new int[binMeasures.Width, binMeasures.Height];
|
---|
| 44 | for (int w = 0; w < binMeasures.Width; w++) {
|
---|
| 45 | for (int h = 0; h < binMeasures.Height; h++) {
|
---|
| 46 | occupiedPoints[w, h] = -1;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | [StorableConstructor]
|
---|
| 51 | protected OccupiedPoints2D(bool deserializing) : base(deserializing) { }
|
---|
| 52 | protected OccupiedPoints2D(OccupiedPoints2D original, Cloner cloner)
|
---|
| 53 | : base(original, cloner) {
|
---|
| 54 | this.occupiedPoints = (int[,])original.occupiedPoints.Clone();
|
---|
| 55 | }
|
---|
| 56 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 57 | return new OccupiedPoints2D(this, cloner);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public override bool IsPositionFeasible(RectangularPackingItem measures, TwoDimensionalPacking position) {
|
---|
| 61 | for (int w = position.X; w < position.X + measures.Width; w++) {
|
---|
| 62 | for (int h = position.Y; h < position.Y + measures.Height; h++) {
|
---|
| 63 | if (occupiedPoints[w, h] != -1)
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | return true;
|
---|
| 68 | }
|
---|
| 69 | public override void OccupyPoints(RectangularPackingItem measures, TwoDimensionalPacking position, int itemID) {
|
---|
| 70 | int width = position.Rotated ? measures.Height : measures.Width;
|
---|
| 71 | int height = position.Rotated ? measures.Width : measures.Height;
|
---|
| 72 | for (int w = position.X; w < position.X + width; w++) {
|
---|
| 73 | for (int h = position.Y; h < position.Y + height; h++) {
|
---|
| 74 | occupiedPoints[w, h] = itemID;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | public override bool IsPointOccupied(TwoDimensionalPacking point) {
|
---|
| 79 | return occupiedPoints[point.X, point.Y] != -1;
|
---|
| 80 | }
|
---|
| 81 | public override int ShortestPossibleSideFromEP(TwoDimensionalPacking ep) {
|
---|
| 82 | int shortestSide = int.MaxValue;
|
---|
| 83 | int width = occupiedPoints.GetLength(0);
|
---|
| 84 | int height = occupiedPoints.GetLength(1);
|
---|
| 85 |
|
---|
| 86 | if (ep.X >= width || ep.Y >= height)
|
---|
| 87 | return shortestSide;
|
---|
| 88 |
|
---|
| 89 | int currentX = ep.X;
|
---|
| 90 | while (currentX < width && occupiedPoints[currentX, ep.Y] == -1) { currentX++; }
|
---|
| 91 | if (currentX - ep.X < shortestSide)
|
---|
| 92 | shortestSide = currentX - ep.X;
|
---|
| 93 |
|
---|
| 94 | int currentY = ep.Y;
|
---|
| 95 | while (currentY < height && occupiedPoints[ep.X, currentY] == -1) { currentY++; }
|
---|
| 96 | if (currentY - ep.Y < shortestSide)
|
---|
| 97 | shortestSide = currentY - ep.Y;
|
---|
| 98 |
|
---|
| 99 | return shortestSide;
|
---|
| 100 | }
|
---|
| 101 | public override bool IsStaticStable(RectangularPackingItem item, TwoDimensionalPacking ep) {
|
---|
| 102 | //For the current implementation there was no need for stacking-constraints in the 2D-case.
|
---|
| 103 | //But it could be interesting for shelf-packing applications!
|
---|
[9596] | 104 | throw new NotImplementedException();
|
---|
[9593] | 105 | }
|
---|
| 106 | public override bool WeightIsSupported(RectangularPackingItem item, TwoDimensionalPacking ep, ItemList<RectangularPackingItem> items) {
|
---|
| 107 | return true;
|
---|
| 108 | }
|
---|
[9596] | 109 | public override void ChangeBinMeasures(RectangularPackingBin binMeasures) {
|
---|
| 110 | throw new NotImplementedException();
|
---|
| 111 | }
|
---|
[9593] | 112 | }
|
---|
| 113 | }
|
---|