Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: unified namespaces

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