Skip to content

Commit d093043

Browse files
committed
Fix integer overflow in PrepareContractionHierarchies
1 parent e2d22c8 commit d093043

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/src/main/java/com/graphhopper/routing/ch/PrepareContractionHierarchies.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,24 @@ private void contractNodesUsingHeuristicNodeOrdering() {
235235
checkCounter = 0;
236236
final long logSize = params.getLogMessagesPercentage() == 0
237237
? Long.MAX_VALUE
238-
: Math.round(Math.max(10, initSize * params.getLogMessagesPercentage() / 100d));
238+
: Math.round(Math.max(10, initSize * (params.getLogMessagesPercentage() / 100d)));
239239

240240
// specifies after how many contracted nodes the queue of remaining nodes is rebuilt. this takes time but the
241241
// more often we do this the more up-to-date the node priorities will be
242242
// todo: instead of using a fixed interval size maybe try adjusting it depending on the number of remaining
243243
// nodes ?
244244
final long periodicUpdatesCount = params.getPeriodicUpdatesPercentage() == 0
245245
? Long.MAX_VALUE
246-
: Math.round(Math.max(10, initSize * params.getPeriodicUpdatesPercentage() / 100d));
246+
: Math.round(Math.max(10, initSize * (params.getPeriodicUpdatesPercentage() / 100d)));
247247
int updateCounter = 0;
248248

249249
// enable lazy updates for last x percentage of nodes. lazy updates make preparation slower but potentially
250250
// keep node priorities more up to date, possibly resulting in a better preparation.
251-
final long lastNodesLazyUpdates = Math.round(initSize * params.getLastNodesLazyUpdatePercentage() / 100d);
251+
final long lastNodesLazyUpdates = Math.round(initSize * (params.getLastNodesLazyUpdatePercentage() / 100d));
252252

253253
// according to paper "Polynomial-time Construction of Contraction Hierarchies for Multi-criteria Objectives" by Funke and Storandt
254254
// we don't need to wait for all nodes to be contracted
255-
final long nodesToAvoidContract = Math.round(initSize * (100 - params.getNodesContractedPercentage()) / 100d);
255+
final long nodesToAvoidContract = Math.round(initSize * ((100 - params.getNodesContractedPercentage()) / 100d));
256256

257257
// Recompute priority of (the given percentage of) uncontracted neighbors. Doing neighbor updates takes additional
258258
// time during preparation but keeps node priorities more up to date. this potentially improves query time and

0 commit comments

Comments
 (0)