Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingItem.cs

Last change on this file was 16140, checked in by abeham, 6 years ago

#2817: updated to trunk r15680

File size: 13.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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
22using HeuristicLab.Core;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24using HeuristicLab.Common;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Problems.BinPacking;
28using HeuristicLab.Problems.BinPacking3D.Material;
29
30namespace HeuristicLab.Problems.BinPacking3D {
31  [Item("PackingItem (3d)", "Represents a cuboidic packing-item for bin-packing problems.")]
32  [StorableClass]
33  public class PackingItem : PackingShape, IPackingItem {
34    #region Properties
35
36
37    public IValueParameter<PackingShape> TargetBinParameter {
38      get { return (IValueParameter<PackingShape>)Parameters["TargetBin"]; }
39    }
40    public IFixedValueParameter<DoubleValue> WeightParameter {
41      get { return (IFixedValueParameter<DoubleValue>)Parameters["Weight"]; }
42    }
43    public IFixedValueParameter<IntValue> LayerParameter {
44      get { return (IFixedValueParameter<IntValue>)Parameters["Layer"]; }
45    }
46
47    public IFixedValueParameter<IntValue> SequenceGroupParameter {
48      get { return (IFixedValueParameter<IntValue>)Parameters["SequenceGroup"]; }
49    }
50
51    public IFixedValueParameter<IntValue> IdParameter {
52      get { return (IFixedValueParameter<IntValue>)Parameters["Id"]; }
53    }
54
55    public PackingShape TargetBin {
56      get { return TargetBinParameter.Value; }
57      set { TargetBinParameter.Value = value; }
58    }
59
60    public double Weight {
61      get { return WeightParameter.Value.Value; }
62      set { WeightParameter.Value.Value = value; }
63    }
64
65    public int Layer {
66      get { return LayerParameter.Value.Value; }
67      set { LayerParameter.Value.Value = value; }
68    }
69
70    public int SequenceGroup {
71      get { return SequenceGroupParameter.Value.Value; }
72      set { SequenceGroupParameter.Value.Value = value; }
73    }
74   
75    public int Id {
76      get { return IdParameter.Value.Value; }
77      set { IdParameter.Value.Value = value; }
78    }
79
80    #region Material   
81
82    public IFixedValueParameter<EnumValue<MaterialType>> MaterialTopParameter {
83      get { return (IFixedValueParameter<EnumValue<MaterialType>>)Parameters["MaterialTop"]; }
84    }
85    public MaterialType MaterialTop {
86      get { return MaterialTopParameter.Value.Value; }
87      set { MaterialTopParameter.Value.Value = value; }
88    }
89    #endregion
90
91    public IFixedValueParameter<DoubleValue> SupportedWeightParameter {
92      get { return (IFixedValueParameter<DoubleValue>)Parameters["SupportedWeight"]; }
93    }
94    public double SupportedWeight {
95      get { return SupportedWeightParameter.Value.Value; }
96      set { SupportedWeightParameter.Value.Value = value; }
97    }
98
99    public double SupportedWeightPerSquareMeter {
100      get {
101        return SupportedWeight / (Width * Depth);
102      }
103    }
104
105    public IValueParameter<BoolValue> IsStackableParameter {
106      get { return (IValueParameter<BoolValue>)Parameters["IsStackable"]; }
107    }
108
109    /// <summary>
110    /// Indicates that another item can be stacked on the current one.
111    /// </summary>
112    public bool IsStackabel {
113      get { return IsStackableParameter.Value.Value; }
114      set { IsStackableParameter.Value.Value = value; }
115    }
116
117    public IValueParameter<BoolValue> RotateEnabledParameter {
118      get { return (IValueParameter<BoolValue>)Parameters["RotateEnabled"]; }
119    }
120
121    public IValueParameter<BoolValue> RotatedParameter {
122      get { return (IValueParameter<BoolValue>)Parameters["Rotated"]; }
123    }
124
125    public IValueParameter<BoolValue> TiltEnabledParameter {
126      get { return (IValueParameter<BoolValue>)Parameters["TiltEnabled"]; }
127    }
128
129    public IValueParameter<BoolValue> TiltedParameter {
130      get { return (IValueParameter<BoolValue>)Parameters["Tilted"]; }
131    }
132
133    /// <summary>
134    /// Enables that the current item can be rotated.
135    /// </summary>
136    public bool RotateEnabled {
137      get { return RotateEnabledParameter.Value.Value; }
138      set { RotateEnabledParameter.Value.Value = value; }
139    }
140
141    /// <summary>
142    /// Indicates that the current item is rotated.
143    /// If the item is also tilted it will be tilted first.
144    /// </summary>
145    public bool Rotated {
146      get { return RotatedParameter.Value.Value; }
147      set { RotatedParameter.Value.Value = value; }
148    }
149
150    /// <summary>
151    /// Enables that the current item can be tilted.
152    /// </summary>
153    public bool TiltEnabled {
154      get { return TiltEnabledParameter.Value.Value; }
155      set { TiltEnabledParameter.Value.Value = value; }
156    }
157
158    /// <summary>
159    /// Indicates that the current item is tilted.
160    /// Tilted means that the item is tilted sidewards.
161    /// If the item is also rotated it will be tilted first.
162    /// </summary>
163    public bool Tilted {
164      get { return TiltedParameter.Value.Value; }
165      set { TiltedParameter.Value.Value = value; }
166    }
167
168    public IFixedValueParameter<IntValue> LoadSecuringHeightParameter {
169      get { return (IFixedValueParameter<IntValue>)Parameters["LoadSecuringHeight"]; }
170    }
171
172    public IFixedValueParameter<IntValue> LoadSecuringWidthParameter {
173      get { return (IFixedValueParameter<IntValue>)Parameters["LoadSecuringWidth"]; }
174    }
175
176    public IFixedValueParameter<IntValue> LoadSecuringDepthParameter {
177      get { return (IFixedValueParameter<IntValue>)Parameters["LoadSecuringDepth"]; }
178    }
179
180    public int LoadSecuringHeight {
181      get { return LoadSecuringHeightParameter.Value.Value; }
182      set { LoadSecuringHeightParameter.Value.Value = value; }
183    }
184
185    public int LoadSecuringWidth {
186      get { return LoadSecuringWidthParameter.Value.Value; }
187      set { LoadSecuringWidthParameter.Value.Value = value; }
188    }
189
190    public int LoadSecuringDepth {
191      get { return LoadSecuringDepthParameter.Value.Value; }
192      set { LoadSecuringDepthParameter.Value.Value = value; }
193    }
194
195    /// <summary>
196    /// This property represents the height as needed in the bin packing.
197    /// </summary>
198    public new int Height {
199      get {
200        if (!Tilted) {
201          return HeightParameter.Value.Value + LoadSecuringHeightParameter.Value.Value;
202        } else {
203          return WidthParameter.Value.Value + LoadSecuringHeightParameter.Value.Value;
204        }
205      }
206    }
207
208    /// <summary>
209    /// This property represents the width as needed in the bin packing.
210    /// </summary>
211    public new int Width {
212      get {
213        if (Rotated) {
214          return DepthParameter.Value.Value + LoadSecuringWidthParameter.Value.Value;
215        } else {
216          if (!Tilted) {
217            return WidthParameter.Value.Value + LoadSecuringWidthParameter.Value.Value;
218          } else {
219            return HeightParameter.Value.Value + LoadSecuringWidthParameter.Value.Value;
220          }
221        }
222      }
223    }
224
225    /// <summary>
226    /// This property represents the depth as needed in the bin packing.
227    /// </summary>
228    public new int Depth {
229      get {
230        if (!Rotated) {
231          return DepthParameter.Value.Value + LoadSecuringDepthParameter.Value.Value;
232        } else {
233          if (!Tilted) {
234            return WidthParameter.Value.Value + LoadSecuringDepthParameter.Value.Value;
235          } else {
236            return HeightParameter.Value.Value + LoadSecuringDepthParameter.Value.Value;
237          }
238        }
239      }
240    }
241
242    /// <summary>
243    /// This property represents the height as it is seen in the view of the bin packing.
244    /// </summary>
245    public int HeightInView {
246      get {
247        if (!Tilted) {
248          return HeightParameter.Value.Value;
249        } else {
250          return WidthParameter.Value.Value;
251        }
252      }
253    }
254
255    /// <summary>
256    /// This property represents the width as it is seen in the view of the bin packing.
257    /// </summary>
258    public int WidthInView {
259      get {
260        if (Rotated) {
261          return DepthParameter.Value.Value;
262        } else {
263          if (!Tilted) {
264            return WidthParameter.Value.Value;
265          } else {
266            return HeightParameter.Value.Value;
267          }
268        }
269      }
270    }
271
272    /// <summary>
273    /// This property represents the depth as it is seen in the view of the bin packing.
274    /// </summary>
275    public int DepthInView {
276      get {
277        if (!Rotated) {
278          return DepthParameter.Value.Value;
279        } else {
280          if (!Tilted) {
281            return WidthParameter.Value.Value;
282          } else {
283            return HeightParameter.Value.Value;
284          }
285        }
286      }
287    }
288
289    /// <summary>
290    /// This property represents the original height.
291    /// </summary>
292    public int OriginalHeight {
293      get { return HeightParameter.Value.Value; }
294      set { HeightParameter.Value.Value = value; }
295    }
296
297    /// <summary>
298    /// This property represents the original width.
299    /// </summary>
300    public int OriginalWidth {
301      get { return WidthParameter.Value.Value; }
302      set { WidthParameter.Value.Value = value; }
303    }
304
305    /// <summary>
306    /// This property represents the original depth.
307    /// </summary>
308    public int OriginalDepth {
309      get { return DepthParameter.Value.Value; }
310      set { DepthParameter.Value.Value = value; }
311    }
312
313    public bool SupportsStacking(IPackingItem other) {
314      return other.Layer <= this.Layer && SupportedWeight > 0;
315    }
316       
317    public bool SupportWeight(double weigth) {
318      return SupportedWeight >= weigth;
319    }
320
321
322
323    #endregion
324
325
326    [StorableConstructor]
327    protected PackingItem(bool deserializing) : base(deserializing) { }
328    protected PackingItem(PackingItem original, Cloner cloner)
329      : base(original, cloner) {
330      RegisterEvents();
331    }
332    public PackingItem()
333      : base() {
334      Parameters.Add(new ValueParameter<PackingShape>("TargetBin"));
335      Parameters.Add(new FixedValueParameter<DoubleValue>("Weight"));     
336      Parameters.Add(new FixedValueParameter<IntValue>("Layer"));
337      Parameters.Add(new FixedValueParameter<IntValue>("SequenceGroup"));
338      Parameters.Add(new FixedValueParameter<IntValue>("Id"));
339
340
341      Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialTop"));
342
343      Parameters.Add(new FixedValueParameter<DoubleValue>("SupportedWeight"));
344
345      Parameters.Add(new FixedValueParameter<BoolValue>("RotateEnabled"));
346      Parameters.Add(new FixedValueParameter<BoolValue>("Rotated"));
347      Parameters.Add(new FixedValueParameter<BoolValue>("TiltEnabled"));
348      Parameters.Add(new FixedValueParameter<BoolValue>("Tilted"));
349      Parameters.Add(new FixedValueParameter<BoolValue>("IsStackable"));
350
351      Parameters.Add(new FixedValueParameter<IntValue>("LoadSecuringHeight"));
352      Parameters.Add(new FixedValueParameter<IntValue>("LoadSecuringWidth"));
353      Parameters.Add(new FixedValueParameter<IntValue>("LoadSecuringDepth"));
354
355      IsStackabel = true;
356
357      RegisterEvents();
358    }
359
360    public PackingItem(int width, int height, int depth, PackingShape targetBin)
361      : this() {
362      this.OriginalWidth = width;
363      this.OriginalHeight = height;
364      this.OriginalDepth = depth;
365      this.TargetBin = (PackingShape)targetBin.Clone();
366    }
367
368    public PackingItem(int width, int height, int depth, PackingShape targetBin, double weight, int sequenceNumber, int layer)
369      : this(width, height, depth, targetBin) {
370      this.Weight = weight;
371      this.Layer = layer;
372      this.SequenceGroup = sequenceNumber;
373    }
374
375    public PackingItem(PackingItem packingItem) : this() {
376      OriginalWidth = packingItem.OriginalWidth;
377      OriginalHeight = packingItem.OriginalHeight;
378      OriginalDepth = packingItem.OriginalDepth;
379      TargetBin = (PackingShape)packingItem.TargetBin.Clone();
380      Weight = packingItem.Weight;
381      Layer = packingItem.Layer;
382      SequenceGroup = packingItem.SequenceGroup;
383      Id = packingItem.Id;
384      Rotated = packingItem.Rotated;
385      Tilted = packingItem.Tilted;
386      IsStackabel = packingItem.IsStackabel;
387      MaterialTop = packingItem.MaterialTop;
388      MaterialBottom = packingItem.MaterialBottom;
389
390      LoadSecuringDepth = packingItem.LoadSecuringDepth;
391      LoadSecuringHeight = packingItem.LoadSecuringHeight;
392      LoadSecuringWidth = packingItem.LoadSecuringWidth;
393    }
394
395    [StorableHook(HookType.AfterDeserialization)]
396    private void AfterDeserialization() {
397      RegisterEvents();
398    }
399
400    public override IDeepCloneable Clone(Cloner cloner) {
401      return new PackingItem(this, cloner);
402    }
403
404    private void RegisterEvents() {
405      // NOTE: only because of ToString override
406      WeightParameter.Value.ValueChanged += (sender, args) => OnToStringChanged();
407      LayerParameter.Value.ValueChanged += (sender, args) => OnToStringChanged();
408
409      // target bin does not occur in ToString()
410    }
411
412    public override string ToString() {
413      return string.Format("CuboidPackingItem ({0}, {1}, {2}; weight={3}, layer={4})", this.Width, this.Height, this.Depth, this.Weight, this.Layer);
414    }
415
416  }
417}
Note: See TracBrowser for help on using the repository browser.