source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PackingSequenceProblem.cs @ 14128

Last change on this file since 14128 was 14128, checked in by gkronber, 5 years ago

#1966: refactoring of bin packing implementation

File size: 2.8 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;
25using System.CodeDom;
26using System.Linq;
27using System.Text;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Encodings.PermutationEncoding;
32using HeuristicLab.Optimization;
33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
34using HeuristicLab.Problems.BinPacking;
35using HeuristicLab.Problems.BinPacking2D;
36
37namespace HeuristicLab.Problems.BinPacking2d {
38  [StorableClass]
39  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)]
40  public class PackingSequenceProblem : PackingSequenceProblem<Permutation, PermutationEncoding> {
41
42    // persistence
43    [StorableConstructor]
44    protected PackingSequenceProblem(bool deserializing) : base(deserializing) { }
45    [StorableHook(HookType.AfterDeserialization)]
46    private void AfterDeserialization() { }
47
48    public override bool Maximization {
49      get { return true; }
50    }
51
52
53    // cloning
54    protected PackingSequenceProblem(PackingSequenceProblem original, Cloner cloner)
55      : base(original, cloner) {
56    }
57
58    protected PackingSequenceProblem() : base() { }
59
60
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new PackingSequenceProblem(this, cloner);
63    }
64
65
66    public override double Evaluate(Individual individual, IRandom random) {
67      var permutation = individual.Permutation();
68      var decoder = new ExtremePointPackingSequenceDecoder2D();
69      var packingPlan = decoder.CreatePackingPlanFromEncoding(permutation, Bin, Items);
70      var ratio = PackingRatioEvaluator.CalculatePackingRatio(packingPlan);
71      return ratio.Value;
72    }
73
74    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
75      base.Analyze(individuals, qualities, results, random);
76      Analyze(individuals.Select(i => i.Permutation()).ToArray(), qualities, results, random);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.