1

I tried to compute the distance to a delivery location using a RoadModel based on a .dot file. However, the calculated distance using Point.distance(currPos, destPos) gives a result that does not seem to fit. I compared this with the distance from MoveProgress (RoadModel.moveTo(...)) and saw that the point distance is about a factor 100 more.

For example, when using the Taxi example from rinsim-example-4.1.1.jar with the following implementation of the Taxi class

class Taxi extends Vehicle implements SimulatorUser {

private RandomGenerator rng;

Taxi(Point startPosition, int capacity) {
    super(VehicleDTO.builder().capacity(capacity).startPosition(startPosition)
                    .speed(1000).build());
}

@Override
public void setSimulator(SimulatorAPI api) {
    rng = api.getRandomGenerator();
}

@Override
protected void tickImpl(TimeLapse time) {
    final RoadModel rm = getRoadModel();

    Point start = rm.getPosition(this);
    MoveProgress mp;

    if (rm.getDestination(this) == null) {
        mp = rm.moveTo(this, rm.getRandomPosition(rng), time);
    }

    if (rm.getPosition(this).equals(rm.getDestination(this)))
        mp = rm.moveTo(this, rm.getRandomPosition(rng), time);
    else
        mp = rm.moveTo(this, rm.getDestination(this), time);

    Point after = rm.getPosition(this);

    System.out.println("Travelled distance");
    System.out.println(mp.distance());
    System.out.println("Straight line distance");
    System.out.println(Point.distance(start, after));
}

then the travelled distance is around 0.277 whereas the calculated straight line distance is about 27.7. Is there a reason for the factor 100 difference or another way to get the distance between two points in the same measure as MoveProgress?

1 Answers1

0

The reason for the difference in distance as obtained by Point.distance(..,..) and MoveProgress is that the latter takes any available ConnectionData into account while the former computes the bird flight distance between two points (ignoring any connection related information).

It turns out that the graph that is used in the TaxiExample has many connections for which the connection length is overridden. It looks as if this length is off by a factor 100 as you mentioned, but it has to be investigated more thoroughly to see what would be the correct value.

For now, a workaround is to simply ignore all ConnectionData. Use the following code for parsing the graph:

final Graph<LengthData> originalGraph = 
  DotGraphIO.getLengthGraphIO().read(Paths.get("path/to/graph.dot"));

final Graph<LengthData> newGraph = new TableGraph<>();
for (final Connection<LengthData> conn : originalGraph.getConnections()) {
  newGraph.addConnection(conn.from(), conn.to());
}

This will construct a new graph without any connection data associated to any of the connections.

rinde
  • 1,181
  • 1
  • 8
  • 20