use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class RoutingCHGraphImplTest method testShortcutConnection.
@Test
void testShortcutConnection() {
// 4 ------ 1 > 0
// ^ \
// 3 2
FlagEncoder encoder = FlagEncoders.createCar();
EncodingManager em = EncodingManager.create(encoder);
BaseGraph graph = new BaseGraph.Builder(em).create();
EdgeExplorer baseCarOutExplorer = graph.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc()));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 1).setDistance(30));
graph.freeze();
CHConfig chConfig = CHConfig.nodeBased("ch", new FastestWeighting(encoder));
CHStorage store = CHStorage.fromGraph(graph, chConfig);
CHStorageBuilder chBuilder = new CHStorageBuilder(store);
chBuilder.setIdentityLevels();
chBuilder.addShortcutNodeBased(0, 1, PrepareEncoder.getScBwdDir(), 10, 12, 13);
chBuilder.addShortcutNodeBased(1, 2, PrepareEncoder.getScDirMask(), 10, 10, 11);
chBuilder.addShortcutNodeBased(1, 3, PrepareEncoder.getScBwdDir(), 10, 14, 15);
RoutingCHGraph lg = RoutingCHGraphImpl.fromGraph(graph, store, chConfig);
RoutingCHEdgeExplorer chOutExplorer = lg.createOutEdgeExplorer();
RoutingCHEdgeExplorer chInExplorer = lg.createInEdgeExplorer();
// shortcuts are only visible from the lower level node, for example we do not see node 1 from node 2, or node
// 0 from node 1
assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(2)));
assertEquals(0, GHUtility.count(chInExplorer.setBaseNode(2)));
assertEquals(2, GHUtility.count(chOutExplorer.setBaseNode(1)));
assertEquals(3, GHUtility.count(chInExplorer.setBaseNode(1)));
assertEquals(GHUtility.asSet(2, 4), GHUtility.getNeighbors(chOutExplorer.setBaseNode(1)));
assertEquals(GHUtility.asSet(4), GHUtility.getNeighbors(baseCarOutExplorer.setBaseNode(1)));
assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(3)));
assertEquals(0, GHUtility.count(chInExplorer.setBaseNode(3)));
assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(0)));
assertEquals(1, GHUtility.count(chInExplorer.setBaseNode(0)));
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class DecimalEncodedValueTest method testMaxValue.
@Test
public void testMaxValue() {
FlagEncoder carEncoder = FlagEncoders.createCar(new PMap("speed_bits=10|speed_factor=0.5"));
EncodingManager em = EncodingManager.create(carEncoder);
DecimalEncodedValue carAverageSpeedEnc = em.getDecimalEncodedValue(EncodingManager.getKey(carEncoder, "average_speed"));
CarTagParser carTagParser = new CarTagParser(em, new PMap());
carTagParser.init(new DateRangeParser());
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "70 mph");
IntsRef flags = carTagParser.handleWayTags(em.createEdgeFlags(), way);
assertEquals(101.5, carAverageSpeedEnc.getDecimal(true, flags), 1e-1);
DecimalEncodedValue instance1 = new DecimalEncodedValueImpl("test1", 8, 0.5, false);
instance1.init(new EncodedValue.InitializerConfig());
flags = em.createEdgeFlags();
instance1.setDecimal(false, flags, 100d);
assertEquals(100, instance1.getDecimal(false, flags), 1e-1);
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GtfsReader method connectStopsToStreetNetwork.
void connectStopsToStreetNetwork() {
EncodingManager em = graph.getEncodingManager();
FlagEncoder footEncoder = em.getEncoder("foot");
final EdgeFilter filter = new DefaultSnapFilter(new FastestWeighting(footEncoder), em.getBooleanEncodedValue(Subnetwork.key("foot")));
for (Stop stop : feed.stops.values()) {
if (stop.location_type == 0) {
// Only stops. Not interested in parent stations for now.
Snap locationSnap = walkNetworkIndex.findClosest(stop.stop_lat, stop.stop_lon, filter);
Integer stopNode;
if (locationSnap.isValid()) {
stopNode = gtfsStorage.getStreetToPt().get(locationSnap.getClosestNode());
if (stopNode == null) {
stopNode = out.createNode();
indexBuilder.addToAllTilesOnLine(stopNode, stop.stop_lat, stop.stop_lon, stop.stop_lat, stop.stop_lon);
gtfsStorage.getPtToStreet().put(stopNode, locationSnap.getClosestNode());
gtfsStorage.getStreetToPt().put(locationSnap.getClosestNode(), stopNode);
}
} else {
stopNode = out.createNode();
indexBuilder.addToAllTilesOnLine(stopNode, stop.stop_lat, stop.stop_lon, stop.stop_lat, stop.stop_lon);
}
gtfsStorage.getStationNodes().put(new GtfsStorage.FeedIdWithStopId(id, stop.stop_id), stopNode);
}
}
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class HeadingRoutingTest method createSquareGraphWithTunnel.
private GraphHopperStorage createSquareGraphWithTunnel() {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).add(Subnetwork.create("profile")).build();
GraphHopperStorage g = new GraphBuilder(encodingManager).create();
// 2----3---4
// | | |
// 1->- 8 >-5 (edge 1->5 is not connected to 8)
// | | |
// 0----7---6
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0.000, 0.000);
na.setNode(1, 0.001, 0.000);
na.setNode(2, 0.002, 0.000);
na.setNode(3, 0.002, 0.001);
na.setNode(4, 0.002, 0.002);
na.setNode(5, 0.001, 0.002);
na.setNode(6, 0.000, 0.002);
na.setNode(7, 0.000, 0.001);
na.setNode(8, 0.001, 0.001);
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 6).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 0).setDistance(100));
GHUtility.setSpeed(60, true, false, carEncoder, g.edge(1, 5).setDistance(110));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 8).setDistance(110));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(110));
return g;
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class ShapeFileReaderTest method initHopper.
private static GraphHopper initHopper(GraphHopper gh, String inputFile, String outDir) {
URL resourceURL = ShapeFileReaderTest.class.getResource(inputFile);
try {
inputFile = new File(resourceURL.toURI()).getAbsolutePath();
} catch (Exception e) {
throw new RuntimeException(e);
}
// turn off geometry simplification so geometry should be the same
// between pbf and shapefile readers
gh.setWayPointMaxDistance(0);
return gh.setStoreOnFlush(false).setDataReaderFile(inputFile).setGraphHopperLocation(new File(outDir).getAbsolutePath()).setEncodingManager(new EncodingManager(new CarFlagEncoder())).setCHEnabled(false).importOrLoad();
}
Aggregations