[9348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[13032] | 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9348] | 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.Text;
|
---|
| 23 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[14046] | 26 | using HeuristicLab.Problems.BinPacking;
|
---|
[9348] | 27 |
|
---|
[14046] | 28 | namespace HeuristicLab.Problems.BinPacking2D {
|
---|
[9348] | 29 | [Item("Two Dimensional Packing", "Represents a packing-position associated with a two dimensional packing-problem.")]
|
---|
| 30 | [StorableClass]
|
---|
[13605] | 31 | // TwoDimensionalPacking is an immutable class (and handled as value type concerning Equals and GetHashCode())
|
---|
[9348] | 32 | public class TwoDimensionalPacking : PackingDimensions {
|
---|
[13605] | 33 | [Storable]
|
---|
| 34 | private readonly int x;
|
---|
| 35 | public int X { get { return x; } }
|
---|
[9348] | 36 |
|
---|
[13605] | 37 | [Storable]
|
---|
| 38 | private readonly int y;
|
---|
| 39 | public int Y { get { return y; } }
|
---|
| 40 |
|
---|
[9348] | 41 | [StorableConstructor]
|
---|
| 42 | protected TwoDimensionalPacking(bool deserializing) : base(deserializing) { }
|
---|
| 43 | protected TwoDimensionalPacking(TwoDimensionalPacking original, Cloner cloner)
|
---|
| 44 | : base(original, cloner) {
|
---|
[13605] | 45 | x = original.X;
|
---|
| 46 | y = original.Y;
|
---|
[9348] | 47 | }
|
---|
[13605] | 48 |
|
---|
| 49 | public TwoDimensionalPacking(int assignedBin, int x, int y, bool rotated = false)
|
---|
| 50 | : base(assignedBin, rotated) {
|
---|
| 51 | this.x = x;
|
---|
| 52 | this.y = y;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[9348] | 55 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 56 | return new TwoDimensionalPacking(this, cloner);
|
---|
[9440] | 57 | }
|
---|
[13605] | 58 |
|
---|
[9348] | 59 | public override string ToString() {
|
---|
[13605] | 60 | return string.Format("[AssignedBin: {0}; ({1},{2})]", AssignedBin, x, y);
|
---|
[9348] | 61 | }
|
---|
[9440] | 62 |
|
---|
| 63 | public override bool Equals(object obj) {
|
---|
[13605] | 64 | var other = obj as TwoDimensionalPacking;
|
---|
| 65 | if (other != null)
|
---|
| 66 | return (other.X == this.X && other.Y == this.Y && base.Equals(other));
|
---|
[9440] | 67 | else return false;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public override int GetHashCode() {
|
---|
| 71 | return base.GetHashCode() + 13 * X + 17 * Y;
|
---|
| 72 | }
|
---|
[9596] | 73 |
|
---|
| 74 | public static TwoDimensionalPacking MoveLeft(TwoDimensionalPacking original) {
|
---|
| 75 | return new TwoDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Rotated);
|
---|
| 76 | }
|
---|
| 77 | public static TwoDimensionalPacking MoveDown(TwoDimensionalPacking original) {
|
---|
| 78 | return new TwoDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Rotated);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public static TwoDimensionalPacking MoveRight(TwoDimensionalPacking original) {
|
---|
| 82 | return new TwoDimensionalPacking(original.AssignedBin, original.X + 1, original.Y, original.Rotated);
|
---|
| 83 | }
|
---|
| 84 | public static TwoDimensionalPacking MoveUp(TwoDimensionalPacking original) {
|
---|
| 85 | return new TwoDimensionalPacking(original.AssignedBin, original.X, original.Y + 1, original.Rotated);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[9348] | 88 | }
|
---|
| 89 | }
|
---|