Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Dimensions/TwoDimensionalPacking.cs @ 13599

Last change on this file since 13599 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
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;
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  public class TwoDimensionalPacking : PackingDimensions {
31    public int X { get; set; }
32    public int Y { get; set; }
33
34    [StorableConstructor]
35    protected TwoDimensionalPacking(bool deserializing) : base(deserializing) { }
36    protected TwoDimensionalPacking(TwoDimensionalPacking original, Cloner cloner)
37      : base(original, cloner) {
38        X = original.X;
39        Y = original.Y;
40    }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new TwoDimensionalPacking(this, cloner);
43    }
44
45    public TwoDimensionalPacking(int assignedBin, int x, int y) : this(assignedBin, x, y, false) { }
46    public TwoDimensionalPacking(int assignedBin, int x, int y, bool rotated)
47      : base(assignedBin, rotated) {
48      this.X = x;
49      this.Y = y;
50    }
51    public override string ToString() {
52      StringBuilder sb = new StringBuilder();
53      sb.Append("[");
54      sb.Append("AssignedBin: ");
55      sb.Append(AssignedBin);
56      sb.Append("; (");
57      sb.Append(X + ",");
58      sb.Append(Y);
59      sb.Append(")");
60      sb.Append("]");
61      return sb.ToString();
62    }
63
64
65    public override bool Equals(object obj) {
66      var tdp = obj as TwoDimensionalPacking;
67      if (tdp != null)
68        return (tdp.X == this.X && tdp.Y == this.Y);
69      else return false;
70    }
71
72    public override int GetHashCode() {
73      return base.GetHashCode() + 13 * X + 17 * Y;
74    }
75
76    public static TwoDimensionalPacking MoveLeft(TwoDimensionalPacking original) {
77      return new TwoDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Rotated);
78    }
79    public static TwoDimensionalPacking MoveDown(TwoDimensionalPacking original) {
80      return new TwoDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Rotated);
81    }
82
83    public static TwoDimensionalPacking MoveRight(TwoDimensionalPacking original) {
84      return new TwoDimensionalPacking(original.AssignedBin, original.X + 1, original.Y, original.Rotated);
85    }
86    public static TwoDimensionalPacking MoveUp(TwoDimensionalPacking original) {
87      return new TwoDimensionalPacking(original.AssignedBin, original.X, original.Y + 1, original.Rotated);
88    }
89
90  }
91}
Note: See TracBrowser for help on using the repository browser.