Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/old files/Problem3D.cs @ 14615

Last change on this file since 14615 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
RevLine 
[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
[14045]22
[9348]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;
[9563]29using HeuristicLab.PluginInfrastructure;
[14039]30using HeuristicLab.Data;
[14046]31using HeuristicLab.Problems.BinPacking;
[9348]32
[14046]33namespace HeuristicLab.Problems.BinPacking3D {
[13460]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.")]
[9348]35  [StorableClass]
[13460]36  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 310)]
[14049]37  public class Problem : Problem<PackingPosition, PackingShape, PackingItem>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> {
[9348]38    #region Default Instance
[14039]39    private static readonly BPPData DefaultInstance = new BPPData() {
40      Name = "3D BPP Default Instance",
[9348]41      Description = "The default instance for 3D Bin Packing.",
[14055]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))
[9348]85      },
86    };
87    #endregion
[14039]88
[9348]89    [StorableConstructor]
[14049]90    protected Problem(bool deserializing) : base(deserializing) { }
91    protected Problem(Problem original, Cloner cloner)
[9348]92      : base(original, cloner) {
93    }
94    public override IDeepCloneable Clone(Cloner cloner) {
[14049]95      return new Problem(this, cloner);
[9348]96    }
[14049]97    public Problem() : base(
[14054]98      new DecodingEvaluator<Permutation, PackingPosition, PackingShape, PackingItem>()) {
[9348]99    }
100
[14040]101    public void Load(BPPData data) {
[14039]102
103
104      BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
105
[14055]106      PackingBinMeasures = data.BinShape;
107      PackingItemMeasures = new ItemList<PackingItem>(data.Items);
[14039]108
109      ApplyHorizontalOrientation();
110      SortItems();
111      PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
112      LowerBoundParameter.Value.Value = CalculateLowerBound();
113    }
114
[14040]115    public BPPData Export() {
[14055]116      return new BPPData {
[14039]117        Name = Name,
118        Description = Description,
[14055]119        BinShape = PackingBinMeasures,
120        Items = PackingItemMeasures.ToArray()
[14039]121      };
122    }
123
[9348]124    #region Helpers
125    protected override void InitializeDecoder() {
[13607]126      // Operators.RemoveAll(op => op is I2DOperator); TODO
[9495]127
[9563]128      PackingSolutionDecoderParameter.ValidValues.Clear();
[14039]129      if (SolutionCreator is PackingSequenceRandomCreator) {
[9563]130        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>());
[14128]131      } /* else if (SolutionCreator is GroupingVectorRandomCreator) {
[9563]132        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>());
[14039]133      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
[9563]134        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>());
[14128]135      } */ else {
[9348]136        string error = "The given problem does not support the selected solution-creator.";
[13460]137        ErrorHandling.ShowErrorDialog(error, null);
[9348]138      }
139    }
140
[14050]141    protected override IEvaluator CreateDefaultEvaluator() {
142      return new PackingRatioEvaluator();
[9348]143    }
144
145    protected override void InitializeProblemData() {
146      Load(DefaultInstance);
147    }
[9598]148
149    protected override void RemoveTooBigItems() {
[14039]150      PackingItemMeasures.RemoveAll(pi =>
[14048]151        !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, false), pi) &&
152        !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, true), pi));
[9598]153    }
[9348]154    #endregion
155  }
156}
Note: See TracBrowser for help on using the repository browser.