Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingDimensions.cs @ 13792

Last change on this file since 13792 was 13608, checked in by gkronber, 9 years ago

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

File size: 2.8 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
22
23using HeuristicLab.Problems.BinPacking.Interfaces;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Core;
26using HeuristicLab.Common;
27
28namespace HeuristicLab.Problems.BinPacking.Dimensions {
29  [Item("Packing Dimensions", "Represents an abstract packing-position associated with a packing-problem.")]
30  [StorableClass]
31  // PackingDimensions is immutable (and handled as value types concerning Equals and GetHashCode)
32  public abstract class PackingDimensions : Item, IPackingDimensions {
33    /// <summary>
34    /// The number of the bin to which the current item is assigned is stored in this variable. Counting starts at 0 !!!
35    /// </summary>   
36    [Storable]
37    private readonly int assignedBin;
38    public int AssignedBin {
39      get { return assignedBin; }
40    }
41
42    [Storable]
43    private readonly bool rotated;
44    /// <summary>
45    /// Determines if the positioned item is to be rotate by 90 degrees or not. (TODO: which axis?)
46    /// </summary>
47    public bool Rotated {
48      get { return rotated; }
49    }
50
51    [StorableConstructor]
52    protected PackingDimensions(bool deserializing) : base(deserializing) { }
53    protected PackingDimensions(PackingDimensions original, Cloner cloner)
54      : base(original, cloner) {
55      assignedBin = original.AssignedBin;
56      rotated = original.Rotated;
57    }
58
59    protected PackingDimensions(int assignedBin, bool rotated) {
60      this.assignedBin = assignedBin;
61      this.rotated = rotated;
62    }
63
64    public override string ToString() {
65      return string.Format("[{0}-{1}]", AssignedBin, Rotated);
66    }
67
68    public override bool Equals(object obj) {
69      var other = obj as PackingDimensions;
70      if (other != null)
71        return (other.AssignedBin == this.AssignedBin && other.Rotated == this.Rotated);
72      else return false;
73    }
74
75    public override int GetHashCode() {
76      return 31 * AssignedBin * (Rotated ? 3 : 7);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.