Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: renamed *PackingDimension -> PackingPosition

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