[14128] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
| 4 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System.Linq;
|
---|
[14154] | 25 | using System.Windows.Forms;
|
---|
[14128] | 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
[14149] | 32 | namespace HeuristicLab.Problems.BinPacking2D {
|
---|
[14146] | 33 | [Item("Bin Packing Problem (2D, permutation encoding) (BPP)", "Represents a two-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")]
|
---|
[14128] | 34 | [StorableClass]
|
---|
| 35 | [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)]
|
---|
[14149] | 36 | public sealed class PermutationProblem : ProblemBase<PermutationEncoding, Permutation> {
|
---|
[14146] | 37 | // persistence
|
---|
| 38 | [StorableConstructor]
|
---|
[14149] | 39 | private PermutationProblem(bool deserializing) : base(deserializing) { }
|
---|
[14128] | 40 |
|
---|
| 41 | // cloning
|
---|
[14149] | 42 | private PermutationProblem(PermutationProblem original, Cloner cloner)
|
---|
[14128] | 43 | : base(original, cloner) {
|
---|
[14146] | 44 | RegisterEventHandlers();
|
---|
[14128] | 45 | }
|
---|
| 46 |
|
---|
[14149] | 47 | public PermutationProblem()
|
---|
[14146] | 48 | : base() {
|
---|
[14149] | 49 | Decoder = new ExtremePointPermutationDecoder(); // default decoder
|
---|
[14128] | 50 |
|
---|
[14149] | 51 | Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
|
---|
[14146] | 52 | AddOperators();
|
---|
| 53 | RegisterEventHandlers();
|
---|
| 54 | }
|
---|
[14128] | 55 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[14149] | 56 | return new PermutationProblem(this, cloner);
|
---|
[14128] | 57 | }
|
---|
| 58 |
|
---|
[14146] | 59 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 60 | private void AfterDeserialization() {
|
---|
| 61 | RegisterEventHandlers();
|
---|
| 62 | }
|
---|
[14128] | 63 |
|
---|
[14146] | 64 |
|
---|
| 65 | private void AddOperators() {
|
---|
| 66 | Operators.Add(new TranslocationMoveEvaluator());
|
---|
[14147] | 67 | Operators.Add(new Swap2MoveEvaluator());
|
---|
[14146] | 68 |
|
---|
| 69 | Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
|
---|
| 70 | Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
|
---|
| 71 | Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
|
---|
| 72 |
|
---|
| 73 | Encoding.ConfigureOperators(Operators.OfType<IOperator>());
|
---|
[14153] | 74 |
|
---|
[14154] | 75 | foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
|
---|
| 76 | op.BinShapeParameter.ActualName = BinShapeParameter.Name;
|
---|
| 77 | op.ItemsParameter.ActualName = ItemsParameter.Name;
|
---|
| 78 | op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
|
---|
| 79 | op.DecoderParameter.ActualName = DecoderParameter.Name;
|
---|
| 80 | }
|
---|
[14146] | 81 | }
|
---|
| 82 |
|
---|
| 83 | private void RegisterEventHandlers() {
|
---|
| 84 | // update encoding length when number of items is changed
|
---|
| 85 | ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count;
|
---|
| 86 | }
|
---|
[14128] | 87 | }
|
---|
| 88 | }
|
---|