Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/PermutationProblem.cs @ 14167

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

#2641:

  • fixed persistence bug
  • added unit test to create BPP sample
  • added BPP sample to start page
  • renaming of properties
File size: 3.4 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.Encodings.PermutationEncoding;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.BinPacking3D {
32  [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.")]
33  [StorableClass]
34  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 320)]
35  public sealed class PermutationProblem : ProblemBase<PermutationEncoding, Permutation> {
36    [StorableConstructor]
37    private PermutationProblem(bool deserializing) : base(deserializing) { }
38
39    // cloning
40    private PermutationProblem(PermutationProblem original, Cloner cloner)
41      : base(original, cloner) {
42      RegisterEventHandlers();
43    }
44
45    public PermutationProblem()
46      : base() {
47      Decoder = new ExtremePointPermutationDecoder(); // default decoder
48
49      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
50      AddOperators();
51      RegisterEventHandlers();
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new PermutationProblem(this, cloner);
55    }
56
57    [StorableHook(HookType.AfterDeserialization)]
58    private void AfterDeserialization() {
59      RegisterEventHandlers();
60    }
61
62
63    private void AddOperators() {
64      Operators.Add(new TranslocationMoveEvaluator());
65      Operators.Add(new Swap2MoveEvaluator());
66
67      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
68      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
69      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
70
71      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
72
73      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
74        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
75        op.ItemsParameter.ActualName = ItemsParameter.Name;
76        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
77        op.DecoderParameter.ActualName = DecoderParameter.Name;
78        op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name;
79      }
80    }
81
82    private void RegisterEventHandlers() {
83      // update encoding length when number of items is changed
84      ItemsParameter.ValueChanged += (sender, args) => Encoding.Length = Items.Count;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.