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