Consumption model
Allow your user to utilise the vehicle-specific consumption model when requesting a new route. The consumption model can be calculated based on a number of Routing API parameters for two vehicle types: combustion or electric, and the output will contain the additional field fuelConsumptionInLiters or batteryConsumptionInkWh. For more details, please refer to: this documentation.
Sample use case: You are planning a journey and you want to select the most optimal route in terms of fuel / energy consumption.
To request a route and calculate the consumption model for a combustion vehicle:
1RouteDescriptor routeDescriptor = new RouteDescriptor.Builder()2 .considerTraffic(false)3 .build()45RouteCalculationDescriptor routeCalculationDescriptor = new RouteCalculationDescriptor.Builder()6 .routeDescription(routeDescriptor)7 .maxAlternatives(2)8 .build();910//vehicle specific consumption model <speed, consumption in liters>11Map<Double, Double> speedToConsumptionMap = new HashMap<>();12speedToConsumptionMap.put(10.0, 6.5);13speedToConsumptionMap.put(30.0, 7.0);14speedToConsumptionMap.put(50.0, 8.0);15speedToConsumptionMap.put(70.0, 8.4);16speedToConsumptionMap.put(90.0, 7.7);17speedToConsumptionMap.put(120.0, 7.5);18speedToConsumptionMap.put(150.0, 9.0);1920CombustionVehicleConsumption combustionVehicleConsumption = new CombustionVehicleConsumption(21 CURRENT_FUEL_IN_LITERS,22 AUXILIARY_POWER_IN_LITERS_PER_HOUR,23 FUEL_ENERGY_DENSITY_IN_MJOULES_PER_LITER,24 speedToConsumptionMap25);2627CombustionVehicleDescriptor combustionVehicleDescriptor = new CombustionVehicleDescriptor.Builder()28 .vehicleConsumption(combustionVehicleConsumption)29 .vehicleDimensions(new VehicleDimensions.Builder()30 .vehicleWeightInKg(1600)31 .build()32 )33 .vehicleEfficiency(new VehicleEfficiency.Builder()34 .accelerationEfficiency(0.33)35 .decelerationEfficiency(0.33)36 .downhillEfficiency(0.33)37 .uphillEfficiency(0.33)38 .build()39 )40 .build();4142RouteSpecification routeSpecification = new RouteSpecification.Builder(routeConfig.getOrigin(), routeConfig.getDestination())43 .routeCalculationDescriptor(routeCalculationDescriptor)44 .combustionVehicleDescriptor(combustionVehicleDescriptor)45 .build();
1val vehicleEfficiency = VehicleEfficiency.Builder()2 .accelerationEfficiency(EFFICIENCY) //e.g. KineticEnergyGained/ChemicalEnergyConsumed3 .decelerationEfficiency(EFFICIENCY) //e.g. ChemicalEnergySaved/KineticEnergyLost4 .downhillEfficiency(EFFICIENCY) //e.g. ChemicalEnergySaved/PotentialEnergyLost5 .uphillEfficiency(EFFICIENCY) //e.g. PotentialEnergyGained/ChemicalEnergyConsumed6 .build()78val vehicleDimensions = VehicleDimensions.Builder()9 .vehicleWeightInKg(VEHICLE_WEIGHT)10 .build()1112//vehicle specific consumption model <speed, consumption in liters>13val combustionVehicleConsumption = CombustionVehicleConsumption(14 CURRENT_FUEL,15 AUXILIARY_POWER_COMBUSTION,16 FUEL_ENERGY_DENSITY,17 mapOf(18 Pair(10.0, 6.5),19 Pair(30.0, 7.0),20 Pair(50.0, 8.0),21 Pair(70.0, 8.4),22 Pair(90.0, 7.7),23 Pair(120.0, 7.5),24 Pair(150.0, 9.0)25 )26)2728val combustionVehicleDescriptor = CombustionVehicleDescriptor.Builder()29 .vehicleConsumption(combustionVehicleConsumption)30 .vehicleEfficiency(vehicleEfficiency)31 .vehicleDimensions(vehicleDimensions)32 .build()3334val routeDescriptor = RouteDescriptor.Builder()35 .considerTraffic(false)36 .build()3738val routeCalculationDescriptor = RouteCalculationDescriptor.Builder()39 .routeDescription(routeDescriptor)40 .maxAlternatives(MAX_ALTERNATIVES)41 .build()4243val routeSpecification = RouteSpecification.Builder(origin, destination)44 .combustionVehicleDescriptor(combustionVehicleDescriptor)45 .routeCalculationDescriptor(routeCalculationDescriptor)46 .build()
To request a route and calculate the consumption model for an electric vehicle:
1RouteDescriptor routeDescriptor = new RouteDescriptor.Builder()2 .considerTraffic(false)3 .build();45RouteCalculationDescriptor routeCalculationDescriptor = new RouteCalculationDescriptor.Builder()6 .routeDescription(routeDescriptor)7 .maxAlternatives(2)8 .build();910//vehicle specific consumption model <speed, consumption in kWh>11Map<Double, Double> speedToConsumptionMap = new HashMap<>();12speedToConsumptionMap.put(10.0, 5.0);13speedToConsumptionMap.put(30.0, 10.0);14speedToConsumptionMap.put(50.0, 15.0);15speedToConsumptionMap.put(70.0, 20.0);16speedToConsumptionMap.put(90.0, 25.0);17speedToConsumptionMap.put(120.0, 30.0);1819ElectricVehicleConsumption electricVehicleConsumption = new ElectricVehicleConsumption(20 MAX_CHARGE_IN_KWH,21 CURRENT_CHARGE_IN_KWH,22 AUXILIARY_POWER_IN_KW,23 speedToConsumptionMap);2425ElectricVehicleDescriptor electricVehicleDescriptor = new ElectricVehicleDescriptor.Builder(electricVehicleConsumption)26 .vehicleDimensions(new VehicleDimensions.Builder()27 .vehicleWeightInKg(1600)28 .build()29 )30 .vehicleEfficiency(new VehicleEfficiency.Builder()31 .accelerationEfficiency(0.33)32 .decelerationEfficiency(0.33)33 .downhillEfficiency(0.33)34 .uphillEfficiency(0.33)35 .build()36 )37 .build();3839RouteSpecification routeSpecification = new RouteSpecification.Builder(routeConfig.getOrigin(), routeConfig.getDestination())40 .routeCalculationDescriptor(routeCalculationDescriptor)41 .electricVehicleDescriptor(electricVehicleDescriptor)42 .build();
1val vehicleEfficiency = VehicleEfficiency.Builder()2 .accelerationEfficiency(EFFICIENCY) //e.g. KineticEnergyGained/ChemicalEnergyConsumed3 .decelerationEfficiency(EFFICIENCY) //e.g. ChemicalEnergySaved/KineticEnergyLost4 .downhillEfficiency(EFFICIENCY) //e.g. ChemicalEnergySaved/PotentialEnergyLost5 .uphillEfficiency(EFFICIENCY) //e.g. PotentialEnergyGained/ChemicalEnergyConsumed6 .build()78val vehicleDimensions = VehicleDimensions.Builder()9 .vehicleWeightInKg(VEHICLE_WEIGHT)10 .build()1112//vehicle specific consumption model <speed, consumption in liters>13val electricVehicleConsumption = ElectricVehicleConsumption(14 MAX_ELECTRIC_CHARGE,15 CURRENT_ELECTRIC_CHARGE,16 AUXILIARY_POWER_ELECTRIC,17 mapOf(18 Pair(10.0, 5.0),19 Pair(30.0, 10.0),20 Pair(50.0, 15.0),21 Pair(70.0, 20.0),22 Pair(90.0, 25.0),23 Pair(120.0, 30.0)24 )25)2627val electricVehicleDescriptor = ElectricVehicleDescriptor.Builder(electricVehicleConsumption)28 .vehicleEfficiency(vehicleEfficiency)29 .vehicleDimensions(vehicleDimensions)30 .build()3132val routeDescriptor = RouteDescriptor.Builder()33 .considerTraffic(false)34 .build()3536val routeCalculationDescriptor = RouteCalculationDescriptor.Builder()37 .routeDescription(routeDescriptor)38 .maxAlternatives(MAX_ALTERNATIVES)39 .build()4041val routeSpecification = RouteSpecification.Builder(origin, destination)42 .electricVehicleDescriptor(electricVehicleDescriptor)43 .routeCalculationDescriptor(routeCalculationDescriptor)44 .build()
Combustion | Electric |