本文整理汇总了Java中com.graphhopper.routing.Path类的典型用法代码示例。如果您正苦于以下问题:Java Path类的具体用法?Java Path怎么用?Java Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Path类属于com.graphhopper.routing包,在下文中一共展示了Path类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createHopper
import com.graphhopper.routing.Path; //导入依赖的package包/类
/**
* Helper method to create a {@link HeatStressGraphHopper} instance using
* the specified files.
*
* @param osmFile
* a OSM XML or OSM PBF file (see {@link OSMFileReader})
* @param weatherDataFile
* a CSV file containing the data of the weather station (see
* {@link WeatherDataParser})
* @param waySegmentsFile
* a CSV file containing the weighted lines segments (see
* {@link WaySegmentParser})
* @return a {@code HeatStressGraphHopper} instance
* @throws IOException
* if an error occurs while reading one of the specified files
*/
public static HeatStressGraphHopper createHopper(File osmFile,
File weatherDataFile, File waySegmentsFile) throws IOException {
java.nio.file.Path ghLocation = Files
.createTempDirectory("graph_hopper");
OSMData osmData = new OSMFileReader().read(osmFile);
WeatherData weatherData = new WeatherDataParser()
.parse(weatherDataFile);
WaySegments waySegments = new WaySegmentParser().parse(waySegmentsFile);
HeatStressGraphHopper hopper = new HeatStressGraphHopper();
hopper.getCHFactoryDecorator().setEnabled(false);
hopper.setOSMFile(osmFile.getAbsolutePath());
hopper.setGraphHopperLocation(ghLocation.toString());
hopper.setEncodingManager(new EncodingManager(FlagEncoderFactory.FOOT));
hopper.setOsmData(osmData);
hopper.setWeatherData(weatherData);
hopper.setSegments(waySegments);
hopper.importOrLoad();
return hopper;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:41,代码来源:RoutingHelper.java
示例2: doMapMatching
import com.graphhopper.routing.Path; //导入依赖的package包/类
public List<GPXEntry> doMapMatching(List<GPXEntry> gpxUnmatched) {
List<GPXEntry> gpxMatched = new ArrayList<GPXEntry>();
MapMatching mapMatching = new MapMatching(hopper, opts);
mapMatching.setMeasurementErrorSigma(50);
// perform map matching, return null if it fails
MatchResult mr = null;
try {
mr = mapMatching.doWork(gpxUnmatched);
}
catch (Exception ex) {
//System.out.println("MapMatching error: " + ex.getMessage());
return null;
}
// get points of matched track
Path path = mapMatching.calcPath(mr);
PointList points = path.calcPoints();
if (points != null && !points.isEmpty()) {
for (GHPoint pt : points) {
// set elevation and time to zero for now
gpxMatched.add(new FCDEntry(pt.lat, pt.lon, 0.0, 0, 0));
}
}
return gpxMatched;
}
开发者ID:MAGDa-BeuthHS,项目名称:fcd2pgsql,代码行数:29,代码来源:MapMatcher.java
示例3: RoutingResponse
import com.graphhopper.routing.Path; //导入依赖的package包/类
public RoutingResponse(RoutingRequest request, GHRequest ghRequest,
GHResponse ghResponse, List<Path> paths) {
this.request = request;
this.ghRequest = ghRequest;
this.ghResponse = ghResponse;
this.paths = paths;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:8,代码来源:RoutingResponse.java
示例4: routePaths
import com.graphhopper.routing.Path; //导入依赖的package包/类
/**
* Calculates the path from specified request visiting the specified
* locations.
*
* @param request
* @param time
* @return the {@link GHResponse} and a list of the found paths
*/
public Pair<GHResponse, List<Path>> routePaths(GHRequest request,
LocalDateTime time) {
// add the time to the weightingMap which is passed to the
// createWeighting method
request.getHints().put("time", time.toString());
return routePaths(request);
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:17,代码来源:HeatStressGraphHopper.java
示例5: route
import com.graphhopper.routing.Path; //导入依赖的package包/类
/**
* Executes a specified {@link RoutingRequest}.
*
* @param request
* the {@link RoutingRequest} to performe
* @return a instance of {@link RoutingResponse} containing the
* {@link GHResponse} as well as {@link Path}s returned by
* {@link HeatStressGraphHopper#routePaths(GHRequest, LocalDateTime)}
*
* @see HeatStressGraphHopper#routePaths(GHRequest, LocalDateTime)
*/
public RoutingResponse route(final RoutingRequest request) {
GHRequest req = new GHRequest(request.getStart(),
request.getDestination())
.setWeighting(request.getWeightingType().toString())
.setVehicle(request.getEncodingManager())
.setLocale(request.getLocale())
.setAlgorithm(request.getRoutingAlgorithm());
Pair<GHResponse, List<Path>> rsp = hopper.routePaths(req,
request.getTime());
return new RoutingResponse(request, req, rsp.getLeft(), rsp.getRight());
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:26,代码来源:RoutingHelper.java
示例6: routePathShortest
import com.graphhopper.routing.Path; //导入依赖的package包/类
/**
* Finds the shortest route between {@code from} and {@code to}.
*
* @param from
* the start
* @param to
* the destination
* @return the shortest route as a {@link Path} or the errors returned by
* GraphHopper
*/
public Result<Path, List<Throwable>> routePathShortest(GHPoint from,
GHPoint to) {
GHRequest req = new GHRequest(from, to)
.setWeighting(WeightingType.SHORTEST.toString())
.setVehicle(encodingManager).setLocale(locale)
.setAlgorithm(routingAlgorithm);
Pair<GHResponse, List<Path>> rsp = hopper.routePaths(req);
if (rsp.getLeft().hasErrors())
return Result.errorOf(rsp.getLeft().getErrors());
else
return Result.okayOf(rsp.getRight().get(0));
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:25,代码来源:RoutingHelper.java
示例7: NearbySearchResult
import com.graphhopper.routing.Path; //导入依赖的package包/类
public NearbySearchResult(int rank, double score, Node place,
OptimalTimeFinderResult optimalTimeFinderResult, Path pathOptimal,
Path pathShortest) {
super(optimalTimeFinderResult.getOptimalTime(),
optimalTimeFinderResult.getDistance(),
optimalTimeFinderResult.getOptimalValue(),
optimalTimeFinderResult.getDuration(), pathOptimal,
pathShortest);
this.rank = rank;
this.score = score;
this.place = place;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:13,代码来源:NearbySearchResult.java
示例8: getOptimalTime
import com.graphhopper.routing.Path; //导入依赖的package包/类
Pair<LocalDateTime, Double> getOptimalTime(Path path,
TimeRange<LocalDateTime> timeRange, int starts) {
// the objective function to be passed to the BrentOptimizer
UnivariateFunction univariateFunction = (x) -> {
LocalDateTime time = timeRange.getFrom().plusSeconds((long) x);
Weighting weighting = routingHelper
.createWeighting(this.weightingType, time);
OptionalDouble value = objectiveFunctionPath.value(time, path,
weighting);
if (value.isPresent()) {
return value.getAsDouble();
} else {
return Double.MAX_VALUE;
}
};
// interval used for optimization is 0 and the duration between the
// lower and upper bound in seconds
double lower = 0;
double upper = timeRange.durationInSeconds() + 1;
logger.debug("lower = " + lower + ", upper = " + upper);
BrentOptimizer optimizer = new BrentOptimizer(RELATIVE_THRESHOLD,
ABSOLUTE_THRESHOLD);
MultiStartUnivariateOptimizer multiStartOptimizer = new MultiStartUnivariateOptimizer(
optimizer, starts, rng);
UnivariatePointValuePair res = multiStartOptimizer.optimize(
new MaxEval(MAX_EVAL), GOAL_TYPE,
new SearchInterval(lower, upper),
new UnivariateObjectiveFunction(univariateFunction));
return Pair.of(timeRange.getFrom().plusSeconds((long) res.getPoint()),
res.getValue());
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:39,代码来源:OptimalTimeFinderHeuristic.java
示例9: getEdges
import com.graphhopper.routing.Path; //导入依赖的package包/类
List<GPXEntry> getEdges(int index) {
Path path = paths.get(index);
Translation tr = getTranslationMap().get("en");
InstructionList instr = path.calcInstructions(tr);
// GPXFile.write(path, "calculated-route.gpx", tr);
return instr.createGPXList();
}
开发者ID:ianmalcolm,项目名称:DeadReckoning,代码行数:8,代码来源:GraphHopperTest.java
示例10: loadGraphStorage
import com.graphhopper.routing.Path; //导入依赖的package包/类
public void loadGraphStorage()
{
prepareInProgress = true;
try {
// logUser("loading graph (" + Constants.VERSION + ") ... ");
new GHAsyncTask<Void, Void, Path>() {
protected Path saveDoInBackground(Void... v) throws Exception {
GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.setCHEnable(true);
tmpHopp.load(new File(Environment.getExternalStorageDirectory() + "/DolphinLocationApp"
+ "/Routing").getAbsolutePath());
log("found graph " + tmpHopp.getGraph().toString() + ", nodes:" + tmpHopp.getGraph().getNodes());
hopper = tmpHopp;
return null;
}
protected void onPostExecute(Path o) {
if (hasError()) {
Log.i("", "An error happend while creating graph:"
+ getErrorMessage());
} else {
Log.i("", "Finished loading graph. Press long to define where to start and end the route.");
}
finishPrepare();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
catch (Exception e)
{
}
}
开发者ID:Arman92,项目名称:Mapsforge-OsmDroid-GraphHopper,代码行数:34,代码来源:RouteCalculator.java
示例11: write
import com.graphhopper.routing.Path; //导入依赖的package包/类
public static void write(Path path, String gpxFile, Translation translation) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(gpxFile));
writer.append(path.calcInstructions(translation).createGPX());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
Helper.close(writer);
}
}
开发者ID:graphhopper,项目名称:map-matching,代码行数:12,代码来源:GPXFile.java
示例12: getPaths
import com.graphhopper.routing.Path; //导入依赖的package包/类
public List<Path> getPaths() {
return paths;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:4,代码来源:RoutingResponse.java
示例13: doRouting
import com.graphhopper.routing.Path; //导入依赖的package包/类
private Optional<RoutingResultRecord> doRouting(int recordId, int i,
WeightingType method, Node fromNode, Node toNode, GHPoint from,
GHPoint to, LocalDateTime time) {
if (method == WeightingType.SHORTEST) {
System.out.print("Shortest Path Routing... ");
} else if (method == WeightingType.TEMPERATURE) {
System.out.print("Minimum Temperature Routing... ");
} else if (method == WeightingType.HEAT_INDEX) {
System.out.print("Minimum Heat Index Routing... ");
} else if (method == WeightingType.HEAT_INDEX_WEIGHTED) {
System.out.print("Weighted Minimum Heat Index Routing... ");
} else {
throw new IllegalStateException(
"unsupported weighting method '" + method + "'");
}
StopWatch sw = new StopWatch();
sw.start();
GHRequest reqShortest = new GHRequest(from, to)
.setWeighting(method.toString())
.setVehicle(FlagEncoderFactory.FOOT).setLocale(Locale.GERMAN)
.setAlgorithm(routingAlgo);
Pair<GHResponse, List<Path>> resShortest = this.hopper
.routePaths(reqShortest, time);
sw.stop();
System.out.println("done (" + sw.getTime() + " ms)");
GHResponse rsp = resShortest.getLeft();
if (rsp.hasErrors()) {
logger.error("rsp " + method.toString() + " hasErros = "
+ rsp.getErrors());
logger.debug("Errors: ");
rsp.getErrors().forEach(Throwable::getMessage);
rsp.getErrors().forEach(Throwable::printStackTrace);
return Optional.empty();
}
PathWrapper pathWrapper = rsp.getBest();
Path path = resShortest.getRight().get(0);
double dist = pathWrapper.getDistance();
double costsTemp = routeCostsTemperature(path, time);
double costsHeatIndex = routeCostsHeatIndex(path, time);
Duration duration = Duration.ofMillis(pathWrapper.getTime());
System.out.println("\tDistance: " + dist + ", costsTemperature: "
+ costsTemp + ", costsHeatIndex: " + costsHeatIndex
+ ", Duration: " + Utils.formatDuration(duration));
return Optional.of(new RoutingResultRecord(recordId, i, time,
method.toString(), fromNode, toNode, dist, costsTemp,
costsHeatIndex, duration.toMillis(), pathWrapper.getPoints()));
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:55,代码来源:RoutingEvaluator.java
示例14: routeCostsTemperature
import com.graphhopper.routing.Path; //导入依赖的package包/类
private double routeCostsTemperature(Path path, LocalDateTime time) {
return routeCosts(path,
createWeighting(WeightingType.TEMPERATURE, time));
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:5,代码来源:RoutingEvaluator.java
示例15: routeCostsHeatIndex
import com.graphhopper.routing.Path; //导入依赖的package包/类
private double routeCostsHeatIndex(Path path, LocalDateTime time) {
return routeCosts(path,
createWeighting(WeightingType.HEAT_INDEX, time));
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:6,代码来源:RoutingEvaluator.java
示例16: routeCosts
import com.graphhopper.routing.Path; //导入依赖的package包/类
private double routeCosts(Path path, Weighting weighting) {
return path.calcEdges().stream()
.mapToDouble(e -> weighting.calcWeight(e, false, 0)).sum();
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:5,代码来源:RoutingEvaluator.java
示例17: getGhLocation
import com.graphhopper.routing.Path; //导入依赖的package包/类
public java.nio.file.Path getGhLocation() {
return ghLocation;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:4,代码来源:RoutingEvaluator.java
示例18: setGhLocation
import com.graphhopper.routing.Path; //导入依赖的package包/类
public void setGhLocation(java.nio.file.Path ghLocation) {
this.ghLocation = ghLocation;
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:4,代码来源:RoutingEvaluator.java
示例19: getReferenceResultItem
import com.graphhopper.routing.Path; //导入依赖的package包/类
private List<OptimalTimeResultItem> getReferenceResultItem(
OptimalTimeEvaluationItem item) {
Predicate<Entity> nodeFilter = EntityFilter
.containsAnyTag(item.getTargetTags())
.and(EntityFilter::hasOpeningHours);
GHPoint start = OSMUtils.getGHPoint(item.start);
int maxResults = item.maxResults != null ? item.maxResults
: this.nearbySearchMaxResults;
double maxDist = item.maxDistance != null ? item.maxDistance
: this.maxDistance;
List<Node> places = osmData.kNearestNeighbor(start, maxResults, maxDist,
nodeFilter);
RoutingHelper helper = new RoutingHelper(hopper);
List<OptimalTimeResultItem> resultItems = new ArrayList<>(
places.size());
for (Node place : places) {
GHPoint placePoint = OSMUtils.getGHPoint(place);
Optional<Path> path = helper.routePathShortest(start, placePoint)
.get();
if (!path.isPresent())
continue;
Optional<OSMOpeningHours> openingHours = osmData
.getOpeningHours(place.getId());
if (!openingHours.isPresent())
continue;
Duration tWalk = Duration.ofMillis(path.get().getTime());
ZonedDateTime tNow = item.now.atZone(ZoneId.systemDefault());
ZonedDateTime tUpper = tNow.plus(tWalk).plus(item.timeBuffer);
double temp = weatherData.getTemperature(tNow.toLocalDateTime());
double rh = weatherData.getRelativeHumidity(tNow.toLocalDateTime());
double hi;
if (HeatIndex.isValidTemperature(temp)
&& HeatIndex.isValidHumidity(rh))
hi = HeatIndex.heatIndex(temp, rh);
else
hi = temp;
if (openingHours.get().isOpenedForTime(tNow)
&& openingHours.get().isOpenedForTime(tUpper)) {
double costRouteTemp = helper.routeWeight(path.get(), item.now,
WeightingType.TEMPERATURE);
double costRouteHI = helper.routeWeight(path.get(), item.now,
WeightingType.HEAT_INDEX);
resultItems.add(new OptimalTimeResultItem(place, item.now,
OptimalTimeResultType.REFERENCE, -1, hi,
path.get().getDistance(), path.get().getTime(),
weatherData.getTemperature(item.now),
weatherData.getHeatIndex(item.now)
.orElse(weatherData.getTemperature(item.now)),
costRouteTemp, costRouteHI, path.get().calcPoints()));
}
}
return Seq
.seq(resultItems).sorted((i1, i2) -> Double
.compare(i1.getDistance(), i2.getDistance()))
.zipWithIndex().map(t -> {
int rank = ((int) t.v2().longValue()) + 1;
return t.v1().setRank(rank);
}).toList();
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:78,代码来源:OptimalTimeEvaluator.java
示例20: value
import com.graphhopper.routing.Path; //导入依赖的package包/类
public OptionalDouble value(LocalDateTime time, Path path, Weighting weighting) {
return OptionalDouble.of(routingHelper.routeWeight(path, time, weightingType));
}
开发者ID:biggis-project,项目名称:path-optimizer,代码行数:4,代码来源:ObjectiveFunctionPathImpl.java
注:本文中的com.graphhopper.routing.Path类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论