Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/DistanceMeasures/EuclideanDistanceMeasure.cs @ 12897

Last change on this file since 12897 was 8670, checked in by svonolfe, 12 years ago

Added first version of the dynamic vehicle routing addon (#1955)

File size: 2.0 KB
RevLine 
[8670]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6using HeuristicLab.Common;
7using HeuristicLab.PDPSimulation.DomainModel;
8
9namespace 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}
Note: See TracBrowser for help on using the repository browser.