[14162] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16140] | 3 | * Copyright (C) 2002-2018 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14162] | 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 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 | [StorableClass]
|
---|
| 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; } }
|
---|
[15705] | 42 |
|
---|
[14162] | 43 |
|
---|
| 44 | [StorableConstructor]
|
---|
| 45 | protected PackingPosition(bool deserializing) : base(deserializing) { }
|
---|
| 46 | protected PackingPosition(PackingPosition 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 PackingPosition(this, cloner);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public PackingPosition(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 PackingPosition;
|
---|
| 70 | if (tdp != null)
|
---|
| 71 | return (tdp.X == this.X && tdp.Y == this.Y && tdp.Z == this.Z);
|
---|
[15705] | 72 | else
|
---|
| 73 | return false;
|
---|
[14162] | 74 | }
|
---|
| 75 |
|
---|
| 76 | public override int GetHashCode() {
|
---|
| 77 | return base.GetHashCode() + 13 * X + 17 * Y + 23 * Z;
|
---|
| 78 | }
|
---|
[15705] | 79 |
|
---|
[14162] | 80 | #region IComparable<PackingPosition> Members
|
---|
| 81 |
|
---|
[15454] | 82 | /// <summary>
|
---|
| 83 | /// Compares two packing positions by their coordinates.
|
---|
[15471] | 84 | /// The order of comparing is y (height) -> z (depth) -> x (width).
|
---|
[15454] | 85 | /// </summary>
|
---|
| 86 | /// <param name="other"></param>
|
---|
| 87 | /// <returns></returns>
|
---|
[14162] | 88 | public int CompareTo(PackingPosition other) {
|
---|
[15471] | 89 | int result = Y.CompareTo(other.Y);
|
---|
| 90 | if (result == 0)
|
---|
| 91 | result = Z.CompareTo(other.Z);
|
---|
| 92 | if (result == 0)
|
---|
| 93 | result = X.CompareTo(other.X);
|
---|
[14162] | 94 | return result;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | #endregion
|
---|
| 98 | }
|
---|
| 99 | }
|
---|