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