[14147] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.BinPacking2D {
|
---|
| 32 | [Item("TranslocationMoveEvaluator", "Move evaluator for insertion or translocation moves.")]
|
---|
| 33 | [StorableClass]
|
---|
| 34 | public sealed class TranslocationMoveEvaluator : SingleSuccessorOperator,
|
---|
| 35 | ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IPermutationTranslocationMoveOperator {
|
---|
| 36 | public override bool CanChangeName {
|
---|
| 37 | get { return false; }
|
---|
| 38 | }
|
---|
| 39 | public ILookupParameter<Permutation> PermutationParameter {
|
---|
| 40 | get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; }
|
---|
| 41 | }
|
---|
| 42 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 43 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 44 | }
|
---|
| 45 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 46 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 47 | }
|
---|
| 48 | public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {
|
---|
| 49 | get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
|
---|
| 50 | }
|
---|
| 51 | public ILookupParameter<PackingShape> PackingBinMeasuresParameter {
|
---|
| 52 | get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; }
|
---|
| 53 | }
|
---|
| 54 | public ILookupParameter<IPermutationDecoder> PackingSolutionDecoderParameter {
|
---|
| 55 | get { return (ILookupParameter<IPermutationDecoder>)Parameters["Decoder"]; }
|
---|
| 56 | }
|
---|
| 57 | public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
|
---|
| 58 | get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public ILookupParameter<TranslocationMove> TranslocationMoveParameter {
|
---|
| 62 | get { return (ILookupParameter<TranslocationMove>)Parameters["TranslocationMove"]; }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | [StorableConstructor]
|
---|
| 66 | private TranslocationMoveEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 67 | private TranslocationMoveEvaluator(TranslocationMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
| 68 | public TranslocationMoveEvaluator()
|
---|
| 69 | : base() {
|
---|
| 70 | Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The encoded solution candidate to evaluate"));
|
---|
| 71 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
|
---|
| 72 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
|
---|
| 73 | Parameters.Add(new LookupParameter<ReadOnlyItemList<PackingItem>>("Items", "Packing-item data taken from the bin-packing problem-instance."));
|
---|
| 74 | Parameters.Add(new LookupParameter<PackingShape>("BinShape", "Packing-bin data taken from the bin-packing problem-instance."));
|
---|
| 75 | Parameters.Add(new LookupParameter<IPermutationDecoder>("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
|
---|
| 76 | Parameters.Add(new LookupParameter<IEvaluator>("SolutionEvaluator", "The actual packing plan evaluation operator."));
|
---|
| 77 | Parameters.Add(new LookupParameter<TranslocationMove>("TranslocationMove", "The move to evaluate."));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | return new TranslocationMoveEvaluator(this, cloner);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | public override IOperation Apply() {
|
---|
| 86 | var move = TranslocationMoveParameter.ActualValue;
|
---|
| 87 | var permutation = PermutationParameter.ActualValue;
|
---|
| 88 | var binShape = PackingBinMeasuresParameter.ActualValue;
|
---|
| 89 | var items = PackingItemMeasuresParameter.ActualValue;
|
---|
| 90 |
|
---|
| 91 | // uses full evaluation
|
---|
| 92 |
|
---|
| 93 | TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3);
|
---|
| 94 | var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);
|
---|
| 95 |
|
---|
| 96 | var quality = PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);
|
---|
| 97 |
|
---|
| 98 | double moveQuality = quality;
|
---|
| 99 |
|
---|
| 100 | if (MoveQualityParameter.ActualValue == null)
|
---|
| 101 | MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
|
---|
| 102 | else
|
---|
| 103 | MoveQualityParameter.ActualValue.Value = moveQuality;
|
---|
| 104 | return base.Apply();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|