#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.BinPacking3D { [Item("Bin Packing Problem (3D, permutation encoding) (BPP)", "Represents a three-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")] [StorableClass] [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 320)] public sealed class PermutationProblem : ProblemBase { [StorableConstructor] private PermutationProblem(bool deserializing) : base(deserializing) { } // cloning private PermutationProblem(PermutationProblem original, Cloner cloner) : base(original, cloner) { RegisterEventHandlers(); } public PermutationProblem() : base() { Decoder = new ExtremePointPermutationDecoder(); // default decoder Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute); AddOperators(); RegisterEventHandlers(); } public override IDeepCloneable Clone(Cloner cloner) { return new PermutationProblem(this, cloner); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { RegisterEventHandlers(); } private void AddOperators() { Operators.Add(new TranslocationMoveEvaluator()); Operators.Add(new Swap2MoveEvaluator()); Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator); Operators.RemoveAll(x => x is SingleObjectiveMoveMaker); Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); Encoding.ConfigureOperators(Operators.OfType()); foreach (var op in Operators.OfType>()) { op.BinShapeParameter.ActualName = BinShapeParameter.Name; op.ItemsParameter.ActualName = ItemsParameter.Name; op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name; op.DecoderParameter.ActualName = DecoderParameter.Name; op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name; } } private void RegisterEventHandlers() { // update encoding length when number of items is changed ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count; } } }