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 HeuristicLab.Problems.BinPacking.Dimensions;
|
---|
23 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
24 | using HeuristicLab.Problems.BinPacking.PackingBin;
|
---|
25 | using HeuristicLab.Problems.BinPacking.PackingItem;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.Common;
|
---|
29 | using HeuristicLab.Problems.BinPacking.Evaluators;
|
---|
30 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
31 | using HeuristicLab.PluginInfrastructure;
|
---|
32 | using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
|
---|
33 | using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
|
---|
34 | using HeuristicLab.Problems.Instances;
|
---|
35 | using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Problems.BinPacking.Problem {
|
---|
38 | [Item("Bin Packing Problem (2D, identical rectangles) (BPP)", "Represents a two-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")]
|
---|
39 | [StorableClass]
|
---|
40 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)]
|
---|
41 | public class RectangularIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> {
|
---|
42 |
|
---|
43 | #region Default Instance
|
---|
44 | private static readonly BPPData DefaultInstance = new BPPData() {
|
---|
45 | Name = "2D BPP Default Instance",
|
---|
46 | Description = "The default instance for 2D Bin Packing.",
|
---|
47 | BinMeasures = new int[] { 20, 16 },
|
---|
48 | ItemMeasures = new int[][] {
|
---|
49 | new int[] {3,8},
|
---|
50 | new int[] {5,3},
|
---|
51 | new int[] {9,3},
|
---|
52 | new int[] {2,7},
|
---|
53 | new int[] {5,3},
|
---|
54 | new int[] {9,3},
|
---|
55 | new int[] {2,7},
|
---|
56 | new int[] {5,3},
|
---|
57 | new int[] {9,3},
|
---|
58 | new int[] {2,7},
|
---|
59 | new int[] {5,3},
|
---|
60 | new int[] {9,3},
|
---|
61 | new int[] {2,7},
|
---|
62 | new int[] {5,3},
|
---|
63 | new int[] {9,3},
|
---|
64 | new int[] {2,7},
|
---|
65 | new int[] {5,3},
|
---|
66 | new int[] {9,3},
|
---|
67 | new int[] {2,7},
|
---|
68 | new int[] {5,3},
|
---|
69 | new int[] {9,3},
|
---|
70 | new int[] {2,7},
|
---|
71 | new int[] {5,3},
|
---|
72 | new int[] {9,3},
|
---|
73 | new int[] {2,7},
|
---|
74 | new int[] {5,3},
|
---|
75 | new int[] {9,3},
|
---|
76 | new int[] {2,7},
|
---|
77 | new int[] {5,3},
|
---|
78 | new int[] {9,3},
|
---|
79 | new int[] {2,7},
|
---|
80 | new int[] {5,3},
|
---|
81 | new int[] {9,3},
|
---|
82 | new int[] {2,7},
|
---|
83 | new int[] {5,3},
|
---|
84 | new int[] {9,3},
|
---|
85 | new int[] {2,7}
|
---|
86 | },
|
---|
87 | Items = 30
|
---|
88 | };
|
---|
89 | #endregion
|
---|
90 |
|
---|
91 | [StorableConstructor]
|
---|
92 | protected RectangularIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
|
---|
93 | protected RectangularIdenticalBinPackingProblem(RectangularIdenticalBinPackingProblem original, Cloner cloner)
|
---|
94 | : base(original, cloner) {
|
---|
95 | }
|
---|
96 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
97 | return new RectangularIdenticalBinPackingProblem(this, cloner);
|
---|
98 | }
|
---|
99 | public RectangularIdenticalBinPackingProblem() : base(
|
---|
100 | new PackingPlanEvaluationAlgorithm<Permutation, TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>()) {
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | #region Helpers
|
---|
105 | protected override void InitializeDecoder() {
|
---|
106 | // Operators.RemoveAll(op => op is I3DOperator); TODO
|
---|
107 |
|
---|
108 | PackingSolutionDecoderParameter.ValidValues.Clear();
|
---|
109 | if (SolutionCreator is PackingSequenceRandomCreator) {
|
---|
110 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DPSDecoder>());
|
---|
111 | } else if (SolutionCreator is GroupingVectorRandomCreator) {
|
---|
112 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DGVDecoder>());
|
---|
113 | } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
|
---|
114 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DMCVDecoder>());
|
---|
115 | } else {
|
---|
116 | string error = "The given problem does not support the selected solution-creator.";
|
---|
117 | ErrorHandling.ShowErrorDialog(error, null);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected override IPackingPlanEvaluator CreateDefaultEvaluator() {
|
---|
122 | return new PackingRatioRectangularIdenticalBinEvaluator ();
|
---|
123 | }
|
---|
124 |
|
---|
125 | protected override void InitializeProblemData() {
|
---|
126 | Load(DefaultInstance);
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected override void RemoveTooBigItems() {
|
---|
130 | PackingItemMeasures.RemoveAll(pi =>
|
---|
131 | !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, false), pi) &&
|
---|
132 | !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, true), pi));
|
---|
133 | }
|
---|
134 | #endregion
|
---|
135 | }
|
---|
136 | }
|
---|