#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Problems.BinPacking.Dimensions; using HeuristicLab.Problems.BinPacking.Interfaces; using HeuristicLab.Problems.BinPacking.Shapes; using HeuristicLab.Problems.BinPacking.PackingBin; using HeuristicLab.Problems.BinPacking.PackingItem; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Optimization; using HeuristicLab.Problems.BinPacking.Evaluators; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Parameters; using HeuristicLab.Data; using HeuristicLab.Problems.BinPacking.Decoders; using HeuristicLab.Encodings.PackingEncoding.PackingPlan; using HeuristicLab.Encodings.PackingEncoding.PackingSequence; using HeuristicLab.Encodings.PackingEncoding.GroupingVector; using HeuristicLab.Problems.Instances; using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; namespace HeuristicLab.Problems.BinPacking.Problem { [Item("RectangularIdenticalBinPackingProblem", "Represents a two-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")] [StorableClass] [Creatable("Problems")] public class RectangularIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem { #region Default Instance private static readonly BPPData DefaultInstance = new BPPData() { Name = "2D BPP Default Instance", Description = "The default instance for 2D Bin Packing.", BinMeasures = new int[] { 20, 16 }, ItemMeasures = new int[][] { new int[] {3,8}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7}, new int[] {5,3}, new int[] {9,3}, new int[] {2,7} }, Items = 30 }; #endregion [StorableConstructor] protected RectangularIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { } protected RectangularIdenticalBinPackingProblem(RectangularIdenticalBinPackingProblem original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new RectangularIdenticalBinPackingProblem(this, cloner); } public RectangularIdenticalBinPackingProblem() : base( new PackingPlanEvaluationAlgorithm()) { } #region Helpers protected override void InitializeDecoder() { Operators.RemoveAll(op => typeof(I3DOperator).IsAssignableFrom(op.GetType())); PackingSolutionDecoderParameter.ValidValues.Clear(); if (SolutionCreator is PackingSequenceRandomCreator) { PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances()); //PackingSolutionDecoder = new ExtremePointPackingSequenceDecoder2D(); } else if (SolutionCreator is GroupingVectorRandomCreator) { PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances()); //PackingSolutionDecoder = new ExtremePointGroupingVectorDecoder2D(); } else if (SolutionCreator is MultiComponentVectorRandomCreator) { PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances()); //PackingSolutionDecoder = new ExtremePointMultiComponentVectorDecoder2D(); } else { string error = "The given problem does not support the selected solution-creator."; PluginInfrastructure.ErrorHandling.ShowErrorDialog(error, null); } } protected override IPackingPlanEvaluator CreateDefaultEvaluator() { return new PackingRatioRectangularIdenticalBinEvaluator (); } protected override void InitializeProblemData() { Load(DefaultInstance); } protected override void RemoveTooBigItems() { PackingItemMeasures.RemoveAll(pi => !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, false), pi) && !PackingBinMeasures.Encloses(new TwoDimensionalPacking(0, 0, 0, true), pi)); } #endregion } }