use of com.graphhopper.routing.querygraph.VirtualEdgeIteratorState in project graphhopper by graphhopper.
the class MapMatching method createTimeSteps.
/**
* Creates TimeSteps with candidates for the GPX entries but does not create emission or
* transition probabilities. Creates directed candidates for virtual nodes and undirected
* candidates for real nodes.
*/
private List<ObservationWithCandidateStates> createTimeSteps(List<Observation> filteredObservations, List<Collection<Snap>> splitsPerObservation) {
if (splitsPerObservation.size() != filteredObservations.size()) {
throw new IllegalArgumentException("filteredGPXEntries and queriesPerEntry must have same size.");
}
final List<ObservationWithCandidateStates> timeSteps = new ArrayList<>();
for (int i = 0; i < filteredObservations.size(); i++) {
Observation observation = filteredObservations.get(i);
Collection<Snap> splits = splitsPerObservation.get(i);
List<State> candidates = new ArrayList<>();
for (Snap split : splits) {
if (queryGraph.isVirtualNode(split.getClosestNode())) {
List<VirtualEdgeIteratorState> virtualEdges = new ArrayList<>();
EdgeIterator iter = queryGraph.createEdgeExplorer().setBaseNode(split.getClosestNode());
while (iter.next()) {
if (!queryGraph.isVirtualEdge(iter.getEdge())) {
throw new RuntimeException("Virtual nodes must only have virtual edges " + "to adjacent nodes.");
}
virtualEdges.add((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), iter.getAdjNode()));
}
if (virtualEdges.size() != 2) {
throw new RuntimeException("Each virtual node must have exactly 2 " + "virtual edges (reverse virtual edges are not returned by the " + "EdgeIterator");
}
// Create a directed candidate for each of the two possible directions through
// the virtual node. We need to add candidates for both directions because
// we don't know yet which is the correct one. This will be figured
// out by the Viterbi algorithm.
candidates.add(new State(observation, split, virtualEdges.get(0), virtualEdges.get(1)));
candidates.add(new State(observation, split, virtualEdges.get(1), virtualEdges.get(0)));
} else {
// Create an undirected candidate for the real node.
candidates.add(new State(observation, split));
}
}
timeSteps.add(new ObservationWithCandidateStates(observation, candidates));
}
return timeSteps;
}
use of com.graphhopper.routing.querygraph.VirtualEdgeIteratorState in project graphhopper by graphhopper.
the class FastestWeightingTest method testWeightWrongHeading.
@Test
public void testWeightWrongHeading() {
Weighting instance = new FastestWeighting(encoder, new PMap().putObject(Parameters.Routing.HEADING_PENALTY, 100));
VirtualEdgeIteratorState virtEdge = new VirtualEdgeIteratorState(0, GHUtility.createEdgeKey(1, false), 1, 2, 10, GHUtility.setSpeed(10, 0, encoder, encodingManager.createEdgeFlags()), "test", Helper.createPointList(51, 0, 51, 1), false);
double time = instance.calcEdgeWeight(virtEdge, false);
virtEdge.setUnfavored(true);
// heading penalty on edge
assertEquals(time + 100, instance.calcEdgeWeight(virtEdge, false), 1e-8);
// only after setting it
virtEdge.setUnfavored(true);
assertEquals(time + 100, instance.calcEdgeWeight(virtEdge, true), 1e-8);
// but not after releasing it
virtEdge.setUnfavored(false);
assertEquals(time, instance.calcEdgeWeight(virtEdge, true), 1e-8);
// test default penalty
virtEdge.setUnfavored(true);
instance = new FastestWeighting(encoder);
assertEquals(time + Routing.DEFAULT_HEADING_PENALTY, instance.calcEdgeWeight(virtEdge, false), 1e-8);
}
use of com.graphhopper.routing.querygraph.VirtualEdgeIteratorState in project graphhopper by graphhopper.
the class ExtendedJsonResponseTest method getEdgeIterator.
private EdgeIteratorState getEdgeIterator() {
PointList pointList = new PointList();
pointList.add(-3.4445, -38.9990);
pointList.add(-3.5550, -38.7990);
return new VirtualEdgeIteratorState(0, 0, 0, 1, 10, new IntsRef(1), "test of iterator", pointList, false);
}
Aggregations