[8670] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 6 | using HeuristicLab.Common;
|
---|
| 7 | using HeuristicLab.PDPSimulation.DomainModel;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.PDPSimulation.DistanceMeasures {
|
---|
| 10 | [StorableClass]
|
---|
| 11 | public class EuclideanDistanceMeasure: DistanceMeasure {
|
---|
| 12 | public EuclideanDistanceMeasure()
|
---|
| 13 | : base() {
|
---|
| 14 | }
|
---|
| 15 | [StorableConstructor]
|
---|
| 16 | private EuclideanDistanceMeasure(bool deserializing) : base(deserializing) {
|
---|
| 17 | }
|
---|
| 18 | private EuclideanDistanceMeasure(EuclideanDistanceMeasure original, Cloner cloner)
|
---|
| 19 | : base(original, cloner) {
|
---|
| 20 |
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 24 | return new EuclideanDistanceMeasure(this, cloner);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public override bool DiversionSupported {
|
---|
| 28 | get { return true; }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public override double GetDistance(double sourceX, double sourceY,
|
---|
| 32 | double currentX, double currentY,
|
---|
| 33 | double destX, double destY) {
|
---|
| 34 | return GetDistance(currentX, currentY, destX, destY);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public override double GetDistance(double sourceX, double sourceY,
|
---|
| 38 | double destX, double destY) {
|
---|
| 39 | double vx = destX - sourceX;
|
---|
| 40 | double vy = destY - sourceY;
|
---|
| 41 | double length = Math.Sqrt(vx * vx + vy * vy);
|
---|
| 42 |
|
---|
| 43 | return length;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public override void Move(double sourceX, double sourceY,
|
---|
| 47 | double currentX, double currentY,
|
---|
| 48 | double destX, double destY, double time, Vehicle.MoveInformation moveInfo,
|
---|
| 49 | out double newPosX, out double newPosY, out double length) {
|
---|
| 50 | length = GetDistance(sourceX, sourceY, currentX, currentY, destX, destY);
|
---|
| 51 |
|
---|
| 52 | if (length < time) {
|
---|
| 53 | newPosX = destX;
|
---|
| 54 | newPosY = destY;
|
---|
| 55 | } else {
|
---|
| 56 | double vx = destX - currentX;
|
---|
| 57 | double vy = destY - currentY;
|
---|
| 58 |
|
---|
| 59 | vx = vx / length * time;
|
---|
| 60 | vy = vy / length * time;
|
---|
| 61 |
|
---|
| 62 | newPosX = currentX + vx;
|
---|
| 63 | newPosY = currentY + vy;
|
---|
| 64 | length = time;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|