Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/CuboidIdenticalBinPackingProblem.cs @ 13608

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

#1966 refactoring (moved 3d-specific classes into separate project)

File size: 5.6 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
22using HeuristicLab.Problems.BinPacking.Dimensions;
23using HeuristicLab.Problems.BinPacking.Interfaces;
24using HeuristicLab.Problems.BinPacking.PackingBin;
25using HeuristicLab.Problems.BinPacking.PackingItem;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Core;
28using HeuristicLab.Common;
29using HeuristicLab.Problems.BinPacking.Evaluators;
30using HeuristicLab.Encodings.PermutationEncoding;
31using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
32using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
33using HeuristicLab.Problems.Instances;
34using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
35using HeuristicLab.PluginInfrastructure;
36
37namespace HeuristicLab.Problems.BinPacking.Problem {
38  [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.")]
39  [StorableClass]
40  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 310)]
41  public class CuboidIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> {
42
43    #region Default Instance
44    private static readonly BPPData DefaultInstance = new BPPData() { 
45      Name = "3D BPP Default Instance",
46      Description = "The default instance for 3D Bin Packing.",
47      BinMeasures = new int[] {25,25,35},
48      ItemMeasures = new int[][] {
49        new int[] {12,5,10},
50        new int[] {10,18,20},
51        new int[] {9,7,7},
52        new int[] {21,12,4},
53        new int[] {8,8,12},
54        new int[] {3,6,14},
55        new int[] {20,4,9},
56        new int[] {5,9,8},
57        new int[] {7,17,3},
58        new int[] {13,20,15},
59        new int[] {9,11,9},
60        new int[] {10,18,20},
61        new int[] {9,7,7},
62        new int[] {21,12,4},
63        new int[] {8,8,12},
64        new int[] {3,6,14},
65        new int[] {20,4,9},
66        new int[] {5,9,8},
67        new int[] {7,17,3},
68        new int[] {13,20,15},
69        new int[] {9,11,9},
70        new int[] {10,18,20},
71        new int[] {9,7,7},
72        new int[] {21,12,4},
73        new int[] {8,8,12},
74        new int[] {3,6,14},
75        new int[] {20,4,9},
76        new int[] {5,9,8},
77        new int[] {7,17,3},
78        new int[] {13,20,15},
79        new int[] {9,11,9},
80        new int[] {10,18,20},
81        new int[] {9,7,7},
82        new int[] {21,12,4},
83        new int[] {8,8,12},
84        new int[] {3,6,14},
85        new int[] {20,4,9},
86        new int[] {5,9,8},
87        new int[] {7,17,3},
88        new int[] {13,20,15},
89        new int[] {9,11,9}
90      },
91      Items = 30
92    };
93    #endregion
94   
95    [StorableConstructor]
96    protected CuboidIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
97    protected CuboidIdenticalBinPackingProblem(CuboidIdenticalBinPackingProblem original, Cloner cloner)
98      : base(original, cloner) {
99    }
100    public override IDeepCloneable Clone(Cloner cloner) {
101      return new CuboidIdenticalBinPackingProblem(this, cloner);
102    }
103    public CuboidIdenticalBinPackingProblem() : base(
104      new PackingPlanEvaluationAlgorithm<Permutation, ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>()) {
105    }
106
107
108
109    #region Helpers
110    protected override void InitializeDecoder() {
111      // Operators.RemoveAll(op => op is I2DOperator); TODO
112
113      PackingSolutionDecoderParameter.ValidValues.Clear();
114      if (SolutionCreator is PackingSequenceRandomCreator) {   
115        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>());
116      } else if (SolutionCreator is GroupingVectorRandomCreator) {     
117        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>());
118      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {   
119        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>());
120      } else {
121        string error = "The given problem does not support the selected solution-creator.";
122        ErrorHandling.ShowErrorDialog(error, null);
123      }
124    }
125
126    protected override IPackingPlanEvaluator CreateDefaultEvaluator() {
127      return new PackingRatioCuboidIdenticalBinEvaluator();
128    }
129
130    protected override void InitializeProblemData() {
131      Load(DefaultInstance);
132    }
133
134    protected override void RemoveTooBigItems() {
135      PackingItemMeasures.RemoveAll(pi =>
136        !PackingBinMeasures.Encloses (new ThreeDimensionalPacking(0, 0, 0, 0, false), pi) &&
137        !PackingBinMeasures.Encloses(new ThreeDimensionalPacking(0, 0, 0, 0, true), pi));
138    }
139    #endregion
140  }
141}
Note: See TracBrowser for help on using the repository browser.