Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 15731 was 15731, checked in by rhanghof, 7 years ago

#2817:

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