[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;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Problems.BinPacking.Dimensions {
|
---|
| 28 | [Item("Three Dimensional Packing", "Represents a packing-position associated with a three dimensional packing-problem.")]
|
---|
| 29 | [StorableClass]
|
---|
[13605] | 30 | // ThreeDimensionalPacking is immutable (and handled as value type concerning Equals and GetHashCode)
|
---|
| 31 | public class ThreeDimensionalPacking : PackingDimensions {
|
---|
| 32 | [Storable]
|
---|
| 33 | private readonly int x;
|
---|
| 34 | [Storable]
|
---|
| 35 | private readonly int y;
|
---|
| 36 | [Storable]
|
---|
| 37 | private readonly int z;
|
---|
[9348] | 38 |
|
---|
[13605] | 39 | public int X { get { return x; } }
|
---|
| 40 | public int Y { get { return y; } }
|
---|
| 41 | public int Z { get { return z; } }
|
---|
| 42 |
|
---|
[9348] | 43 | [StorableConstructor]
|
---|
| 44 | protected ThreeDimensionalPacking(bool deserializing) : base(deserializing) { }
|
---|
| 45 | protected ThreeDimensionalPacking(ThreeDimensionalPacking original, Cloner cloner)
|
---|
| 46 | : base(original, cloner) {
|
---|
[13605] | 47 | x = original.X;
|
---|
| 48 | y = original.Y;
|
---|
| 49 | z = original.Z;
|
---|
[9348] | 50 | }
|
---|
| 51 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 52 | return new ThreeDimensionalPacking(this, cloner);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[13605] | 55 | public ThreeDimensionalPacking(int assignedBin, int x, int y, int z, bool rotated = false)
|
---|
[9440] | 56 | : base(assignedBin, rotated) {
|
---|
[13605] | 57 | this.x = x;
|
---|
| 58 | this.y = y;
|
---|
| 59 | this.z = z;
|
---|
[9348] | 60 | }
|
---|
[13605] | 61 |
|
---|
[9348] | 62 | public override string ToString() {
|
---|
[13605] | 63 | return string.Format("[AssignedBin: {0}; ({1},{2},{3})]", AssignedBin, X, Y, Z);
|
---|
[9348] | 64 | }
|
---|
[9440] | 65 |
|
---|
| 66 |
|
---|
| 67 | public override bool Equals(object obj) {
|
---|
| 68 | var tdp = obj as ThreeDimensionalPacking;
|
---|
| 69 | if (tdp != null)
|
---|
| 70 | return (tdp.X == this.X && tdp.Y == this.Y && tdp.Z == this.Z);
|
---|
| 71 | else return false;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public override int GetHashCode() {
|
---|
| 75 | return base.GetHashCode() + 13 * X + 17 * Y + 23 * Z;
|
---|
| 76 | }
|
---|
[9596] | 77 |
|
---|
| 78 | public static ThreeDimensionalPacking MoveLeft(ThreeDimensionalPacking original) {
|
---|
| 79 | return new ThreeDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Z, original.Rotated);
|
---|
| 80 | }
|
---|
| 81 | public static ThreeDimensionalPacking MoveDown(ThreeDimensionalPacking original) {
|
---|
| 82 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Z, original.Rotated);
|
---|
| 83 | }
|
---|
| 84 | public static ThreeDimensionalPacking MoveBack(ThreeDimensionalPacking original) {
|
---|
| 85 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y, original.Z - 1, original.Rotated);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public static ThreeDimensionalPacking MoveRight(ThreeDimensionalPacking original) {
|
---|
| 89 | return new ThreeDimensionalPacking(original.AssignedBin, original.X + 1, original.Y, original.Z, original.Rotated);
|
---|
| 90 | }
|
---|
| 91 | public static ThreeDimensionalPacking MoveUp(ThreeDimensionalPacking original) {
|
---|
| 92 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y + 1, original.Z, original.Rotated);
|
---|
| 93 | }
|
---|
| 94 | public static ThreeDimensionalPacking MoveFront(ThreeDimensionalPacking original) {
|
---|
| 95 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y, original.Z + 1, original.Rotated);
|
---|
| 96 | }
|
---|
[9348] | 97 | }
|
---|
| 98 | }
|
---|