#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 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.Optimization;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Problems.VehicleRouting.Interfaces;
namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
[Item("VRPMoveEvaluator", "Evaluates a VRP move.")]
[StorableClass]
public abstract class VRPMoveEvaluator : VRPMoveOperator, ISingleObjectiveMoveEvaluator {
public const string MovePrefix = "Move";
public ILookupParameter QualityParameter {
get { return (ILookupParameter)Parameters["Quality"]; }
}
public ILookupParameter MoveQualityParameter {
get { return (ILookupParameter)Parameters["MoveQuality"]; }
}
public ILookupParameter MovePenaltyParameter {
get { return (ILookupParameter)Parameters["MovePenalty"]; }
}
[StorableConstructor]
protected VRPMoveEvaluator(bool deserializing) : base(deserializing) { }
public VRPMoveEvaluator()
: base() {
Parameters.Add(new LookupParameter("Quality", "The quality of the solution."));
Parameters.Add(new LookupParameter("MoveQuality", "The relative quality of the move."));
Parameters.Add(new LookupParameter("MovePenalty", "The penalty applied to the move."));
}
protected VRPMoveEvaluator(VRPMoveEvaluator original, Cloner cloner)
: base(original, cloner) {
}
//helper method to evaluate an updated individual
protected void UpdateEvaluation(IVRPEncoding updatedTours) {
IVRPEvaluator evaluator = ProblemInstance.MoveEvaluator;
try {
this.ExecutionContext.Scope.Variables.Add(new Variable(evaluator.VRPToursParameter.ActualName,
updatedTours));
IAtomicOperation op = this.ExecutionContext.CreateChildOperation(evaluator);
op.Operator.Execute((IExecutionContext)op, CancellationToken);
}
finally {
this.ExecutionContext.Scope.Variables.Remove(evaluator.VRPToursParameter.ActualName);
}
}
protected abstract void EvaluateMove();
public override IOperation Apply() {
EvaluateMove();
return base.Apply();
}
}
}