Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/old files/Problem3D.cs @ 18066

Last change on this file since 18066 was 14146, checked in by gkronber, 8 years ago

#1966: new implementation for 2d bin packing problem with permutation encoding

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