Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PackingPosition.cs @ 17956

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

#1966: renamed *PackingDimension -> PackingPosition

File size: 3.2 KB
Line 
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
22using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
23using HeuristicLab.Core;
24using HeuristicLab.Common;
25
26namespace HeuristicLab.Problems.BinPacking2D {
27  [Item("Packing Position (2d)", "Represents a packing-position associated with a two dimensional packing-problem.")]
28  [StorableClass]
29  // PackingPosition is an immutable class (and handled as value type concerning Equals and GetHashCode())
30  public class PackingPosition : BinPacking.PackingPosition {
31    [Storable]
32    private readonly int x;
33    public int X { get { return x; } }
34
35    [Storable]
36    private readonly int y;
37    public int Y { get { return y; } }
38
39    [StorableConstructor]
40    protected PackingPosition(bool deserializing) : base(deserializing) { }
41    protected PackingPosition(PackingPosition original, Cloner cloner)
42      : base(original, cloner) {
43      x = original.X;
44      y = original.Y;
45    }
46
47    public PackingPosition(int assignedBin, int x, int y, bool rotated = false)
48      : base(assignedBin, rotated) {
49      this.x = x;
50      this.y = y;
51    }
52
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new PackingPosition(this, cloner);
55    }
56   
57    public override string ToString() {
58      return string.Format("[AssignedBin: {0}; ({1},{2})]", AssignedBin, x, y);
59    }
60
61    public override bool Equals(object obj) {
62      var other = obj as PackingPosition;
63      if (other != null)
64        return (other.X == this.X && other.Y == this.Y && base.Equals(other));
65      else return false;
66    }
67
68    public override int GetHashCode() {
69      return base.GetHashCode() + 13 * X + 17 * Y;
70    }
71
72    public static PackingPosition MoveLeft(PackingPosition original) {
73      return new PackingPosition(original.AssignedBin, original.X - 1, original.Y, original.Rotated);
74    }
75    public static PackingPosition MoveDown(PackingPosition original) {
76      return new PackingPosition(original.AssignedBin, original.X, original.Y - 1, original.Rotated);
77    }
78
79    public static PackingPosition MoveRight(PackingPosition original) {
80      return new PackingPosition(original.AssignedBin, original.X + 1, original.Y, original.Rotated);
81    }
82    public static PackingPosition MoveUp(PackingPosition original) {
83      return new PackingPosition(original.AssignedBin, original.X, original.Y + 1, original.Rotated);
84    }
85
86  }
87}
Note: See TracBrowser for help on using the repository browser.