using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.PDPSimulation.DomainModel; namespace HeuristicLab.PDPSimulation.DistanceMeasures { [StorableClass] public class EuclideanDistanceMeasure: DistanceMeasure { public EuclideanDistanceMeasure() : base() { } [StorableConstructor] private EuclideanDistanceMeasure(bool deserializing) : base(deserializing) { } private EuclideanDistanceMeasure(EuclideanDistanceMeasure original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new EuclideanDistanceMeasure(this, cloner); } public override bool DiversionSupported { get { return true; } } public override double GetDistance(double sourceX, double sourceY, double currentX, double currentY, double destX, double destY) { return GetDistance(currentX, currentY, destX, destY); } public override double GetDistance(double sourceX, double sourceY, double destX, double destY) { double vx = destX - sourceX; double vy = destY - sourceY; double length = Math.Sqrt(vx * vx + vy * vy); return length; } public override void Move(double sourceX, double sourceY, double currentX, double currentY, double destX, double destY, double time, Vehicle.MoveInformation moveInfo, out double newPosX, out double newPosY, out double length) { length = GetDistance(sourceX, sourceY, currentX, currentY, destX, destY); if (length < time) { newPosX = destX; newPosY = destY; } else { double vx = destX - currentX; double vy = destY - currentY; vx = vx / length * time; vy = vy / length * time; newPosX = currentX + vx; newPosY = currentY + vy; length = time; } } } }