Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Problem/RectangularIdenticalBinPackingProblem.cs @ 12966

Last change on this file since 12966 was 9598, checked in by jhelm, 12 years ago

#1966: Fixed a bug which caused the stacking-contraint to be wrongly enforced; Did some cleanup;

File size: 5.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Problems.BinPacking.Dimensions;
27using HeuristicLab.Problems.BinPacking.Interfaces;
28using HeuristicLab.Problems.BinPacking.Shapes;
29using HeuristicLab.Problems.BinPacking.PackingBin;
30using HeuristicLab.Problems.BinPacking.PackingItem;
31using HeuristicLab.Core;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.Common;
34using HeuristicLab.Optimization;
35using HeuristicLab.Problems.BinPacking.Evaluators;
36using HeuristicLab.Encodings.PermutationEncoding;
37using HeuristicLab.PluginInfrastructure;
38using HeuristicLab.Parameters;
39using HeuristicLab.Data;
40using HeuristicLab.Problems.BinPacking.Decoders;
41using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
42using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
43using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
44using HeuristicLab.Problems.Instances;
45using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
46
47namespace HeuristicLab.Problems.BinPacking.Problem {
48  [Item("RectangularIdenticalBinPackingProblem", "Represents a two-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")]
49  [StorableClass]
50  [Creatable("Problems")]
51  public class RectangularIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> {
52
53    #region Default Instance
54    private static readonly BPPData DefaultInstance = new BPPData() {
55      Name = "2D BPP Default Instance",
56      Description = "The default instance for 2D Bin Packing.",
57      BinMeasures = new int[] { 20, 16 },
58      ItemMeasures = new int[][] {
59        new int[] {3,8},
60        new int[] {5,3},
61        new int[] {9,3},
62        new int[] {2,7},
63        new int[] {5,3},
64        new int[] {9,3},
65        new int[] {2,7},
66        new int[] {5,3},
67        new int[] {9,3},
68        new int[] {2,7},
69        new int[] {5,3},
70        new int[] {9,3},
71        new int[] {2,7},
72        new int[] {5,3},
73        new int[] {9,3},
74        new int[] {2,7},
75        new int[] {5,3},
76        new int[] {9,3},
77        new int[] {2,7},
78        new int[] {5,3},
79        new int[] {9,3},
80        new int[] {2,7},
81        new int[] {5,3},
82        new int[] {9,3},
83        new int[] {2,7},
84        new int[] {5,3},
85        new int[] {9,3},
86        new int[] {2,7},
87        new int[] {5,3},
88        new int[] {9,3},
89        new int[] {2,7},
90        new int[] {5,3},
91        new int[] {9,3},
92        new int[] {2,7},
93        new int[] {5,3},
94        new int[] {9,3},
95        new int[] {2,7}
96      },
97      Items = 30
98    };
99    #endregion
100
101    [StorableConstructor]
102    protected RectangularIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
103    protected RectangularIdenticalBinPackingProblem(RectangularIdenticalBinPackingProblem original, Cloner cloner)
104      : base(original, cloner) {
105    }
106    public override IDeepCloneable Clone(Cloner cloner) {
107      return new RectangularIdenticalBinPackingProblem(this, cloner);
108    }
109    public RectangularIdenticalBinPackingProblem() : base(
110      new PackingPlanEvaluationAlgorithm<Permutation, TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>()) {
111    }
112
113
114    #region Helpers
115    protected override void InitializeDecoder() {
116      Operators.RemoveAll(op => typeof(I3DOperator).IsAssignableFrom(op.GetType()));
117
118      PackingSolutionDecoderParameter.ValidValues.Clear();
119      if (SolutionCreator is PackingSequenceRandomCreator) {       
120        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DPSDecoder>());
121        //PackingSolutionDecoder = new ExtremePointPackingSequenceDecoder2D();
122      } else if (SolutionCreator is GroupingVectorRandomCreator) { 
123        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DGVDecoder>());
124        //PackingSolutionDecoder = new ExtremePointGroupingVectorDecoder2D();
125      } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 
126        PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DMCVDecoder>());
127        //PackingSolutionDecoder = new ExtremePointMultiComponentVectorDecoder2D();
128      } else {
129        string error = "The given problem does not support the selected solution-creator.";
130        PluginInfrastructure.ErrorHandling.ShowErrorDialog(error, null);
131      }
132    }
133
134    protected override IPackingPlanEvaluator CreateDefaultEvaluator() {
135      return new PackingRatioRectangularIdenticalBinEvaluator ();
136    }
137
138    protected override void InitializeProblemData() {
139      Load(DefaultInstance);
140    }
141
142    protected override void RemoveTooBigItems() {
143      PackingItemMeasures.RemoveAll(pi =>
144        !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, false), pi) &&
145        !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, true), pi));
146    }
147    #endregion
148  }
149}
Note: See TracBrowser for help on using the repository browser.