Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingDimensions.cs @ 17514

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

#1966: renamed *PackingDimension -> PackingPosition

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