Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/TwoDimensionalPacking.cs @ 13606

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

#1966 refactoring (moved 2d-specific classes into separate project)

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