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 | 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]
|
---|
30 | public class ThreeDimensionalPacking: PackingDimensions {
|
---|
31 | public int X { get; set; }
|
---|
32 | public int Y { get; set; }
|
---|
33 | public int Z { get; set; }
|
---|
34 |
|
---|
35 | [StorableConstructor]
|
---|
36 | protected ThreeDimensionalPacking(bool deserializing) : base(deserializing) { }
|
---|
37 | protected ThreeDimensionalPacking(ThreeDimensionalPacking original, Cloner cloner)
|
---|
38 | : base(original, cloner) {
|
---|
39 | X = original.X;
|
---|
40 | Y = original.Y;
|
---|
41 | Z = original.Z;
|
---|
42 | }
|
---|
43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
44 | return new ThreeDimensionalPacking(this, cloner);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public ThreeDimensionalPacking(int assignedBin, int x, int y, int z) : this(assignedBin, x, y, z, false) {}
|
---|
48 | public ThreeDimensionalPacking(int assignedBin, int x, int y, int z, bool rotated)
|
---|
49 | : base(assignedBin, rotated) {
|
---|
50 | this.X = x;
|
---|
51 | this.Y = y;
|
---|
52 | this.Z = z;
|
---|
53 | }
|
---|
54 | public override string ToString() {
|
---|
55 | StringBuilder sb = new StringBuilder();
|
---|
56 | sb.Append("[");
|
---|
57 | sb.Append("AssignedBin: ");
|
---|
58 | sb.Append(AssignedBin);
|
---|
59 | sb.Append("; (");
|
---|
60 | sb.Append(X + ",");
|
---|
61 | sb.Append(Y + ",");
|
---|
62 | sb.Append(Z);
|
---|
63 | sb.Append(")");
|
---|
64 | sb.Append("]");
|
---|
65 | return sb.ToString();
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | public override bool Equals(object obj) {
|
---|
70 | var tdp = obj as ThreeDimensionalPacking;
|
---|
71 | if (tdp != null)
|
---|
72 | return (tdp.X == this.X && tdp.Y == this.Y && tdp.Z == this.Z);
|
---|
73 | else return false;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override int GetHashCode() {
|
---|
77 | return base.GetHashCode() + 13 * X + 17 * Y + 23 * Z;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public static ThreeDimensionalPacking MoveLeft(ThreeDimensionalPacking original) {
|
---|
81 | return new ThreeDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Z, original.Rotated);
|
---|
82 | }
|
---|
83 | public static ThreeDimensionalPacking MoveDown(ThreeDimensionalPacking original) {
|
---|
84 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Z, original.Rotated);
|
---|
85 | }
|
---|
86 | public static ThreeDimensionalPacking MoveBack(ThreeDimensionalPacking original) {
|
---|
87 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y, original.Z - 1, original.Rotated);
|
---|
88 | }
|
---|
89 |
|
---|
90 | public static ThreeDimensionalPacking MoveRight(ThreeDimensionalPacking original) {
|
---|
91 | return new ThreeDimensionalPacking(original.AssignedBin, original.X + 1, original.Y, original.Z, original.Rotated);
|
---|
92 | }
|
---|
93 | public static ThreeDimensionalPacking MoveUp(ThreeDimensionalPacking original) {
|
---|
94 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y + 1, original.Z, original.Rotated);
|
---|
95 | }
|
---|
96 | public static ThreeDimensionalPacking MoveFront(ThreeDimensionalPacking original) {
|
---|
97 | return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y, original.Z + 1, original.Rotated);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|