Changeset 13574 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs
- Timestamp:
- 01/28/16 18:32:54 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs
r13497 r13574 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 using HeuristicLab.Common; 28 using HeuristicLab.Data; 29 using HeuristicLab.Parameters; 28 30 using HeuristicLab.Problems.BinPacking.Dimensions; 29 31 … … 33 35 public abstract class RectangularPackingShape : PackingShape<TwoDimensionalPacking>, IRegularPackingShape, IComparable<RectangularPackingShape> { 34 36 #region Properties 35 [Storable] 36 public int Height { get; set; } 37 public int Height { 38 get { return ((IFixedValueParameter<IntValue>)Parameters["Height"]).Value.Value; } 39 set { ((IFixedValueParameter<IntValue>)Parameters["Height"]).Value.Value = value; } 40 } 37 41 38 [Storable] 39 public int Width { get; set; } 42 public int Width { 43 get { return ((IFixedValueParameter<IntValue>)Parameters["Width"]).Value.Value; } 44 set { ((IFixedValueParameter<IntValue>)Parameters["Width"]).Value.Value = value; } 45 } 46 40 47 #endregion 48 49 protected RectangularPackingShape() 50 : base() { 51 Parameters.Add(new FixedValueParameter<IntValue>("Width")); 52 Parameters.Add(new FixedValueParameter<IntValue>("Height")); 53 } 54 protected RectangularPackingShape(int width, int height) 55 : this() { 56 this.Height = height; 57 this.Width = width; 58 } 59 60 [StorableConstructor] 61 protected RectangularPackingShape(bool deserializing) : base(deserializing) { } 62 protected RectangularPackingShape(RectangularPackingShape original, Cloner cloner) 63 : base(original, cloner) { 64 } 65 66 public override void InitializeFromMeasures(int[] measures) { 67 if (measures.Length != 2) 68 throw new InvalidOperationException("Nr of measures does not fit shape-dimension."); 69 this.Width = measures[0]; 70 this.Height = measures[1]; 71 } 72 73 74 75 public override string ToString() { 76 return String.Format("RectangularPackingShape ({0}, {1})", this.Width, this.Height); 77 } 78 79 #region IComparable<RectangularPackingShape> Members 80 81 public int CompareTo(RectangularPackingShape other) { 82 int result = this.Width.CompareTo(other.Width); 83 if (result == 0) 84 result = this.Height.CompareTo(other.Height); 85 return result; 86 } 87 88 public int CompareTo(object obj) { 89 var other = obj as RectangularPackingShape; 90 if (other != null) return CompareTo(other); 91 else throw new ArgumentException(string.Format("Cannot compare to object {0}", obj), "obj"); 92 } 93 94 #endregion 95 96 public override int[] ToArray() { 97 return new int[] { Width, Height }; 98 } 99 100 41 101 42 102 #region Helpers … … 85 145 #endregion 86 146 87 protected RectangularPackingShape() : base() { }88 protected RectangularPackingShape(int width, int height)89 : base() {90 this.Height = height;91 this.Width = width;92 }93 94 public override void InitializeFromMeasures(int[] measures) {95 if (measures.Length != 2)96 throw new InvalidOperationException("Nr of measures does not fit shape-dimension.");97 this.Width = measures[0];98 this.Height = measures[1];99 }100 101 102 [StorableConstructor]103 protected RectangularPackingShape(bool deserializing) : base(deserializing) { }104 protected RectangularPackingShape(RectangularPackingShape original, Cloner cloner)105 : base(original, cloner) {106 this.Width = original.Width;107 this.Height = original.Height;108 }109 110 public override string ToString() {111 return String.Format("RectangularPackingShape ({0}, {1})", this.Width, this.Height);112 }113 114 #region IComparable<RectangularPackingShape> Members115 116 public int CompareTo(RectangularPackingShape other) {117 int result = 0;// this.MultipliedMeasures.CompareTo(other.MultipliedMeasures);118 if (result == 0) {119 result = this.Width.CompareTo(other.Width);120 if (result == 0)121 result = this.Height.CompareTo(other.Height);122 }123 return result;124 }125 126 public int CompareTo(object obj) {127 var other = obj as RectangularPackingShape;128 if (other != null) return CompareTo(other);129 else throw new ArgumentException(string.Format("Cannot compare to object {0}", obj), "obj");130 }131 132 #endregion133 134 public override int[] ToArray() {135 return new int[] { Width, Height };136 }137 147 138 148 private struct RectangleDiagonal {
Note: See TracChangeset
for help on using the changeset viewer.