use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.
the class PathBidirRefTest method testExtract.
@Test
public void testExtract() {
Graph g = createGraph();
g.edge(1, 2, 10, true);
PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
EdgeIterator iter = explorer.setBaseNode(1);
iter.next();
pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
Path p = pw.extract();
assertEquals(Helper.createTList(1, 2), p.calcNodes());
assertEquals(10, p.getDistance(), 1e-4);
}
use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.
the class GraphHopperStorageCHTest method testShortcutCreationAndAccessForManyVehicles.
@Test
public void testShortcutCreationAndAccessForManyVehicles() {
FlagEncoder tmpCar = new CarFlagEncoder();
FlagEncoder tmpBike = new Bike2WeightFlagEncoder();
EncodingManager em = new EncodingManager(tmpCar, tmpBike);
List<Weighting> chWeightings = new ArrayList<Weighting>();
chWeightings.add(new FastestWeighting(tmpCar));
chWeightings.add(new FastestWeighting(tmpBike));
graph = new GraphHopperStorage(chWeightings, new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()).create(1000);
graph.edge(0, 1).setDistance(10).setFlags(tmpCar.setProperties(100, true, true) | tmpBike.setProperties(10, true, true));
graph.edge(1, 2).setDistance(10).setFlags(tmpCar.setProperties(100, true, true) | tmpBike.setProperties(10, true, true));
graph.freeze();
CHGraph carCHGraph = graph.getGraph(CHGraph.class, chWeightings.get(0));
// enable forward directions for car
EdgeIteratorState carSC02 = carCHGraph.shortcut(0, 2).setWeight(10).setFlags(PrepareEncoder.getScFwdDir()).setDistance(20);
CHGraph bikeCHGraph = graph.getGraph(CHGraph.class, chWeightings.get(1));
// enable both directions for bike
EdgeIteratorState bikeSC02 = bikeCHGraph.shortcut(0, 2).setWeight(10).setFlags(PrepareEncoder.getScDirMask()).setDistance(20);
// assert car CH graph
assertTrue(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isForward(tmpCar));
assertFalse(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isBackward(tmpCar));
// throw exception for wrong encoder
try {
assertFalse(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isForward(tmpBike));
assertTrue(false);
} catch (AssertionError ex) {
}
// assert bike CH graph
assertTrue(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isForward(tmpBike));
assertTrue(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isBackward(tmpBike));
// throw exception for wrong encoder
try {
assertFalse(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isBackward(tmpCar));
assertTrue(false);
} catch (AssertionError ex) {
}
}
use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.
the class GraphHopperStorageCHTest method testGetWeightIfAdvancedEncoder.
@Test
public void testGetWeightIfAdvancedEncoder() {
FlagEncoder customEncoder = new Bike2WeightFlagEncoder();
EncodingManager em = new EncodingManager(customEncoder);
FastestWeighting weighting = new FastestWeighting(customEncoder);
GraphHopperStorage ghStorage = new GraphBuilder(em).setCHGraph(weighting).create();
ghStorage.edge(0, 2);
ghStorage.freeze();
CHGraphImpl lg = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting);
CHEdgeIteratorState sc1 = lg.shortcut(0, 1);
long flags = customEncoder.setProperties(10, false, true);
sc1.setFlags(flags);
sc1.setWeight(100.123);
assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getAdjNode()).getWeight(), 1e-3);
assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getBaseNode()).getWeight(), 1e-3);
assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getBaseNode(), sc1.getAdjNode())).getWeight(), 1e-3);
assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getAdjNode(), sc1.getBaseNode())).getWeight(), 1e-3);
sc1 = lg.shortcut(1, 0);
assertTrue(sc1.isShortcut());
sc1.setFlags(PrepareEncoder.getScDirMask());
sc1.setWeight(1.011011);
assertEquals(1.011011, sc1.getWeight(), 1e-3);
}
use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.
the class CHEdgeIteratorTest method testUpdateFlags.
@Test
public void testUpdateFlags() {
CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
ghStorage.freeze();
assertEquals(2, GHUtility.count(g.getAllEdges()));
assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
assertEquals(1, iter.getAdjNode());
assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
// update setProperties
iter.setFlags(carFlagEncoder.setProperties(20, true, false));
assertEquals(12, iter.getDistance(), 1e-4);
// update distance
iter.setDistance(10);
assertEquals(10, iter.getDistance(), 1e-4);
assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
iter = GHUtility.getEdge(g, 0, 1);
assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
assertEquals(10, iter.getDistance(), 1e-4);
assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.
the class GHUtilityTest method testCopyWithSelfRef.
@Test
public void testCopyWithSelfRef() {
Graph g = initUnsorted(createGraph());
g.edge(0, 0, 11, true);
CHGraph lg = new GraphBuilder(encodingManager).chGraphCreate(new FastestWeighting(carEncoder));
GHUtility.copyTo(g, lg);
assertEquals(g.getAllEdges().getMaxId(), lg.getAllEdges().getMaxId());
}
Aggregations