#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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.IntegerVectorEncoding; using HeuristicLab.Encodings.PackingEncoding.GroupingVector; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.BinPacking.Decoders; using HeuristicLab.Problems.BinPacking.Dimensions; using HeuristicLab.Problems.BinPacking.Evaluators; using HeuristicLab.Problems.BinPacking.Interfaces; using HeuristicLab.Problems.BinPacking.PackingBin; using HeuristicLab.Problems.BinPacking.PackingItem; namespace HeuristicLab.Problems.BinPacking { [Item("Grouping Vector MoveEvaluator", "Base class for evaluating packing moves.")] [StorableClass] public class GroupingVectorMoveEvaluator : PackingMoveEvaluator, ISingleObjectiveMoveEvaluator, IGroupingVectorMoveOperator{ public ILookupParameter SingleGroupingMoveParameter { get { return (ILookupParameter)Parameters["SingleGroupingMove"]; } } public ILookupParameter GroupingVectorParameter { get { return (ILookupParameter)Parameters["GroupingVector"]; } } [StorableConstructor] protected GroupingVectorMoveEvaluator(bool deserializing) : base(deserializing) { } protected GroupingVectorMoveEvaluator(GroupingVectorMoveEvaluator original, Cloner cloner) : base(original, cloner) { } public GroupingVectorMoveEvaluator() : base() { Parameters.Add(new LookupParameter("SingleGroupingMove", "The move to evaluate.")); Parameters.Add(new LookupParameter("GroupingVector", "The solution to evaluate.")); } public override IDeepCloneable Clone(Cloner cloner) { return new GroupingVectorMoveEvaluator(this, cloner); } public override IOperation Apply() { GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue; SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue; GroupingVectorEncoding newSolution = new GroupingVectorEncoding(); newSolution.GroupingVector = new IntegerVector (groupingVector.GroupingVector); newSolution.GroupingVector[move.Index] = move.NewGroup; var packingPlan = ExtremePointGroupingVectorDecoder3D.Decode(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator.CalculatePackingRatio( packingPlan, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); double moveQuality = quality.Value; if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality); else MoveQualityParameter.ActualValue.Value = moveQuality; return base.Apply(); } } }