From bd025875d452ffb8873459d8523bae227bb0806e Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Tue, 27 Nov 2018 23:03:46 +0100 Subject: [PATCH] Few fixes to travel time computation * Takes `costfactor` into account for switching to walking mode. * Better energy computation in hiking mode. * Reword the `bikerMass` to make it clearer for different modes. --- .../src/main/java/btools/router/RoutingContext.java | 6 +++--- brouter-core/src/main/java/btools/router/StdPath.java | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index 9adbffa..d5a70cb 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -175,8 +175,8 @@ public final class RoutingContext turnInstructionRoundabouts = expctxGlobal.getVariableValue( "turnInstructionRoundabouts", 1.f ) != 0.f; // Speed computation model (for bikes) - // Mass of the biker + bike + luggages, in kg - bikeMass = expctxGlobal.getVariableValue( "bikeMass", 90.f ); + // Total mass (biker + bike + luggages or hiker), in kg + totalMass = expctxGlobal.getVariableValue( "totalMass", 90.f ); // Max speed (before braking), in km/h in profile and m/s in code maxSpeed = expctxGlobal.getVariableValue( "maxSpeed", 45.f ) / 3.6; // Equivalent surface for wind, S * C_x, F = -1/2 * S * C_x * v^2 = - S_C_x * v^2 @@ -225,7 +225,7 @@ public final class RoutingContext public boolean turnInstructionRoundabouts; // Speed computation model (for bikes) - public double bikeMass; + public double totalMass; public double maxSpeed; public double S_C_x; public double defaultC_r; diff --git a/brouter-core/src/main/java/btools/router/StdPath.java b/brouter-core/src/main/java/btools/router/StdPath.java index c299f04..4eef9d7 100644 --- a/brouter-core/src/main/java/btools/router/StdPath.java +++ b/brouter-core/src/main/java/btools/router/StdPath.java @@ -244,16 +244,21 @@ final class StdPath extends OsmPath double incline = calcIncline( dist ); double speed; // Travel speed - double f_roll = rc.bikeMass * GRAVITY * ( rc.defaultC_r + incline ); - if (rc.footMode ) + double energy; + if (rc.footMode || rc.expctxWay.getCostfactor() > 5) { // Use Tobler's hiking function for walking sections speed = 6 * exp(-3.5 * Math.abs( incline + 0.05)) / 3.6; + energy = rc.totalMass * GRAVITY * incline * dist; } else if (rc.bikeMode) { + double f_roll = rc.totalMass * GRAVITY * ( rc.defaultC_r + incline ); speed = solveCubic( rc.S_C_x, f_roll, rc.bikerPower ); speed = Math.min(speed, rc.maxSpeed); + // Don't compute energy assuming constant biker power, as speed is capped + // to a max value. + energy = dist*(rc.S_C_x*speed*speed + f_roll); } else { @@ -261,7 +266,7 @@ final class StdPath extends OsmPath } float dt = (float) ( dist / speed ); totalTime += dt; - totalEnergy += dist*(rc.S_C_x*speed*speed + f_roll); + totalEnergy += energy; } private static double solveCubic( double a, double c, double d )