[14128] | 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 |
|
---|
| 24 | using System;
|
---|
| 25 | using System.CodeDom;
|
---|
| 26 | using System.Linq;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 32 | using HeuristicLab.Optimization;
|
---|
| 33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 34 | using HeuristicLab.Problems.BinPacking;
|
---|
| 35 | using HeuristicLab.Problems.BinPacking2D;
|
---|
| 36 |
|
---|
| 37 | namespace 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 | }
|
---|