Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2520_PersistenceReintegration/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/PermutationProblem.cs @ 16559

Last change on this file since 16559 was 16559, checked in by jkarder, 5 years ago

#2520: renamed Fossil to Attic and set version to 1.0.0-pre01

File size: 4.1 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2019 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 HEAL.Attic;
32
33namespace HeuristicLab.Problems.BinPacking3D {
34  [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.")]
35  [StorableType("84B8B871-C360-43BD-BFC3-F6F16B379439")]
36  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 320)]
37  public sealed class PermutationProblem : ProblemBase<PermutationEncoding, Permutation> {
38    [StorableConstructor]
39    private PermutationProblem(StorableConstructorFlag _) : base(_) { }
40
41    // cloning
42    private PermutationProblem(PermutationProblem original, Cloner cloner)
43      : base(original, cloner) {
44      RegisterEventHandlers();
45    }
46
47    public PermutationProblem()
48      : base() {
49      Decoder = new ExtremePointPermutationDecoder(); // default decoder
50
51      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
52      AddOperators();
53      Parameterize();
54      RegisterEventHandlers();
55    }
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new PermutationProblem(this, cloner);
58    }
59
60    [StorableHook(HookType.AfterDeserialization)]
61    private void AfterDeserialization() {
62      RegisterEventHandlers();
63    }
64
65    protected override void OnEncodingChanged() {
66      base.OnEncodingChanged();
67      Parameterize();
68    }
69
70    private void AddOperators() {
71      Operators.Add(new TranslocationMoveEvaluator());
72      Operators.Add(new Swap2MoveEvaluator());
73
74      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
75      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
76      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
77      Operators.Add(new HammingSimilarityCalculator());
78      Operators.Add(new QualitySimilarityCalculator());
79      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
80
81      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
82
83      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
84        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
85        op.ItemsParameter.ActualName = ItemsParameter.Name;
86        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
87        op.DecoderParameter.ActualName = DecoderParameter.Name;
88        op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name;
89      }
90    }
91
92    private void RegisterEventHandlers() {
93      // update encoding length when number of items is changed
94      ItemsParameter.ValueChanged += (sender, args) => Parameterize();
95    }
96
97    private void Parameterize() {
98      Encoding.Length = Items.Count;
99      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
100        similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.PermutationParameter.ActualName;
101        similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName;
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.