[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 |
|
---|
| 22 | using HeuristicLab.Core;
|
---|
| 23 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
[13574] | 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[14046] | 27 | using HeuristicLab.Problems.BinPacking;
|
---|
[9348] | 28 |
|
---|
[14046] | 29 | namespace HeuristicLab.Problems.BinPacking3D {
|
---|
[14049] | 30 | [Item("PackingItem (3d)", "Represents a cuboidic packing-item for bin-packing problems.")]
|
---|
[9348] | 31 | [StorableClass]
|
---|
[14049] | 32 | public class PackingItem : PackingShape, IPackingItem {
|
---|
| 33 | public IValueParameter<PackingShape> TargetBinParameter {
|
---|
| 34 | get { return (IValueParameter<PackingShape>)Parameters["TargetBin"]; }
|
---|
[13605] | 35 | }
|
---|
| 36 | public IFixedValueParameter<DoubleValue> WeightParameter {
|
---|
| 37 | get { return (IFixedValueParameter<DoubleValue>)Parameters["Weight"]; }
|
---|
| 38 | }
|
---|
| 39 | public IFixedValueParameter<IntValue> MaterialParameter {
|
---|
| 40 | get { return (IFixedValueParameter<IntValue>)Parameters["Material"]; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[14049] | 43 | public PackingShape TargetBin {
|
---|
[13605] | 44 | get { return TargetBinParameter.Value; }
|
---|
| 45 | set { TargetBinParameter.Value = value; }
|
---|
[13574] | 46 | }
|
---|
[9348] | 47 |
|
---|
[13574] | 48 | public double Weight {
|
---|
[13605] | 49 | get { return WeightParameter.Value.Value; }
|
---|
| 50 | set { WeightParameter.Value.Value = value; }
|
---|
[13574] | 51 | }
|
---|
[13497] | 52 |
|
---|
[13574] | 53 | public int Material {
|
---|
[13605] | 54 | get { return MaterialParameter.Value.Value; }
|
---|
| 55 | set { MaterialParameter.Value.Value = value; }
|
---|
[13574] | 56 | }
|
---|
[13497] | 57 |
|
---|
[9563] | 58 | public bool SupportsStacking(IPackingItem other) {
|
---|
| 59 | return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
|
---|
| 60 | }
|
---|
[9348] | 61 |
|
---|
| 62 | [StorableConstructor]
|
---|
[14049] | 63 | protected PackingItem(bool deserializing) : base(deserializing) { }
|
---|
| 64 | protected PackingItem(PackingItem original, Cloner cloner)
|
---|
[9348] | 65 | : base(original, cloner) {
|
---|
[13605] | 66 | RegisterEvents();
|
---|
[9348] | 67 | }
|
---|
[14049] | 68 | public PackingItem()
|
---|
[13497] | 69 | : base() {
|
---|
[14049] | 70 | Parameters.Add(new ValueParameter<PackingShape>("TargetBin"));
|
---|
[13574] | 71 | Parameters.Add(new FixedValueParameter<DoubleValue>("Weight"));
|
---|
| 72 | Parameters.Add(new FixedValueParameter<IntValue>("Material"));
|
---|
[13605] | 73 |
|
---|
| 74 | RegisterEvents();
|
---|
[9348] | 75 | }
|
---|
| 76 |
|
---|
[14049] | 77 | public PackingItem(int width, int height, int depth, PackingShape targetBin, double weight, int material)
|
---|
[13574] | 78 | : this() {
|
---|
| 79 | this.Width = width;
|
---|
| 80 | this.Height = height;
|
---|
| 81 | this.Depth = depth;
|
---|
[13497] | 82 | this.Weight = weight;
|
---|
| 83 | this.Material = material;
|
---|
[14049] | 84 | this.TargetBin = (PackingShape)targetBin.Clone();
|
---|
[13497] | 85 | }
|
---|
[9348] | 86 |
|
---|
[14049] | 87 | public PackingItem(int width, int height, int depth, PackingShape targetBin)
|
---|
[13574] | 88 | : this() {
|
---|
| 89 | this.Width = width;
|
---|
| 90 | this.Height = height;
|
---|
| 91 | this.Depth = depth;
|
---|
[14049] | 92 | this.TargetBin = (PackingShape)targetBin.Clone();
|
---|
[13497] | 93 | }
|
---|
| 94 |
|
---|
[13605] | 95 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 96 | private void AfterDeserialization() {
|
---|
| 97 | RegisterEvents();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[13574] | 100 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[14049] | 101 | return new PackingItem(this, cloner);
|
---|
[13574] | 102 | }
|
---|
| 103 |
|
---|
[13605] | 104 | private void RegisterEvents() {
|
---|
[14153] | 105 | // NOTE: only because of ToString override
|
---|
[13605] | 106 | WeightParameter.Value.ValueChanged += (sender, args) => OnToStringChanged();
|
---|
| 107 | MaterialParameter.Value.ValueChanged += (sender, args) => OnToStringChanged();
|
---|
| 108 |
|
---|
| 109 | // target bin does not occur in ToString()
|
---|
[9348] | 110 | }
|
---|
[9563] | 111 |
|
---|
[13605] | 112 |
|
---|
[9563] | 113 | public override string ToString() {
|
---|
[13605] | 114 | return string.Format("CuboidPackingItem ({0}, {1}, {2}; weight={3}, mat={4})", this.Width, this.Height, this.Depth, this.Weight, this.Material);
|
---|
[9563] | 115 | }
|
---|
[9348] | 116 | }
|
---|
| 117 | }
|
---|