1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Problems.BinPacking3D {
|
---|
28 | [Item("Packing Position (3d)", "Represents a packing-position associated with a three dimensional packing-problem.")]
|
---|
29 | [StorableType("68408986-2325-43D3-A53B-DC2F31FB690C")]
|
---|
30 | // PackingPosition is immutable (and handled as value type concerning Equals and GetHashCode)
|
---|
31 | public class PackingPosition : BinPacking.PackingPosition, IComparable<PackingPosition> {
|
---|
32 | [Storable]
|
---|
33 | private readonly int x;
|
---|
34 | [Storable]
|
---|
35 | private readonly int y;
|
---|
36 | [Storable]
|
---|
37 | private readonly int z;
|
---|
38 |
|
---|
39 | public int X { get { return x; } }
|
---|
40 | public int Y { get { return y; } }
|
---|
41 | public int Z { get { return z; } }
|
---|
42 |
|
---|
43 | [StorableConstructor]
|
---|
44 | protected PackingPosition(StorableConstructorFlag _) : base(_) { }
|
---|
45 | protected PackingPosition(PackingPosition original, Cloner cloner)
|
---|
46 | : base(original, cloner) {
|
---|
47 | x = original.X;
|
---|
48 | y = original.Y;
|
---|
49 | z = original.Z;
|
---|
50 | }
|
---|
51 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
52 | return new PackingPosition(this, cloner);
|
---|
53 | }
|
---|
54 |
|
---|
55 | public PackingPosition(int assignedBin, int x, int y, int z, bool rotated = false)
|
---|
56 | : base(assignedBin, rotated) {
|
---|
57 | this.x = x;
|
---|
58 | this.y = y;
|
---|
59 | this.z = z;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override string ToString() {
|
---|
63 | return string.Format("[AssignedBin: {0}; ({1},{2},{3})]", AssignedBin, X, Y, Z);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | public override bool Equals(object obj) {
|
---|
68 | var tdp = obj as PackingPosition;
|
---|
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 | }
|
---|
77 |
|
---|
78 | public static PackingPosition MoveLeft(PackingPosition original) {
|
---|
79 | return new PackingPosition(original.AssignedBin, original.X - 1, original.Y, original.Z, original.Rotated);
|
---|
80 | }
|
---|
81 | public static PackingPosition MoveDown(PackingPosition original) {
|
---|
82 | return new PackingPosition(original.AssignedBin, original.X, original.Y - 1, original.Z, original.Rotated);
|
---|
83 | }
|
---|
84 | public static PackingPosition MoveBack(PackingPosition original) {
|
---|
85 | return new PackingPosition(original.AssignedBin, original.X, original.Y, original.Z - 1, original.Rotated);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public static PackingPosition MoveRight(PackingPosition original) {
|
---|
89 | return new PackingPosition(original.AssignedBin, original.X + 1, original.Y, original.Z, original.Rotated);
|
---|
90 | }
|
---|
91 | public static PackingPosition MoveUp(PackingPosition original) {
|
---|
92 | return new PackingPosition(original.AssignedBin, original.X, original.Y + 1, original.Z, original.Rotated);
|
---|
93 | }
|
---|
94 | public static PackingPosition MoveFront(PackingPosition original) {
|
---|
95 | return new PackingPosition(original.AssignedBin, original.X, original.Y, original.Z + 1, original.Rotated);
|
---|
96 | }
|
---|
97 |
|
---|
98 | #region IComparable<PackingPosition> Members
|
---|
99 |
|
---|
100 | public int CompareTo(PackingPosition other) {
|
---|
101 | int result = Z.CompareTo(other.Z);
|
---|
102 | if (result == 0)
|
---|
103 | result = X.CompareTo(other.X);
|
---|
104 | if (result == 0)
|
---|
105 | result = Y.CompareTo(other.Y);
|
---|
106 |
|
---|
107 | return result;
|
---|
108 |
|
---|
109 | }
|
---|
110 |
|
---|
111 | #endregion
|
---|
112 | }
|
---|
113 | }
|
---|