Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1966: simplified parsers

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