#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.PermutationEncoding; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.BinPacking2D { [Item("Swap2MoveEvaluator", "Move evaluator for 2-opt moves.")] [StorableClass] public sealed class Swap2MoveEvaluator : SingleSuccessorOperator, ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IPermutationSwap2MoveOperator { public override bool CanChangeName { get { return false; } } public ILookupParameter PermutationParameter { get { return (ILookupParameter)Parameters["PackingSequence"]; } } public ILookupParameter QualityParameter { get { return (ILookupParameter)Parameters["Quality"]; } } public ILookupParameter MoveQualityParameter { get { return (ILookupParameter)Parameters["MoveQuality"]; } } public ILookupParameter> PackingItemMeasuresParameter { get { return (LookupParameter>)Parameters["Items"]; } } public ILookupParameter PackingBinMeasuresParameter { get { return (LookupParameter)Parameters["BinShape"]; } } public ILookupParameter PackingSolutionDecoderParameter { get { return (ILookupParameter)Parameters["Decoder"]; } } public ILookupParameter PackingPlanEvaluatorParameter { get { return (ILookupParameter)Parameters["SolutionEvaluator"]; } } public ILookupParameter Swap2MoveParameter { get { return (ILookupParameter)Parameters["Swap2Move"]; } } [StorableConstructor] private Swap2MoveEvaluator(bool deserializing) : base(deserializing) { } private Swap2MoveEvaluator(Swap2MoveEvaluator original, Cloner cloner) : base(original, cloner) { } public Swap2MoveEvaluator() : base() { Parameters.Add(new LookupParameter("PackingSequence", "The encoded solution candidate to evaluate")); Parameters.Add(new LookupParameter("Quality", "The quality of a packing solution.")); Parameters.Add(new LookupParameter("MoveQuality", "The evaluated quality of a move on a packing solution.")); Parameters.Add(new LookupParameter>("Items", "Packing-item data taken from the bin-packing problem-instance.")); Parameters.Add(new LookupParameter("BinShape", "Packing-bin data taken from the bin-packing problem-instance.")); Parameters.Add(new LookupParameter("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation.")); Parameters.Add(new LookupParameter("SolutionEvaluator", "The actual packing plan evaluation operator.")); Parameters.Add(new LookupParameter("Swap2Move", "The move to evaluate.")); } public override IDeepCloneable Clone(Cloner cloner) { return new Swap2MoveEvaluator(this, cloner); } public override IOperation Apply() { var move = Swap2MoveParameter.ActualValue; var permutation = PermutationParameter.ActualValue; var binShape = PackingBinMeasuresParameter.ActualValue; var items = PackingItemMeasuresParameter.ActualValue; // uses full evaluation Swap2Manipulator.Apply(permutation, move.Index1, move.Index2); var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items); var quality = PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution); double moveQuality = quality; if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality); else MoveQualityParameter.ActualValue.Value = moveQuality; return base.Apply(); } } }