source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/PermutationProblem.cs @ 14149

Last change on this file since 14149 was 14149, checked in by gkronber, 6 years ago

#1966: refactoring 2d problem

File size: 3.0 KB
Line 
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
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.PermutationEncoding;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.Problems.Instances;
33
34namespace HeuristicLab.Problems.BinPacking2D {
35  [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.")]
36  [StorableClass]
37  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)]
38  public sealed class PermutationProblem : ProblemBase<PermutationEncoding, Permutation> {
39    // persistence
40    [StorableConstructor]
41    private PermutationProblem(bool deserializing) : base(deserializing) { }
42
43    // cloning
44    private PermutationProblem(PermutationProblem original, Cloner cloner)
45      : base(original, cloner) {
46      RegisterEventHandlers();
47    }
48
49    public PermutationProblem()
50      : base() {
51      Decoder = new ExtremePointPermutationDecoder(); // default decoder
52
53      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
54      AddOperators();
55      RegisterEventHandlers();
56    }
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new PermutationProblem(this, cloner);
59    }
60
61    [StorableHook(HookType.AfterDeserialization)]
62    private void AfterDeserialization() {
63      RegisterEventHandlers();
64    }
65
66
67    private void AddOperators() {
68      Operators.Add(new TranslocationMoveEvaluator());
69      Operators.Add(new Swap2MoveEvaluator());
70
71      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
72      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
73      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
74
75      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
76    }
77
78    private void RegisterEventHandlers() {
79      // update encoding length when number of items is changed
80      ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count;
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.