use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class MiniGraphUI method createAlgo.
private RoutingAlgorithm createAlgo(GraphHopper hopper) {
Profile profile = hopper.getProfiles().iterator().next();
if (useCH) {
RoutingCHGraph chGraph = hopper.getCHGraphs().get(profile.getName());
logger.info("CH algo, profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(hopper.getGraphHopperStorage(), fromRes, toRes);
QueryRoutingCHGraph queryRoutingCHGraph = new QueryRoutingCHGraph(chGraph, qGraph);
return new CHDebugAlgo(queryRoutingCHGraph, mg);
} else {
LandmarkStorage landmarks = hopper.getLandmarks().get(profile.getName());
RoutingAlgorithmFactory algoFactory = (g, w, opts) -> {
RoutingAlgorithm algo = new LMRoutingAlgorithmFactory(landmarks).createAlgo(g, w, opts);
if (algo instanceof AStarBidirection) {
return new DebugAStarBi(g, w, opts.getTraversalMode(), mg).setApproximation(((AStarBidirection) algo).getApproximation());
} else if (algo instanceof AStar) {
return new DebugAStar(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof DijkstraBidirectionRef) {
return new DebugDijkstraBidirection(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof Dijkstra) {
return new DebugDijkstraSimple(g, w, opts.getTraversalMode(), mg);
}
return algo;
};
AlgorithmOptions algoOpts = new AlgorithmOptions().setAlgorithm(Algorithms.ASTAR_BI);
logger.info("algoOpts:" + algoOpts + ", weighting: " + landmarks.getWeighting() + ", profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(graph, fromRes, toRes);
return algoFactory.createAlgo(qGraph, landmarks.getWeighting(), algoOpts);
}
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class MatchCommand method run.
@Override
protected void run(Bootstrap<GraphHopperServerConfiguration> bootstrap, Namespace args, GraphHopperServerConfiguration configuration) {
GraphHopperConfig graphHopperConfiguration = configuration.getGraphHopperConfiguration();
GraphHopper hopper = new GraphHopper().init(graphHopperConfiguration);
hopper.importOrLoad();
PMap hints = new PMap();
hints.putObject("profile", args.get("profile"));
MapMatching mapMatching = new MapMatching(hopper, hints);
mapMatching.setTransitionProbabilityBeta(args.getDouble("transition_probability_beta"));
mapMatching.setMeasurementErrorSigma(args.getInt("gps_accuracy"));
StopWatch importSW = new StopWatch();
StopWatch matchSW = new StopWatch();
Translation tr = new TranslationMap().doImport().getWithFallBack(Helper.getLocale(args.getString("instructions")));
final boolean withRoute = !args.getString("instructions").isEmpty();
XmlMapper xmlMapper = new XmlMapper();
for (File gpxFile : args.<File>getList("gpx")) {
try {
importSW.start();
Gpx gpx = xmlMapper.readValue(gpxFile, Gpx.class);
if (gpx.trk == null) {
throw new IllegalArgumentException("No tracks found in GPX document. Are you using waypoints or routes instead?");
}
if (gpx.trk.size() > 1) {
throw new IllegalArgumentException("GPX documents with multiple tracks not supported yet.");
}
List<Observation> measurements = GpxConversions.getEntries(gpx.trk.get(0));
importSW.stop();
matchSW.start();
MatchResult mr = mapMatching.match(measurements);
matchSW.stop();
System.out.println(gpxFile);
System.out.println("\tmatches:\t" + mr.getEdgeMatches().size() + ", gps entries:" + measurements.size());
System.out.println("\tgpx length:\t" + (float) mr.getGpxEntriesLength() + " vs " + (float) mr.getMatchLength());
String outFile = gpxFile.getAbsolutePath() + ".res.gpx";
System.out.println("\texport results to:" + outFile);
ResponsePath responsePath = new PathMerger(mr.getGraph(), mr.getWeighting()).doWork(PointList.EMPTY, Collections.singletonList(mr.getMergedPath()), hopper.getEncodingManager(), tr);
if (responsePath.hasErrors()) {
System.err.println("Problem with file " + gpxFile + ", " + responsePath.getErrors());
continue;
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) {
long time = gpx.trk.get(0).getStartTime().map(Date::getTime).orElse(System.currentTimeMillis());
writer.append(GpxConversions.createGPX(responsePath.getInstructions(), gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", time, hopper.hasElevation(), withRoute, true, false, Constants.VERSION, tr));
}
} catch (Exception ex) {
importSW.stop();
matchSW.stop();
System.err.println("Problem with file " + gpxFile);
ex.printStackTrace(System.err);
}
}
System.out.println("gps import took:" + importSW.getSeconds() + "s, match took: " + matchSW.getSeconds());
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class MapMatchingTest method setup.
@BeforeAll
public static void setup() {
Helper.removeDir(new File(GH_LOCATION));
graphHopper = new GraphHopper();
graphHopper.setOSMFile("../map-matching/files/leipzig_germany.osm.pbf");
graphHopper.setGraphHopperLocation(GH_LOCATION);
graphHopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
graphHopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
graphHopper.importOrLoad();
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GpxTravelTimeConsistencyTest method beforeClass.
@BeforeAll
public static void beforeClass() {
Helper.removeDir(new File(graphFileFoot));
hopper = new GraphHopper().setOSMFile(osmFile).setProfiles(new Profile("profile").setVehicle("foot").setWeighting("fastest")).setStoreOnFlush(true).setGraphHopperLocation(graphFileFoot).importOrLoad();
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class MapMatching2Test method testIssue13.
@Test
public void testIssue13() throws IOException {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
hopper.setGraphHopperLocation(GH_LOCATION);
hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
hopper.importOrLoad();
MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-13.gpx"), Gpx.class);
MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
// make sure no virtual edges are returned
int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
for (EdgeMatch em : mr.getEdgeMatches()) {
assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
validateEdgeMatch(em);
}
assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), 2.5);
assertEquals(28790, mr.getMatchMillis(), 50);
}
Aggregations