Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Encoding/PermutationProblem.cs @ 15488

Last change on this file since 15488 was 15488, checked in by rhanghof, 6 years ago

#2817:

  • Added line projection based bin packing
  • Added residual spaces to the view
File size: 4.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.Analysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Encodings.PermutationEncoding;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.Problems.BinPacking3D.Encoding;
33using HeuristicLab.Problems.BinPacking3D.Packer;
34using HeuristicLab.Problems.BinPacking3D.Evaluators;
35
36namespace HeuristicLab.Problems.BinPacking3D {
37  [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.")]
38  [StorableClass]
39  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 320)]
40  public sealed class PermutationProblem : ProblemBase<Encodings.PermutationEncoding.PermutationEncoding, Permutation> {
41    [StorableConstructor]
42    private PermutationProblem(bool deserializing) : base(deserializing) { }
43
44    // cloning
45    private PermutationProblem(PermutationProblem original, Cloner cloner)
46      : base(original, cloner) {
47      RegisterEventHandlers();
48    }
49
50    public PermutationProblem()
51      : base() {
52      Decoder = new ExtremePointPermutationDecoder(); // default decoder
53
54      Encoding = new Encodings.PermutationEncoding.PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
55      AddOperators();
56      Parameterize();
57      RegisterEventHandlers();
58    }
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new PermutationProblem(this, cloner);
61    }
62
63    [StorableHook(HookType.AfterDeserialization)]
64    private void AfterDeserialization() {
65      RegisterEventHandlers();
66    }
67
68    protected override void OnEncodingChanged() {
69      base.OnEncodingChanged();
70      Parameterize();
71    }
72
73    private void AddOperators() {
74      Operators.Add(new TranslocationMoveEvaluator());
75      Operators.Add(new Swap2MoveEvaluator());
76
77      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
78      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
79      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
80      Operators.Add(new HammingSimilarityCalculator());
81      Operators.Add(new QualitySimilarityCalculator());
82      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
83
84      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
85
86      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
87        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
88        op.ItemsParameter.ActualName = ItemsParameter.Name;
89        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
90        op.DecoderParameter.ActualName = DecoderParameter.Name;
91        op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name;
92      }
93    }
94
95    private void RegisterEventHandlers() {
96      // update encoding length when number of items were changed
97      ItemsParameter.ValueChanged += (sender, args) => Parameterize();
98    }
99
100    private void Parameterize() {
101      Encoding.Length = Items.Count;
102      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
103        similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.PermutationParameter.ActualName;
104        similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName;
105      }
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.