[14162] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14162] | 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 | using System;
|
---|
| 23 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Problems.BinPacking {
|
---|
| 28 | [StorableClass]
|
---|
| 29 | // PackingPosition is immutable (and handled as value types concerning Equals and GetHashCode)
|
---|
| 30 | public abstract class PackingPosition : Item, IPackingPosition {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// The number of the bin to which the current item is assigned is stored in this variable. Counting starts at 0 !!!
|
---|
| 33 | /// </summary>
|
---|
| 34 | [Storable]
|
---|
| 35 | private readonly int assignedBin;
|
---|
| 36 | public int AssignedBin {
|
---|
| 37 | get { return assignedBin; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | [Storable]
|
---|
| 41 | private readonly bool rotated;
|
---|
| 42 | /// <summary>
|
---|
| 43 | /// Determines if the positioned item is to be rotate by 90 degrees or not. (TODO: which axis?)
|
---|
| 44 | /// </summary>
|
---|
| 45 | public bool Rotated {
|
---|
| 46 | get { return rotated; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | [StorableConstructor]
|
---|
| 50 | protected PackingPosition(bool deserializing) : base(deserializing) { }
|
---|
| 51 | protected PackingPosition(PackingPosition original, Cloner cloner)
|
---|
| 52 | : base(original, cloner) {
|
---|
| 53 | assignedBin = original.AssignedBin;
|
---|
| 54 | rotated = original.Rotated;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | protected PackingPosition(int assignedBin, bool rotated) {
|
---|
| 58 | this.assignedBin = assignedBin;
|
---|
| 59 | this.rotated = rotated;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public override string ToString() {
|
---|
| 63 | return string.Format("[{0}-{1}]", AssignedBin, Rotated);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public override bool Equals(object obj) {
|
---|
| 67 | var other = obj as PackingPosition;
|
---|
| 68 | if (other != null)
|
---|
| 69 | return (other.AssignedBin == this.AssignedBin && other.Rotated == this.Rotated);
|
---|
| 70 | else return false;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public override int GetHashCode() {
|
---|
| 74 | return 31 * AssignedBin * (Rotated ? 3 : 7);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|