Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PackingPosition.cs @ 15870

Last change on this file since 15870 was 14048, checked in by gkronber, 8 years ago

#1966: renamed *PackingDimension -> PackingPosition

File size: 3.8 KB
RevLine 
[9348]1#region License Information
2/* HeuristicLab
[13032]3 * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[9348]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
[14046]22
[9348]23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24using HeuristicLab.Core;
25using HeuristicLab.Common;
26
[14046]27namespace HeuristicLab.Problems.BinPacking3D {
[14048]28  [Item("Packing Position (3d)", "Represents a packing-position associated with a three dimensional packing-problem.")]
[9348]29  [StorableClass]
[14048]30  // PackingPosition is immutable (and handled as value type concerning Equals and GetHashCode)
31  public class PackingPosition : BinPacking.PackingPosition {
[13605]32    [Storable]
33    private readonly int x;
34    [Storable]
35    private readonly int y;
36    [Storable]
37    private readonly int z;
[9348]38
[13605]39    public int X { get { return x; } }
40    public int Y { get { return y; } }
41    public int Z { get { return z; } }
42
[9348]43    [StorableConstructor]
[14048]44    protected PackingPosition(bool deserializing) : base(deserializing) { }
45    protected PackingPosition(PackingPosition original, Cloner cloner)
[9348]46      : base(original, cloner) {
[13605]47      x = original.X;
48      y = original.Y;
49      z = original.Z;
[9348]50    }
51    public override IDeepCloneable Clone(Cloner cloner) {
[14048]52      return new PackingPosition(this, cloner);
[9348]53    }
54
[14048]55    public PackingPosition(int assignedBin, int x, int y, int z, bool rotated = false)
[9440]56      : base(assignedBin, rotated) {
[13605]57      this.x = x;
58      this.y = y;
59      this.z = z;
[9348]60    }
[13605]61
[9348]62    public override string ToString() {
[13605]63      return string.Format("[AssignedBin: {0}; ({1},{2},{3})]", AssignedBin, X, Y, Z);
[9348]64    }
[9440]65
66
67    public override bool Equals(object obj) {
[14048]68      var tdp = obj as PackingPosition;
[9440]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    }
[9596]77
[14048]78    public static PackingPosition MoveLeft(PackingPosition original) {
79      return new PackingPosition(original.AssignedBin, original.X - 1, original.Y, original.Z, original.Rotated);
[9596]80    }
[14048]81    public static PackingPosition MoveDown(PackingPosition original) {
82      return new PackingPosition(original.AssignedBin, original.X, original.Y - 1, original.Z, original.Rotated);
[9596]83    }
[14048]84    public static PackingPosition MoveBack(PackingPosition original) {
85      return new PackingPosition(original.AssignedBin, original.X, original.Y, original.Z - 1, original.Rotated);
[9596]86    }
87
[14048]88    public static PackingPosition MoveRight(PackingPosition original) {
89      return new PackingPosition(original.AssignedBin, original.X + 1, original.Y, original.Z, original.Rotated);
[9596]90    }
[14048]91    public static PackingPosition MoveUp(PackingPosition original) {
92      return new PackingPosition(original.AssignedBin, original.X, original.Y + 1, original.Z, original.Rotated);
[9596]93    }
[14048]94    public static PackingPosition MoveFront(PackingPosition original) {
95      return new PackingPosition(original.AssignedBin, original.X, original.Y, original.Z + 1, original.Rotated);
[9596]96    }
[9348]97  }
98}
Note: See TracBrowser for help on using the repository browser.