Skip to content

Commit 4cbba82

Browse files
committed
include measurement for alternative routes graphhopper#1722
1 parent 631fd1e commit 4cbba82

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

tools/src/main/java/com/graphhopper/tools/Measurement.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.concurrent.atomic.AtomicLong;
5050

5151
import static com.graphhopper.util.Helper.*;
52+
import static com.graphhopper.util.Parameters.Algorithms.ALT_ROUTE;
5253
import static com.graphhopper.util.Parameters.Algorithms.DIJKSTRA_BI;
5354

5455
/**
@@ -169,7 +170,7 @@ protected DataReader importData() throws IOException {
169170
printLocationIndexQuery(g, hopper.getLocationIndex(), count);
170171
if (runSlow) {
171172
printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr,
172-
true, false, -1, true, false, false);
173+
true, false, -1, true, false, false, false);
173174
}
174175

175176
if (hopper.getLMFactoryDecorator().isEnabled()) {
@@ -178,7 +179,7 @@ protected DataReader importData() throws IOException {
178179
int activeLMCount = 12;
179180
for (; activeLMCount > 3; activeLMCount -= 4) {
180181
printTimeOfRouteQuery(hopper, isCH, isLM, count / 4, "routingLM" + activeLMCount, vehicleStr,
181-
true, false, activeLMCount, true, false, false);
182+
true, false, activeLMCount, true, false, false, false);
182183
}
183184

184185
// compareRouting(hopper, vehicleStr, count / 5);
@@ -193,7 +194,7 @@ protected DataReader importData() throws IOException {
193194
// try just one constellation, often ~4-6 is best
194195
int lmCount = 5;
195196
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCHLM" + lmCount, vehicleStr,
196-
true, false, lmCount, true, false, false);
197+
true, false, lmCount, true, false, false, false);
197198
}
198199

199200
isLM = false;
@@ -203,24 +204,26 @@ protected DataReader importData() throws IOException {
203204
CHGraph lg = g.getCHGraph(chProfile);
204205
fillAllowedEdges(lg.getAllEdges(), allowedEdges);
205206
printMiscUnitPerfTests(lg, isCH, encoder, count * 100, allowedEdges);
206-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr,
207-
true, false, -1, true, false, false);
208-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_with_hints", vehicleStr,
209-
true, true, -1, true, false, false);
210-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_sod", vehicleStr,
211-
true, false, -1, false, false, false);
212-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr,
213-
false, false, -1, true, false, false);
214-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_full", vehicleStr,
215-
true, true, -1, true, false, true);
207+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true,
208+
false, -1, true, false, false, false);
209+
printTimeOfRouteQuery(hopper, isCH, isLM, count / 10, "routingCH_alt", vehicleStr, true,
210+
false, -1, true, false, false, true);
211+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_with_hints", vehicleStr, true,
212+
true, -1, true, false, false, false);
213+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_sod", vehicleStr, true,
214+
false, -1, false, false, false, false);
215+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false,
216+
false, -1, true, false, false, false);
217+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_full", vehicleStr, true,
218+
true, -1, true, false, true, false);
216219
}
217220
if (!hopper.getCHFactoryDecorator().getEdgeBasedCHProfiles().isEmpty()) {
218-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge", vehicleStr,
219-
true, false, -1, false, true, false);
220-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge_no_instr", vehicleStr,
221-
false, false, -1, false, true, false);
222-
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge_full", vehicleStr,
223-
true, true, -1, false, true, true);
221+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge", vehicleStr, true,
222+
false, -1, false, true, false, false);
223+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge_no_instr", vehicleStr, false,
224+
false, -1, false, true, false, false);
225+
printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_edge_full", vehicleStr, true,
226+
true, -1, false, true, true, false);
224227
}
225228
}
226229
} catch (Exception ex) {
@@ -453,12 +456,13 @@ private void printTimeOfRouteQuery(final GraphHopper hopper, final boolean ch, f
453456
int count, String prefix, final String vehicle,
454457
final boolean withInstructions, final boolean withPointHints,
455458
final int activeLandmarks, final boolean sod, final boolean edgeBased,
456-
final boolean simplify) {
459+
final boolean simplify, final boolean alternative) {
457460
final Graph g = hopper.getGraphHopperStorage();
458461
final AtomicLong maxDistance = new AtomicLong(0);
459462
final AtomicLong minDistance = new AtomicLong(Long.MAX_VALUE);
460463
final AtomicLong distSum = new AtomicLong(0);
461464
final AtomicLong airDistSum = new AtomicLong(0);
465+
final AtomicLong altCount = new AtomicLong(0);
462466
final AtomicInteger failedCount = new AtomicInteger(0);
463467
final DistanceCalc distCalc = new DistanceCalcEarth();
464468

@@ -492,6 +496,9 @@ public int doCalc(boolean warmup, int run) {
492496
put(Landmark.ACTIVE_COUNT, activeLandmarks).
493497
put("instructions", withInstructions);
494498

499+
if (alternative)
500+
req.setAlgorithm(ALT_ROUTE);
501+
495502
if (withInstructions)
496503
req.setPathDetails(Arrays.asList(Parameters.Details.AVERAGE_SPEED));
497504

@@ -555,10 +562,8 @@ else if (!toLowerCase(rsp.getErrors().get(0).getMessage()).contains("not found")
555562
if (dist < minDistance.get())
556563
minDistance.set(dist);
557564

558-
// extractTimeSum.addAndGet(p.getExtractTime());
559-
// long start = System.nanoTime();
560-
// size = p.calcPoints().getSize();
561-
// calcPointsTimeSum.addAndGet(System.nanoTime() - start);
565+
if (alternative)
566+
altCount.addAndGet(rsp.getAll().size());
562567
}
563568

564569
return arsp.getPoints().getSize();
@@ -580,17 +585,13 @@ else if (!toLowerCase(rsp.getErrors().get(0).getMessage()).contains("not found")
580585
put(prefix + ".distance_max", maxDistance.get());
581586
put(prefix + ".visited_nodes_mean", (float) visitedNodesSum.get() / count);
582587
put(prefix + ".visited_nodes_max", (float) maxVisitedNodes.get());
583-
584-
// put(prefix + ".extractTime", (float) extractTimeSum.get() / count / 1000000f);
585-
// put(prefix + ".calcPointsTime", (float) calcPointsTimeSum.get() / count / 1000000f);
586-
// put(prefix + ".calcDistTime", (float) calcDistTimeSum.get() / count / 1000000f);
588+
put(prefix + ".alternative_rate", (float) altCount.get() / count);
587589
print(prefix, miniPerf);
588590
}
589591

590592
void print(String prefix, MiniPerfTest perf) {
591593
logger.info(prefix + ": " + perf.getReport());
592594
put(prefix + ".sum", perf.getSum());
593-
// put(prefix+".rms", perf.getRMS());
594595
put(prefix + ".min", perf.getMin());
595596
put(prefix + ".mean", perf.getMean());
596597
put(prefix + ".max", perf.getMax());

0 commit comments

Comments
 (0)