Constraints and rules play a crucial role in establishing relationships between various entities like vehicles, orders, tasks, and depots within the optimization process. They define specific limitations or conditional modifications that need to be taken into account when scheduling routes and assigning tasks.
Constraints typically serve as strict, non-negotiable boundaries that must be respected during optimization, ensuring that certain conditions — such as restricting specific orders from being assigned to certain vehicles or enforcing a specific sequence of tasks — are always upheld. In contrast, rules provide flexibility by allowing adjustments to properties such as preparation durations at locations, which can vary based on the vehicle assigned to the stop or the preceding location. Together, constraints ensure feasibility, while rules allow fine-tuning of behavior to meet specific operational requirements.
Categories
Constraints and rules are usually not only specific to one entity, like a vehicle or order, but entail different classes of entities. Therefore constraints are expressed based on categories, which are often functional properties of the entity itself. Examples of categories might be whether or not a vehicle can be cooled, the region a depot is located or whether a task requires certification of the driver.
Constraints are expressed between categories of locations, orders, tasks, vehicles and depots. Each of these entities can define the categories it belongs to. If a constraint is expressed towards a category that does not contain any entities, the constraint is ignored.
Constraints
There are three types of constraints that can be used.
- Combination constraints restrict whether two entities can be used together, such as whether or not a depot is allowed to be visited by a vehicle.
- Order constraints restrict how orders can be structurally planned on a route.
- Task constraints restrict how tasks can be structurally planned on a route.
Each constraint places restrictions on the scheduling of tasks along routes. During the optimization process, all constraints, including the default ones associated with route structure, are taken into account. Each new constraint serves as an additional requirement, meaning that for a route to be valid, it must satisfy all the imposed constraints simultaneously.
Combination constraints
Combination constraints define relationships between various entities like vehicles, orders, and depots. They can both restrict as well as enforce certain combinations to guide optimization, aiding in efficient route planning.
Order-vehicle combination constraints
Order-vehicle combination constraints restrict which orders can or should be transported by which vehicles. There are three types of order-vehicle constraints available.
Order requires vehicle
When an order requires a vehicle, orders with the specified order category must be transported by a vehicle with the required vehicle category.
Example
Your fresh orders might require a vehicle to have a cooling compartment.
"constraints":{ "combinations":{ "orderVehicle":[ { "type":"ORDER_REQUIRES_VEHICLE", "orderCategory":"FRESH", "vehicleCategory":"COOLING_COMPARTMENT" } ] } }
Vehicle requires order
When a vehicle requires an order, vehicles with the specified vehicle category can only transport orders with the required order category.
Example
Your low-emission vehicles might be reserved to handle orders within a city center.
"constraints":{ "combinations":{ "orderVehicle":[ { "type":"VEHICLE_REQUIRES_ORDER", "orderCategory":"CITY_CENTER", "vehicleCategory":"LOW_EMISSION" } ] } }
Forbidden combination
When an order-vehicle combination is forbidden, an order with the specified order category is not allowed to be transported by a vehicle with the specified vehicle category.
Example
If you have vehicles with advertisements for company A, displayed on their side but company B is also a customer. Those vehicles are not allowed to visit company B.
"constraints":{ "combinations":{ "orderVehicle":[ { "type":"FORBIDDEN_COMBINATION", "orderCategory":"COMPANY_B", "vehicleCategory":"ADVERTISES_COMPANY_A" } ] } }
Violation cost
When a violation cost is set, the constraint can be overridden. Optimization may violate the constraint if paying the violation cost leads to an overall cheaper plan.
Example
Orders for which a task is situated in Belgium might not be ideally delivered from Germany unless the routes become significantly more efficient. In this example we allow a Germany-based vehicle to deliver to a Belgian store if it saves 10 euros of transportation cost.
"constraints":{ "combinations":{ "orderVehicle":[ { "type":"FORBIDDEN_COMBINATION", "orderCategory":"BELGIAN_STORE", "vehicleCategory":"GERMANY_BASED", "violationCost":10 } ] } }
Depot-vehicle combination constraints
Depot-vehicle combination constraints restrict which depots can or should be visited by which vehicles. There are three types of depot-vehicle constraints available.
Depot requires vehicle
When a depot requires a vehicle, depots with the specified depot category can only be visited by vehicles with the required vehicle category.
Example
Depots within a low-emission zone can only be accessed by low-emission vehicles.
"constraints":{ "combinations":{ "depotVehicle":[ { "type":"DEPOT_REQUIRES_VEHICLE", "depotCategory":"LOW-EMISSION", "vehicleCategory":"LOW-EMISSION" } ] } }
Vehicle requires depot
When a vehicle requires a depot, vehicles with the specified vehicle category can only visit depots with the required depot category.
Example
Depots located in Berlin might be reserved for vehicles based in Germany.
"constraints":{ "combinations":{ "depotVehicle":[ { "type":"VEHICLE_REQUIRES_DEPOT", "depotCategory":"BERLIN", "vehicleCategory":"GERMANY" } ] } }
Forbidden combination
When a depot-vehicle combination is forbidden, a depot with the specified depot category is not allowed to be visited by a vehicle with the specified vehicle category.
Example
If you have a relatively small depot, it might not be accessible by large vehicles.
"constraints":{ "combinations":{ "depotVehicle":[ { "type":"FORBIDDEN_COMBINATION", "depotCategory":"SMALL_DEPOT", "vehicleCategory":"LARGE_VEHICLE" } ] } }
Order constraints
Order constraints are rules that govern how orders can be arranged or scheduled within a route, ensuring specific conditions are met before certain orders are picked up or delivered. They regulate the sequence and arrangement of orders to ensure efficient and compliant route planning. If a vehicle category is specified, the constraint can be aimed to apply only to particular vehicles.
Respected order sequences
Respected order sequences require that one order be completed before another begins. When referring to executing an order, this involves both the pickup and the delivery task. This constraint ensures a specific sequence in which orders are handled, establishing that certain orders must follow the completion of another order.
Example
Say you transport both food and garbage. Since food can be contaminated by garbage, food should be delivered before any garbage may be handled. This constraint should only be applied to vehicles with a single compartment.
"constraints": { "orders": { "respectedSequences": [ { "orderCategories": [ "FOOD", "GARBAGE" ], "vehicleCategory": "SINGLE_COMPARTMENT" } ] } }
Loading incompatibilities
Loading incompatibility constraints dictate when certain orders can be picked up or delivered, considering whether another order of a specific category is already in the vehicle. These rules prevent handling certain tasks if the vehicle already contains orders that fit a particular category, ensuring that such orders are not picked up or delivered together.
Example
If you transport both small and big boxes, it's efficient to stack and arrange small boxes once big boxes are present, optimizing the remaining space. Loading the small boxes initially might lead to difficulties in organizing the vehicle and should therefore be avoided. In this example, we apply this constraint to all vehicles.
"constraints": { "orders": { "loadingIncompatibilities": [ { "loadedOrderCategory": "SMALL_BOX", "forbiddenOrderCategory": "BIG_BOX" } ] } }
Note the asymmetric nature of the constraint above. While it is not allowed the pickup or deliver big boxes while your vehicle contains small boxes, the reverse is permissible – you can pick up or deliver small boxes even if your vehicle already contains big boxes. If you don’t want certain order types to be mixed, this can be enforced with two loading incompatibilities.
Example
If you don’t want to transport explosive materials in combination with inflammables.
"constraints": { "orders": { "loadingIncompatibilities": [ { "loadedOrderCategory": "EXPLOSIVE", "forbiddenOrderCategory": "INFLAMMABLE" }, { "loadedOrderCategory": "INFLAMMABLE", "forbiddenOrderCategory": "EXPLOSIVE" } ] } }
Task constraints
Task constraints define limitations on how tasks can be scheduled within a route, dictating specific rules that tasks must follow. For instance, these constraints might prevent the scheduling of a particular task before another task, or they might require tasks of certain categories to be scheduled in a predetermined order. Essentially, task constraints regulate the sequencing and arrangement of tasks within a route, ensuring that specific rules or conditions are adhered to during the scheduling process. If a vehicle category is specified, the constraint can be aimed to apply only to particular vehicles.
Task groups
Task groups define a constraint between tasks that belong to a certain category. There are two types of task group constraints:
CONSECUTIVE
: Tasks belonging to the specified category must be scheduled consecutively without interruption by tasks not belonging to the category.SAME_ROUTE
: Tasks belonging to the given category should be assigned to the same route.
When a group of tasks must be scheduled consecutively on the same route, both types of constraints must be defined for this category.
Example 1: CONSECUTIVE
If you are based in Germany and have to deliver orders in France, you may desire not to cross the border more than twice in a route. This can be achieved by enforcing that tasks in France should all be scheduled consecutively within the same route. By specifying the constraint below, tasks in France will not be interrupted by those in Germany. Note that this does not mean that all France orders should be scheduled on the same route.
"constraints": { "tasks": { "groups": [ { "taskCategory": "FRANCE" "constraint": "CONSECUTIVE" } ] } }
Example 2: SAME_ROUTE
When boxes of bananas arrive at the depot on a single pallet, you might want to keep the pallet intact by avoiding the distribution of orders among different drivers.
"constraints": { "tasks": { "groups": [ { "taskCategory": "BANANAS" "constraint": "SAME_ROUTE" } ] } }
Respected task sequences
Respected task sequences require tasks belonging to specific categories to follow a predefined order when scheduled. This constraint ensures that tasks of certain categories are arranged in a particular sequence, dictating the order in which they are planned within a route.
Example
If you have delivery orders in Germany and France and desire not to cross the border too often. You might want to enforce that all deliveries in Germany are handled before the deliveries in France. This constraint should be applied to all vehicles, and therefore the vehicle category is not filled in.
"constraints": { "tasks": { "respectedSequences": [ { "taskCategories": [ "GERMANY", "FRANCE" ] } ] } }
Forbidden task sequences
Forbidden task sequences impose restrictions on the scheduling of tasks by dictating that tasks of a particular category cannot be scheduled before tasks of another category, either directly before or anywhere before in the route. This ensures a specific order or arrangement of tasks, preventing certain combinations from occurring within the route.
Example
When you transport both parcels and letters, for example, and certain customers have a premium delivery agreement for parcels, their parcels should be delivered first. This is an example where a forbidden task sequence can be used.
"constraints": { "tasks": { "forbiddenSequences": [ { "firstTaskCategory": "STANDARD_DELIVERY", "type": "NOT_BEFORE", "secondTaskCategory": "PREMIUM_DELIVERY", "vehicleCategory": "PARCEL_DELIVERY_VAN" } ] } }
Rules
Rules provide flexibility by allowing adjustments to properties such as preparation durations at locations, which can vary based on the vehicle assigned to the stop or the preceding location. Each rule consists of conditions and associated changes that can be applied to various properties of the routes. During optimization, rules are evaluated individually and once at least one of the rule's conditions is met, its changes are applied. A condition itself is defined by multiple properties, all of which must simultaneously match for the condition to be considered satisfied. This allows for flexible adjustments to properties like preparation durations based on factors such as the vehicle assigned to the stop or the kind of preceding location, ensuring the solution meets the specified operational requirements.
Location rules
Location preparation duration rules enable adjustments to the preparation time applied when a stop is scheduled on a route. The conditions for these rules can reference the previous location, the vehicle assigned to the stop, and the stop itself.
An important remark about preparation duration rules is that there are two ways to adjust the duration, either using a factor or an extra duration. When both are provided the factor is always applied to the location's regular preparation duration before extra time is added. When multiple rules are applied to a stop, all factors are applied before the sum of all extra durations is added.
Example 1: Reorganizing the truck
If you have both pickup and delivery orders, it may be useful to account for a bit more time at a stop of a delivery task when preceded by a pickup. This extra time can be used to reorganize the truck and move the picked up goods out of the way and make room to unload the delivery order.
"rules": { "locations": [ "conditions": [ { "locationCategory": "DELIVERY_LOCATION", "previousLocationCategory": "PICKUP_LOCATION" } ], "preparationDuration": { "extra": 600 } ] }
Example 2: Large trucks
Certain locations might have a narrow entrance, which requires large trucks to unload further from the drop-off point and deliver the goods using a pallet jack.
"rules": { "locations": [ "conditions": [ { "locationCategory": "NARROW_ENTRANCE", "vehicleCategory": "LARGE_TRUCK" } ], "preparationDuration": { "extra": 1800 } ] }
Example 3: A snowy day
After a snowy day, daily operations might be a bit chaotic. To incorporate this in the transport plan, aside from applying a speed factor, we could also increase the location preparation duration of all customer locations by 50%.
"rules": { "locations": [ "conditions": [ { "locationCategory": "CUSTOMER_LOCATION" } ], "preparationDuration": { "factor": 1.5 } ] }