1

I'm trying to get get the expected time it would take to move to a specific point. Here is the code I am using:

long getTimeToReachGivenPoint(Point point) {

    System.out.println("Point: " + point);

    List<Point> path = getRoadModel().getShortestPathTo(this, point);

    System.out.println("Path: " + path);
    System.out.println("Path length: " + path.size());

    Measure<Double,Length> distance = getRoadModel().getDistanceOfPath(path);   

    long time = (long) (distance.getValue()/AgvAgent.SPEED);
    return time;
}

When I run this i get the following output:

point: (8.0,36.0)
Path: [(12.0,28.22222222222222), (12.0,32.0), (12.0,36.0), (8.0,36.0)]
Path length: 4

And the following exception:

Exception in thread "Thread-0" java.lang.IllegalArgumentException: Can not get connection length from a non-existing connection.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:135)
at com.github.rinde.rinsim.geom.AbstractGraph.connectionLength(AbstractGraph.java:48)
at com.github.rinde.rinsim.core.model.road.GraphRoadModelSnapshot.getDistanceOfPath(GraphRoadModelSnapshot.java:83)
at com.github.rinde.rinsim.core.model.road.DynamicGraphRoadModelImpl.getDistanceOfPath(DynamicGraphRoadModelImpl.java:226)
at project.agents.AgvAgent.getTimeToReachGivenPoint(AgvAgent.java:162)
at project.agents.AgvScheduler.calculateExpectedPickUpTime(AgvScheduler.java:116)
at project.agents.AgvScheduler.getReservationProposal(AgvScheduler.java:43)
at project.agents.AgvAgent.getReservationProposal(AgvAgent.java:147)
at project.smartMessage.ExplorationAntComputationalBehaviour.compute(ExplorationAntComputationalBehaviour.java:41)
at project.smartMessage.ExplorationAntComputationalBehaviour.run(ExplorationAntComputationalBehaviour.java:75)
at project.smartMessage.AntAgent.run(AntAgent.java:64)
at project.agents.AgvAgent.tickImpl(AgvAgent.java:205)
at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:401)

From what I understand it seems there are no connections between the points on the path that is returned by the getShortestPath() method?

rinde
  • 1,181
  • 1
  • 8
  • 20
Damcios
  • 333
  • 2
  • 6
  • For now I fixed if with Measure maxSpeed = Measure.valueOf(getSpeed(), getRoadModel().getSpeedUnit()); List path = new LinkedList<>(getRoadModel().getPathTo(this, point, this.timeUnit, maxSpeed, GeomHeuristics.euclidean()).getPath()); But i'm unsure if I'm doing something wrong above or if it is a bug. – Damcios May 30 '18 at 09:12

1 Answers1

0

The getDistanceOfPath(Iterable<Point>) method requires all points in the path to be a node in the graph. The path returned by getShortestPathTo(RoadUser, Point) may contain a position that is not a node in the graph in case the RoadUser is not on a node. There is currently no built-in way to detect this and work around it.

You can detect this situation by using the GraphRoadModel.getConnection(RoadUser) method and if the RoadUser is on a connection then you can use the Connection.to() as the starting point for the getShortestPathTo(RoadUser, Point) call. For example:

Optional<? extends Connection<?>> conn = ((GraphRoadModel)getRoadModel()).getConnection(this);
Point from;
double dist = 0;
if( conn.isPresent() ){
  dist += Point.distance(getRoadModel().getPosition(this),conn.to());
  from = conn.to();
} else {
  from = getRoadModel().getPosition(this);
}

List<Point> path = getRoadModel().getShortestPathTo(from, point);
Measure<Double,Length> distance = getRoadModel().getDistanceOfPath(path); 

// total distance is the sum of distance and dist  
rinde
  • 1,181
  • 1
  • 8
  • 20
  • The RoadModel I use is CollisionGraphRoadModelImpl. Somehow this makes the getConnection() method invisible, not sure why? But I tried casting the RoadModel to GraphRoadModel but when i do `Optional> conn = model.getConnection(this);` I get the error: `Type mismatch: cannot convert from Optional> to Optional>` – Damcios May 30 '18 at 11:08
  • It is working if I cast the road model and use `Optional extends Connection>>` as the type of conn. – Damcios May 30 '18 at 11:23