[9440] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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 System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[9495] | 26 | using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
|
---|
[9440] | 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[9495] | 31 | using HeuristicLab.Problems.BinPacking.Decoders;
|
---|
| 32 | using HeuristicLab.Problems.BinPacking.Evaluators;
|
---|
[9440] | 33 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
| 34 | using HeuristicLab.Problems.BinPacking.Shapes;
|
---|
| 35 |
|
---|
| 36 | namespace HeuristicLab.Problems.BinPacking {
|
---|
| 37 | [Item("PackingMoveEvaluator", "A base class for operators which evaluate Packing-Solution moves.")]
|
---|
| 38 | [StorableClass]
|
---|
| 39 | public abstract class PackingMoveEvaluator<D, B, I> : SingleSuccessorOperator, IPackingMoveEvaluator, IMoveOperator
|
---|
| 40 | where D : class, IPackingDimensions
|
---|
[9495] | 41 | where B : PackingShape<D>, IPackingBin, IRegularPackingShape
|
---|
| 42 | where I : PackingShape<D>, IPackingItem, IRegularPackingShape {
|
---|
[9440] | 43 | public override bool CanChangeName {
|
---|
| 44 | get { return false; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 48 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 49 | }
|
---|
| 50 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 51 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 52 | }
|
---|
| 53 | public ILookupParameter<ItemList<I>> PackingItemMeasuresParameter {
|
---|
| 54 | get { return (LookupParameter<ItemList<I>>)Parameters["PackingItemMeasures"]; }
|
---|
| 55 | }
|
---|
| 56 | public ILookupParameter<B> PackingBinMeasuresParameter {
|
---|
| 57 | get { return (LookupParameter<B>)Parameters["PackingBinMeasures"]; }
|
---|
| 58 | }
|
---|
| 59 | public IValueLookupParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter {
|
---|
| 60 | get { return (IValueLookupParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; }
|
---|
| 61 | }
|
---|
| 62 | public IValueLookupParameter<IPackingPlanEvaluator> PackingPlanEvaluatorParameter {
|
---|
| 63 | get { return (IValueLookupParameter<IPackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }
|
---|
| 64 | }
|
---|
[9495] | 65 | protected ScopeParameter CurrentScopeParameter {
|
---|
| 66 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
| 67 | }
|
---|
| 68 | public ILookupParameter<IPackingMove> PackingMoveParameter {
|
---|
| 69 | get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
|
---|
| 70 | }
|
---|
[9440] | 71 |
|
---|
| 72 | [StorableConstructor]
|
---|
| 73 | protected PackingMoveEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 74 | protected PackingMoveEvaluator(PackingMoveEvaluator<D, B, I> original, Cloner cloner) : base(original, cloner) { }
|
---|
| 75 | protected PackingMoveEvaluator()
|
---|
| 76 | : base() {
|
---|
| 77 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
|
---|
| 78 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
|
---|
| 79 | Parameters.Add(new LookupParameter<ItemList<I>>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance."));
|
---|
| 80 | Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance."));
|
---|
| 81 | Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
|
---|
| 82 | Parameters.Add(new ValueLookupParameter<IPackingPlanEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));
|
---|
[9495] | 83 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the decoded solution should be added to."));
|
---|
| 84 | Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
|
---|
[9440] | 85 | }
|
---|
[9495] | 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | public override IOperation Apply() {
|
---|
| 90 | IPackingMove move = PackingMoveParameter.ActualValue;
|
---|
| 91 | IPackingSolutionEncoding newSolution = move.GetSolutionAfterMove();
|
---|
| 92 | CurrentScopeParameter.ActualValue.Variables.Add(new Variable("MovedSolution", newSolution));
|
---|
| 93 |
|
---|
| 94 | PackingPlan<D, B, I> packingPlan = (PackingSolutionDecoderParameter.ActualValue as PackingSolutionDecoder<D, B, I>).
|
---|
| 95 | CreatePackingPlanFromEncoding(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan));
|
---|
| 99 |
|
---|
[9563] | 100 | DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator<D, B, I>.CalculatePackingRatio(packingPlan);
|
---|
[9495] | 101 |
|
---|
| 102 | double moveQuality = quality.Value;
|
---|
| 103 |
|
---|
| 104 | if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
|
---|
| 105 | else MoveQualityParameter.ActualValue.Value = moveQuality;
|
---|
| 106 | return base.Apply();
|
---|
| 107 | }
|
---|
[9440] | 108 | }
|
---|
| 109 | }
|
---|