Skip to main content

Vehicle Constraints

|

Vehicle Constraints class in Fleet Management SDK define the limitations and requirements applied to a vehicle during the route optimization process. These constraints ensure that the vehicle operates within its capabilities, such as capacity, distance, and revenue limits. Properly configuring these constraints ensures that the optimization algorithm generates feasible and efficient routes for the vehicle.

Vehicle Constraints Structure

Each Vehicle Constraint consists of:

NameTypeDescription
StartDateTimeThe date when the vehicle starts its route. Default is the current UTC time.
MaxNumberOfPackagesunsigned intThe maximum number of packages that the vehicle can carry. Default is INT_MAX.
MinNumberOfOrdersunsigned intThe minimum number of orders that the vehicle must visit. Default is 0.
MaxNumberOfOrdersunsigned intThe maximum number of orders that the vehicle can visit. Default is INT_MAX.
MinDistancefloatThe minimum distance that the vehicle must travel (in the same distance unit as set in ConfigurationParameters). Default is 0.
MaxDistancefloatThe maximum distance that the vehicle can travel (in the same distance unit as set in ConfigurationParameters). Default is INT_MAX.
MaxRevenuefloatThe maximum revenue that the vehicle can collect in total from all customers. Default is INT_MAX.
FuelPricefloatThe price for 1 liter of fuel or 1 kWh for an electric engine. This value is set using the Service::addFuelPrices() method.

Example Usage

gem::vrp::VehicleConstraints vehicleConstraints;  
vehicleConstraints.setStartDate(startTime);
vehicleConstraints.setEndDate(endTime);
vehicleConstraints.setMaxNumberOfPackages(100);
vehicleConstraints.setMinNumberOfOrders(5);
vehicleConstraints.setMaxNumberOfOrders(20);
vehicleConstraints.setMinDistance(50.0f);
vehicleConstraints.setMaxDistance(500.0f);
vehicleConstraints.setMaxRevenue(10000.0f);

Explanation

This setup configures a vehicle with the following vehicleConstraints:

  • Start time – The vehicle begins its route at the specified startTime.
  • End time – The vehicle must finish its route by the specified endTime.
  • Maximum of 100 packages – The vehicle can carry up to 100 packages.
  • Minimum of 5 orders – The vehicle must visit at least 5 orders.
  • Maximum of 20 orders – The vehicle can visit up to 20 orders.
  • Minimum distance of 50 units – The vehicle must travel at least 50 units (e.g., kilometers or miles, depending on the configuration).
  • Maximum distance of 500 units – The vehicle cannot travel more than 500 units.
  • Maximum revenue of 10,000 – The total revenue collected from all customers must not exceed 10,000.

These constraints ensure that the vehicle operates within its defined limits, allowing the optimization algorithm to generate feasible and efficient routes.