Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PackingPosition.cs @ 15401

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

#1966: renamed *PackingDimension -> PackingPosition

File size: 3.2 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
22using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
23using HeuristicLab.Core;
24using HeuristicLab.Common;
25
[14046]26namespace HeuristicLab.Problems.BinPacking2D {
[14048]27  [Item("Packing Position (2d)", "Represents a packing-position associated with a two dimensional packing-problem.")]
[9348]28  [StorableClass]
[14048]29  // PackingPosition is an immutable class (and handled as value type concerning Equals and GetHashCode())
30  public class PackingPosition : BinPacking.PackingPosition {
[13605]31    [Storable]
32    private readonly int x;
33    public int X { get { return x; } }
[9348]34
[13605]35    [Storable]
36    private readonly int y;
37    public int Y { get { return y; } }
38
[9348]39    [StorableConstructor]
[14048]40    protected PackingPosition(bool deserializing) : base(deserializing) { }
41    protected PackingPosition(PackingPosition original, Cloner cloner)
[9348]42      : base(original, cloner) {
[13605]43      x = original.X;
44      y = original.Y;
[9348]45    }
[13605]46
[14048]47    public PackingPosition(int assignedBin, int x, int y, bool rotated = false)
[13605]48      : base(assignedBin, rotated) {
49      this.x = x;
50      this.y = y;
51    }
52
[9348]53    public override IDeepCloneable Clone(Cloner cloner) {
[14048]54      return new PackingPosition(this, cloner);
[9440]55    }
[13605]56   
[9348]57    public override string ToString() {
[13605]58      return string.Format("[AssignedBin: {0}; ({1},{2})]", AssignedBin, x, y);
[9348]59    }
[9440]60
61    public override bool Equals(object obj) {
[14048]62      var other = obj as PackingPosition;
[13605]63      if (other != null)
64        return (other.X == this.X && other.Y == this.Y && base.Equals(other));
[9440]65      else return false;
66    }
67
68    public override int GetHashCode() {
69      return base.GetHashCode() + 13 * X + 17 * Y;
70    }
[9596]71
[14048]72    public static PackingPosition MoveLeft(PackingPosition original) {
73      return new PackingPosition(original.AssignedBin, original.X - 1, original.Y, original.Rotated);
[9596]74    }
[14048]75    public static PackingPosition MoveDown(PackingPosition original) {
76      return new PackingPosition(original.AssignedBin, original.X, original.Y - 1, original.Rotated);
[9596]77    }
78
[14048]79    public static PackingPosition MoveRight(PackingPosition original) {
80      return new PackingPosition(original.AssignedBin, original.X + 1, original.Y, original.Rotated);
[9596]81    }
[14048]82    public static PackingPosition MoveUp(PackingPosition original) {
83      return new PackingPosition(original.AssignedBin, original.X, original.Y + 1, original.Rotated);
[9596]84    }
85
[9348]86  }
87}
Note: See TracBrowser for help on using the repository browser.