Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingPosition.cs @ 15554

Last change on this file since 15554 was 15554, checked in by rhanghof, 7 years ago

#2817:

  • Unittests
  • Bugfixes on the line projection based extreme point creation method
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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
22using System;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24using HeuristicLab.Core;
25using HeuristicLab.Common;
26
27namespace 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; } }
42
43    [StorableConstructor]
44    protected PackingPosition(bool deserializing) : base(deserializing) { }
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    #region IComparable<PackingPosition> Members
79
80    /// <summary>
81    /// Compares two packing positions by their coordinates.
82    /// The order of comparing is y (height) -> z (depth) -> x (width).
83    /// </summary>
84    /// <param name="other"></param>
85    /// <returns></returns>
86    public int CompareTo(PackingPosition other) {
87      int result = Y.CompareTo(other.Y);
88      if (result == 0)
89        result = Z.CompareTo(other.Z);
90      if (result == 0)
91        result = X.CompareTo(other.X);
92      return result;
93    }
94
95    #endregion
96  }
97}
Note: See TracBrowser for help on using the repository browser.