#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence; namespace HeuristicLab.Problems.BinPacking2D { [StorableType("691c3981-3242-4540-a119-c0faa2c28e4e")] public abstract class MoveEvaluatorBase : SingleSuccessorOperator, ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator where TSol : class, IItem where TMove : class, IItem { public ILookupParameter EncodedSolutionParameter { get { return (ILookupParameter)Parameters["EncodedSolution"]; } } public ILookupParameter QualityParameter { get { return (ILookupParameter)Parameters["Quality"]; } } public ILookupParameter MoveQualityParameter { get { return (ILookupParameter)Parameters["MoveQuality"]; } } public ILookupParameter> ItemsParameter { get { return (LookupParameter>)Parameters["Items"]; } } public ILookupParameter BinShapeParameter { get { return (LookupParameter)Parameters["BinShape"]; } } public ILookupParameter> DecoderParameter { get { return (ILookupParameter>)Parameters["Decoder"]; } } public ILookupParameter SolutionEvaluatorParameter { get { return (ILookupParameter)Parameters["SolutionEvaluator"]; } } public ILookupParameter MoveParameter { get { return (ILookupParameter)Parameters["Move"]; } } [StorableConstructor] protected MoveEvaluatorBase(bool deserializing) : base(deserializing) { } protected MoveEvaluatorBase(MoveEvaluatorBase original, Cloner cloner) : base(original, cloner) { } protected MoveEvaluatorBase() : base() { Parameters.Add(new LookupParameter("EncodedSolution", "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("Move", "The move to evaluate.")); } public override IOperation Apply() { var move = MoveParameter.ActualValue; var encSolCandidate = EncodedSolutionParameter.ActualValue; var binShape = BinShapeParameter.ActualValue; var items = ItemsParameter.ActualValue; double moveQuality = EvaluateMove(encSolCandidate, move, binShape, items); if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality); else MoveQualityParameter.ActualValue.Value = moveQuality; return base.Apply(); } public abstract double EvaluateMove(TSol encodedSolutionCandidate, TMove move, PackingShape binShape, ReadOnlyItemList items); } }