1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 |
|
---|
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;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Problems.BinPacking.PackingBin;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.BinPacking.PackingItem {
|
---|
33 | [Item("CuboidPackingItem", "Represents a cuboidic packing-item for bin-packing problems.")]
|
---|
34 | [StorableClass]
|
---|
35 | public class CuboidPackingItem : CuboidPackingShape, IPackingItem {
|
---|
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 |
|
---|
46 | public CuboidPackingBin TargetBin {
|
---|
47 | get { return TargetBinParameter.Value; }
|
---|
48 | set { TargetBinParameter.Value = value; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public double Weight {
|
---|
52 | get { return WeightParameter.Value.Value; }
|
---|
53 | set { WeightParameter.Value.Value = value; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public int Material {
|
---|
57 | get { return MaterialParameter.Value.Value; }
|
---|
58 | set { MaterialParameter.Value.Value = value; }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public bool SupportsStacking(IPackingItem other) {
|
---|
62 | return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
|
---|
63 | }
|
---|
64 |
|
---|
65 | [StorableConstructor]
|
---|
66 | protected CuboidPackingItem(bool deserializing) : base(deserializing) { }
|
---|
67 | protected CuboidPackingItem(CuboidPackingItem original, Cloner cloner)
|
---|
68 | : base(original, cloner) {
|
---|
69 | RegisterEvents();
|
---|
70 | }
|
---|
71 | public CuboidPackingItem()
|
---|
72 | : base() {
|
---|
73 | Parameters.Add(new ValueParameter<CuboidPackingBin>("TargetBin"));
|
---|
74 | Parameters.Add(new FixedValueParameter<DoubleValue>("Weight"));
|
---|
75 | Parameters.Add(new FixedValueParameter<IntValue>("Material"));
|
---|
76 |
|
---|
77 | RegisterEvents();
|
---|
78 | }
|
---|
79 |
|
---|
80 | public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin, double weight, int material)
|
---|
81 | : this() {
|
---|
82 | this.Width = width;
|
---|
83 | this.Height = height;
|
---|
84 | this.Depth = depth;
|
---|
85 | this.Weight = weight;
|
---|
86 | this.Material = material;
|
---|
87 | this.TargetBin = (CuboidPackingBin)targetBin.Clone();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin)
|
---|
91 | : this() {
|
---|
92 | this.Width = width;
|
---|
93 | this.Height = height;
|
---|
94 | this.Depth = depth;
|
---|
95 | this.TargetBin = (CuboidPackingBin)targetBin.Clone();
|
---|
96 | }
|
---|
97 |
|
---|
98 | [StorableHook(HookType.AfterDeserialization)]
|
---|
99 | private void AfterDeserialization() {
|
---|
100 | RegisterEvents();
|
---|
101 | }
|
---|
102 |
|
---|
103 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
104 | return new CuboidPackingItem(this, cloner);
|
---|
105 | }
|
---|
106 |
|
---|
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()
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | public override string ToString() {
|
---|
117 | return string.Format("CuboidPackingItem ({0}, {1}, {2}; weight={3}, mat={4})", this.Width, this.Height, this.Depth, this.Weight, this.Material);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|