#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.PackingEncoding.PackingPlan;
using HeuristicLab.Operators;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.BinPacking.Decoders;
using HeuristicLab.Problems.BinPacking.Evaluators;
using HeuristicLab.Problems.BinPacking.Interfaces;
using HeuristicLab.Problems.BinPacking.Shapes;
namespace HeuristicLab.Problems.BinPacking {
[Item("PackingMoveEvaluator", "A base class for operators which evaluate Packing-Solution moves.")]
[StorableClass]
public abstract class PackingMoveEvaluator : SingleSuccessorOperator, IPackingMoveEvaluator, IMoveOperator
where D : class, IPackingDimensions
where B : PackingShape, IPackingBin, IRegularPackingShape
where I : PackingShape, IPackingItem, IRegularPackingShape {
public override bool CanChangeName {
get { return false; }
}
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ILookupParameter> PackingItemMeasuresParameter {
get { return (LookupParameter>)Parameters["PackingItemMeasures"]; }
}
public ILookupParameter PackingBinMeasuresParameter {
get { return (LookupParameter)Parameters["PackingBinMeasures"]; }
}
public IValueLookupParameter PackingSolutionDecoderParameter {
get { return (IValueLookupParameter)Parameters["PackingSolutionDecoder"]; }
}
public IValueLookupParameter PackingPlanEvaluatorParameter {
get { return (IValueLookupParameter)Parameters["PackingPlanEvaluator"]; }
}
protected ScopeParameter CurrentScopeParameter {
get { return (ScopeParameter)Parameters["CurrentScope"]; }
}
public ILookupParameter PackingMoveParameter {
get { return (ILookupParameter)Parameters["PackingMove"]; }
}
[StorableConstructor]
protected PackingMoveEvaluator(bool deserializing) : base(deserializing) { }
protected PackingMoveEvaluator(PackingMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
protected PackingMoveEvaluator()
: base() {
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>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance."));
Parameters.Add(new LookupParameter("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance."));
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 ScopeParameter("CurrentScope", "The current scope where the decoded solution should be added to."));
Parameters.Add(new LookupParameter("PackingMove", "The move to evaluate."));
}
public override IOperation Apply() {
IPackingMove move = PackingMoveParameter.ActualValue;
IPackingSolutionEncoding newSolution = move.GetSolutionAfterMove();
CurrentScopeParameter.ActualValue.Variables.Add(new Variable("MovedSolution", newSolution));
PackingPlan packingPlan = (PackingSolutionDecoderParameter.ActualValue as PackingSolutionDecoder).
CreatePackingPlanFromEncoding(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan));
DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator.CalculatePackingRatio(packingPlan);
double moveQuality = quality.Value;
if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
else MoveQualityParameter.ActualValue.Value = moveQuality;
return base.Apply();
}
}
}