use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class OSMTurnRelationTest method testGetRestrictionAsEntries.
@Test
public void testGetRestrictionAsEntries() {
CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
osmNodeToInternal.put(3L, 3);
// edge ids are only stored if they occured before in an OSMRelation
internalToOSMEdge.put(3, 3L);
internalToOSMEdge.put(4, 4L);
GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
OSMReader osmReader = new OSMReader(ghStorage) {
@Override
public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
return osmNodeToInternal.get(nodeOsmId);
}
@Override
public long getOsmIdOfInternalEdge(int edgeId) {
Long l = internalToOSMEdge.get(edgeId);
if (l == null)
return -1;
return l;
}
};
EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
// TYPE == ONLY
OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(2, result.size());
Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
OSMTurnRelation.TurnCostTableEntry entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(6, entry.edgeTo);
assertEquals(3, entry.nodeVia);
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(2, entry.edgeTo);
assertEquals(3, entry.nodeVia);
// TYPE == NOT
instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(1, result.size());
iter = result.iterator();
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(3, entry.edgeTo);
assertEquals(3, entry.nodeVia);
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class PrepareContractionHierarchiesTest method testMultiplePreparationsIdenticalView.
@Test
public void testMultiplePreparationsIdenticalView() {
CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
// FastestWeighting would lead to different shortcuts due to different default speeds for bike and car
Weighting carWeighting = new ShortestWeighting(tmpCarEncoder);
Weighting bikeWeighting = new ShortestWeighting(tmpBikeEncoder);
List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
initShortcutsGraph(ghStorage);
ghStorage.freeze();
for (Weighting w : chWeightings) {
checkPath(ghStorage, w, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
}
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class AbstractEdgeElevationInterpolatorTest method setUp.
@SuppressWarnings("resource")
@Before
public void setUp() {
dataFlagEncoder = new DataFlagEncoder();
graph = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(Arrays.asList(dataFlagEncoder, new FootFlagEncoder()), 8), true, new GraphExtension.NoOpExtension()).create(100);
edgeElevationInterpolator = createEdgeElevationInterpolator();
interpolatableWay = createInterpolatableWay();
normalWay = new ReaderWay(0);
normalWay.setTag("highway", "primary");
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class GraphHopperAPITest method testConcurrentGraphChange.
@Test
public void testConcurrentGraphChange() throws InterruptedException {
final GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
initGraph(graph);
graph.edge(1, 2, 10, true);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger checkPointCounter = new AtomicInteger(0);
final GraphHopper graphHopper = new GraphHopper() {
@Override
protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) {
return new ChangeGraphHelper(graph, locationIndex) {
@Override
public long applyChanges(EncodingManager em, Collection<JsonFeature> features) {
// force sleep inside the lock and let the main thread run until the lock barrier
latch.countDown();
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
checkPointCounter.incrementAndGet();
return super.applyChanges(em, features);
}
};
}
}.setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
GHResponse rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.toString(), rsp.hasErrors());
assertEquals(1800, rsp.getBest().getTime());
final List<JsonFeature> list = new ArrayList<>();
Map<String, Object> properties = new HashMap<>();
properties.put("speed", 5);
list.add(new JsonFeature("1", "bbox", new BBox(10.399, 10.4, 42.0, 42.001), null, properties));
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(new Runnable() {
@Override
public void run() {
graphHopper.changeGraph(list);
checkPointCounter.incrementAndGet();
}
});
latch.await();
assertEquals(0, checkPointCounter.get());
rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.toString(), rsp.hasErrors());
assertEquals(8400, rsp.getBest().getTime());
executorService.shutdown();
executorService.awaitTermination(3, TimeUnit.SECONDS);
assertEquals(2, checkPointCounter.get());
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class ChangeGraphHelperTest method setUp.
@Before
public void setUp() {
encodingManager = new EncodingManager("car");
graph = new GraphBuilder(encodingManager).create();
ghson = new GHJsonBuilder().create();
}
Aggregations