source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/Problem.cs @ 14055

Last change on this file since 14055 was 14055, checked in by gkronber, 5 years ago

#1966: simplified parsers

File size: 7.2 KB
Line 
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
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24using HeuristicLab.Core;
25using HeuristicLab.Common;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
28using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
29using HeuristicLab.Problems.Instances;
30using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Data;
33using HeuristicLab.Problems.BinPacking;
34
35namespace HeuristicLab.Problems.BinPacking3D {
36  [Item("Bin Packing Problem (3D, identical cuboids) (BPP)", "Represents a three-dimensional bin-packing problem using only bins with identical measures and bins/items with cuboidic shapes.")]
37  [StorableClass]
38  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 310)]
39  public class Problem : Problem<PackingPosition, PackingShape, PackingItem>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> {
40    #region Default Instance
41    private static readonly BPPData DefaultInstance = new BPPData() {
42      Name = "3D BPP Default Instance",
43      Description = "The default instance for 3D Bin Packing.",
44      BinShape = new PackingShape(25, 25, 35),
45      Items = new PackingItem[] {
46        new PackingItem(12,5,10, new PackingShape(25,25,35)),
47        new PackingItem(10,18,20, new PackingShape(25,25,35)),
48        new PackingItem(9,7,7, new PackingShape(25,25,35)),
49        new PackingItem(21,12,4, new PackingShape(25,25,35)),
50        new PackingItem(8,8,12, new PackingShape(25,25,35)),
51        new PackingItem(3,6,14, new PackingShape(25,25,35)),
52        new PackingItem(20,4,9, new PackingShape(25,25,35)),
53        new PackingItem(5,9,8, new PackingShape(25,25,35)),
54        new PackingItem(7,17,3, new PackingShape(25,25,35)),
55        new PackingItem(13,20,15, new PackingShape(25,25,35)),
56        new PackingItem(9,11,9, new PackingShape(25,25,35)),
57        new PackingItem(10,18,20, new PackingShape(25,25,35)),
58        new PackingItem(9,7,7, new PackingShape(25,25,35)),
59        new PackingItem(21,12,4, new PackingShape(25,25,35)),
60        new PackingItem(8,8,12, new PackingShape(25,25,35)),
61        new PackingItem(3,6,14, new PackingShape(25,25,35)),
62        new PackingItem(20,4,9, new PackingShape(25,25,35)),
63        new PackingItem(5,9,8, new PackingShape(25,25,35)),
64        new PackingItem(7,17,3, new PackingShape(25,25,35)),
65        new PackingItem(13,20,15, new PackingShape(25,25,35)),
66        new PackingItem(9,11,9, new PackingShape(25,25,35)),
67        new PackingItem(10,18,20, new PackingShape(25,25,35)),
68        new PackingItem(9,7,7, new PackingShape(25,25,35)),
69        new PackingItem(21,12,4, new PackingShape(25,25,35)),
70        new PackingItem(8,8,12, new PackingShape(25,25,35)),
71        new PackingItem(3,6,14, new PackingShape(25,25,35)),
72        new PackingItem(20,4,9, new PackingShape(25,25,35)),
73        new PackingItem(5,9,8, new PackingShape(25,25,35)),
74        new PackingItem(7,17,3, new PackingShape(25,25,35)),
75        new PackingItem(13,20,15, new PackingShape(25,25,35)),
76        new PackingItem(9,11, 9,new PackingShape(25,25,35)),
77        new PackingItem(10,18,20, new PackingShape(25,25,35)),
78        new PackingItem(9,7,7, new PackingShape(25,25,35)),
79        new PackingItem(21,12,4, new PackingShape(25,25,35)),
80        new PackingItem(8,8,12, new PackingShape(25,25,35)),
81        new PackingItem(3,6,14, new PackingShape(25,25,35)),
82        new PackingItem(20,4,9, new PackingShape(25,25,35)),
83        new PackingItem(5,9,8, new PackingShape(25,25,35)),
84        new PackingItem(7,17,3, new PackingShape(25,25,35)),
85        new PackingItem(13,20,15, new PackingShape(25,25,35)),
86        new PackingItem(9,11,9, new PackingShape(25,25,35))
87      },
88    };
89    #endregion
90
91    [StorableConstructor]
92    protected Problem(bool deserializing) : base(deserializing) { }
93    protected Problem(Problem original, Cloner cloner)
94      : base(original, cloner) {
95    }
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new Problem(this, cloner);
98    }
99    public Problem() : base(
100      new DecodingEvaluator<Permutation, PackingPosition, PackingShape, PackingItem>()) {
101    }
102
103    public void Load(BPPData data) {
104
105
106      BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
107
108      PackingBinMeasures = data.BinShape;
109      PackingItemMeasures = new ItemList<PackingItem>(data.Items);
110
111      ApplyHorizontalOrientation();
112      SortItems();
113      PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
114      LowerBoundParameter.Value.Value = CalculateLowerBound();
115    }
116
117    public BPPData Export() {
118      return new BPPData {
119        Name = Name,
120        Description = Description,
121        BinShape = PackingBinMeasures,
122        Items = PackingItemMeasures.ToArray()
123      };
124    }
125
126    #region Helpers
127    protected override void InitializeDecoder() {
128      // Operators.RemoveAll(op => op is I2DOperator); TODO
129
130      PackingSolutionDecoderParameter.ValidValues.Clear();
131      if (SolutionCreator is PackingSequenceRandomCreator) {
132        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>());
133      } else if (SolutionCreator is GroupingVectorRandomCreator) {
134        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>());
135      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
136        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>());
137      } else {
138        string error = "The given problem does not support the selected solution-creator.";
139        ErrorHandling.ShowErrorDialog(error, null);
140      }
141    }
142
143    protected override IEvaluator CreateDefaultEvaluator() {
144      return new PackingRatioEvaluator();
145    }
146
147    protected override void InitializeProblemData() {
148      Load(DefaultInstance);
149    }
150
151    protected override void RemoveTooBigItems() {
152      PackingItemMeasures.RemoveAll(pi =>
153        !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, false), pi) &&
154        !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, true), pi));
155    }
156    #endregion
157  }
158}
Note: See TracBrowser for help on using the repository browser.