#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 System; using HeuristicLab.Operators; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Data; using HeuristicLab.Parameters; namespace HeuristicLab.Problems.BinPacking { [Item("Packingplan Evaluation Algorithm", "Represents a composition of a decoder and an evaluator for bin-packing problems.")] [StorableClass] public class PackingPlanEvaluationAlgorithm : SingleSuccessorOperator, IPackingPlanEvaluationAlgorithm where E : Item //E defines the used Encoding where D : class, IPackingPosition where B : PackingShape where I : PackingShape, IPackingItem { public IValueLookupParameter PackingSolutionDecoderParameter { get { return (IValueLookupParameter)Parameters["PackingSolutionDecoder"]; } } ILookupParameter IPackingPlanEvaluationAlgorithm.PackingSolutionDecoderParameter { get { return PackingSolutionDecoderParameter; } } public IValueLookupParameter PackingPlanEvaluatorParameter { get { return (IValueLookupParameter)Parameters["PackingPlanEvaluator"]; } } ILookupParameter IPackingPlanEvaluationAlgorithm.PackingPlanEvaluatorParameter { get { return PackingPlanEvaluatorParameter; } } public ILookupParameter QualityParameter { get { return (ILookupParameter)Parameters["Quality"]; } } [StorableConstructor] protected PackingPlanEvaluationAlgorithm(bool deserializing) : base(deserializing) { } protected PackingPlanEvaluationAlgorithm(PackingPlanEvaluationAlgorithm original, Cloner cloner) : base(original, cloner) { } public PackingPlanEvaluationAlgorithm () : base() { Parameters.Add(new ValueLookupParameter("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation.")); Parameters.Add(new ValueLookupParameter("PackingPlanEvaluator", "The actual packing plan evaluation operator.")); Parameters.Add(new LookupParameter("Quality", "The quality value aka fitness value of the solution.")); QualityParameter.Hidden = true; } public override IDeepCloneable Clone(Cloner cloner) { return new PackingPlanEvaluationAlgorithm(this, cloner); } public override IOperation Apply() { var decoder = PackingSolutionDecoderParameter.ActualValue; var evaluator = PackingPlanEvaluatorParameter.ActualValue; if (evaluator == null) throw new InvalidOperationException("A PackingPlanEvaluator could not be found."); var operations = new OperationCollection(base.Apply()); operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator)); if (decoder != null) // decode before evaluating operations.Insert(0, ExecutionContext.CreateChildOperation(decoder)); return operations; } } }