Skip to content

Commit

Permalink
Dealing with null routes when Valhalla query returns with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego committed Aug 4, 2023
1 parent 3f4a9d8 commit a11c0b5
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public List<IObjectArtifact> instantiate(IObservable semantics, IContextualizati

Set<IObservation> connected = new HashSet<>();

int nullTrajectories = 0;

for (IObservation source : allSources) {


Expand Down Expand Up @@ -249,6 +251,7 @@ public List<IObjectArtifact> instantiate(IObservable semantics, IContextualizati
route = valhalla.optimized_route(valhallaInput);
trajectory = route.getPath().transform(scope.getScale().getSpace().getProjection());
stats = route.getSummaryStatistics();

} catch (ValhallaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -261,26 +264,43 @@ public List<IObjectArtifact> instantiate(IObservable semantics, IContextualizati
if (
(timeThreshold == null || (stats.get("time") < timeThreshold)) &&
(distanceThreshold == null || (stats.get("length") < distanceThreshold))

)
{
connect((IDirectObservation) source, (IDirectObservation) target, trajectory);
connected.add((IObservation) target);
trajectories.put(new Pair<IDirectObservation,IDirectObservation>((IDirectObservation)source,(IDirectObservation)target),trajectory);
}

if (trajectory != null) {
connect((IDirectObservation) source, (IDirectObservation) target, trajectory);
connected.add((IObservation) target);
trajectories.put(new Pair<IDirectObservation,IDirectObservation>((IDirectObservation)source,(IDirectObservation)target),trajectory);
}
else {

nullTrajectories += 1;

}
}

}
}


context.getMonitor()
.info("creating " + graph.edgeSet().size() + " " + Concepts.INSTANCE.getDisplayName(semantics.getType())
+ " routing relationships.");


if (nullTrajectories > 0) {

context.getMonitor()
.info("creating " + graph.edgeSet().size() + " " + Concepts.INSTANCE.getDisplayName(semantics.getType())
+ " routing relationships. \n" + nullTrajectories + " relationships could not be created because a route "
+ "was not found either due to a lack of data or because travel characteristics exceed the allowed limits.");

} else {
context.getMonitor()
.info("creating " + graph.edgeSet().size() + " " + Concepts.INSTANCE.getDisplayName(semantics.getType())
+ " routing relationships.");
}

return instantiateRelationships(semantics);
}

private List<IObjectArtifact> instantiateRelationships(IObservable observable) {
// Diego: Not sure about the IScale part...

int i = 1;
List<IObjectArtifact> ret = new ArrayList<>();
// build from graph
Expand Down

0 comments on commit a11c0b5

Please sign in to comment.