Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.BinPacking/3.3/2D/PermutationEncoding/PermutationProblem.cs @ 16755

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

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

File size: 4.1 KB
RevLine 
[14162]1#region License Information
2
3/* HeuristicLab
[16565]4 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[14162]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;
[15069]25using HeuristicLab.Analysis;
[14162]26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Encodings.PermutationEncoding;
29using HeuristicLab.Optimization;
[15069]30using HeuristicLab.Optimization.Operators;
[16565]31using HEAL.Attic;
[14162]32
33namespace HeuristicLab.Problems.BinPacking2D {
34  [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.")]
[16565]35  [StorableType("BE95CC5D-7FFD-4BC7-A2FF-7D71D3B951F6")]
[14162]36  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)]
37  public sealed class PermutationProblem : ProblemBase<PermutationEncoding, Permutation> {
38    // persistence
39    [StorableConstructor]
[16565]40    private PermutationProblem(StorableConstructorFlag _) : base(_) { }
[14162]41
42    // cloning
43    private PermutationProblem(PermutationProblem original, Cloner cloner)
44      : base(original, cloner) {
45      RegisterEventHandlers();
46    }
47
48    public PermutationProblem()
49      : base() {
50      Decoder = new ExtremePointPermutationDecoder(); // default decoder
51
52      Encoding = new PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
53      AddOperators();
[15069]54      Parameterize();
[14162]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
[15069]66    protected override void OnEncodingChanged() {
67      base.OnEncodingChanged();
68      Parameterize();
69    }
[14162]70
71    private void AddOperators() {
72      Operators.Add(new TranslocationMoveEvaluator());
73      Operators.Add(new Swap2MoveEvaluator());
74
75      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
76      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
77      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
[15069]78      Operators.Add(new HammingSimilarityCalculator());
79      Operators.Add(new QualitySimilarityCalculator());
80      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
[14162]81
82      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
83
84      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
85        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
86        op.ItemsParameter.ActualName = ItemsParameter.Name;
87        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
88        op.DecoderParameter.ActualName = DecoderParameter.Name;
89      }
90    }
91
92    private void RegisterEventHandlers() {
93      // update encoding length when number of items is changed
[15069]94      ItemsParameter.ValueChanged += (sender, args) => Parameterize();
[14162]95    }
[15069]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    }
[14162]104  }
105}
Note: See TracBrowser for help on using the repository browser.