Skip to main content
Each business rule of a plan has its own guide. Start with the one that matches your rule:
  • Time windows explains what a window limits. It also covers preferred windows, several windows per stop, and windows reserved for some resources.
  • Breaks describes the three kinds of break and where the engine can place one. It also points to the multi-day guide for a night rest.
  • Skills and assignments shows how to reserve an order for qualified resources, prefer one resource, or bar one resource from a stop.
  • Capacities sets ceilings per vehicle and describes compartments. It also covers pickups after deliveries, tolerated overload, visit caps and last-in-first-out unloading.
  • Orders and sequences covers the stops of one order, optional orders, and stops back to back. It also covers one site among several, and stops kept on one vehicle in any order.
  • Resource limits sets the working hours, working time, and distance of a resource. It also caps the longest drive between two stops.
  • Multi-day trips explains one rest per night and where each rest falls. It also shows how to write the times in one time zone.
The sections below keep the old headings of this page. Each one gives a summary and a link to the guide that covers the rule. For the general distinction between hard and soft rules, see Hard vs soft constraints.

Heterogeneous capacities per vehicle

A resource’s capacities is a ceiling on its running load. The ceiling covers all the orders of the resource together, so two vehicles of different sizes can each take the stops that fit them. See Capacities of vehicles and stops for the rule, what happens with two vehicle sizes, and the keys a vehicle doesn’t declare.

Multi-compartment vehicles

A vehicle with a compartment that you set up before departure, such as a reefer split between chilled and frozen, keeps one setup for the whole tour. You list each possible setup and combine them with atLeastOneConstraint. See Compartments set up before departure for the construction and how to read the setup the engine chose.

Sequencing pickups after deliveries

atLeastOneValidCapacity is checked at every stop, so it can express a sequencing rule. With two counting capacities, it keeps the vehicle from picking up goods while deliveries remain. See Pickups after deliveries for the counters, the threshold, and a whole-plan example.

Tolerated capacity overflow

A hard capacities ceiling drops a stop that doesn’t fit. A costsByCapacity entry lets the plan exceed the load you normally plan for, at a price, up to that ceiling. See Tolerated overload for the cost figures and the delivery-only limit.

Creative capacity modeling patterns

A capacity doesn’t have to measure a physical load. A synthetic capacity that each relevant stop increments caps the number of visits in a tour. See Counting visits with a capacity for the cap and for two keys on the same stops.

Soft version of the visit cap

A cost can replace the capacity, so that a fourth visit is allowed at a price. You tag the stops and add a costsByStopTag entry that charges past a free allowance. See Soft version for the cost entry and how to combine it with the hard cap.

LIFO unloading order for stacked cargo

A removalStrategy constraint with strategy: "lifo" makes a vehicle unload the goods it loaded last. It suits a car carrier or a multi-deck cage truck. See Last in, first out for the rule, the vehicle tags, and the cost of applying it to a whole fleet.

Driver skills and qualifications

requiredSkills on an order and skills on a resource are the hard match: a resource can serve an order only if it has every skill the order requires. When the match should be a preference instead, tag the stop and use preferredStopTags on the resource. See Skills and assignments for how skills match, how to prefer instead of require, and the other ways to control who serves a stop.

Mandatory breaks

A resource’s breaks array accepts three break types: timeWindowBreak, workingDurationSlidingBreak and travelDurationSlidingBreak. You can combine them to model a realistic shift. See Three kinds of break for what triggers each type, how to combine them, and which figures you can default.

Where a break can fall

The engine schedules a break only where the vehicle already stands. A timeWindowBreak can fall at the start of its tour or at a stop. A sliding break falls only after a stop. The engine never schedules a break in the middle of a drive. What happens to a long drive depends on the break type. See Where a break can fall for the rule of each type, including the catch-up of a sliding break, an example, and how to give the route a stop for the break.

Modeling multi-day sleepovers

A workingTimeWindow that spans more than one calendar day doesn’t force any rest between working days. You need to encode the rest in breaks. See Multi-day trips for one rest per night, the working limits, and time zones.

Multiple time windows per stop

authorizedTimeWindows accepts an array, so a stop can have several hard windows, for example one in the morning and one in the late afternoon. The stop is feasible if the resource can start service in any one of them. See Several windows on one stop for the full explanation.

Restricting a window to specific resources

A window can carry resourceTags, so that it applies only to resources with a matching tag. A resource without the tag does not see that window. See Windows reserved for some resources for how the tags match and what happens when no window applies.

Optional steps that gate a mandatory stop

An AlternativesStop lets the engine pick one stop among several. No pattern is published yet for a step that the vehicle needs only when another condition holds. See One site among several for what an AlternativesStop does and for a working example.

Keeping stops on the same vehicle in any order

A maxCumulatedCost entry in globalConstraints can keep a set of tagged stops on one vehicle, while the vehicle picks the best order. See Same vehicle in any order for the pattern and a worked example.

See also

  • Hard vs soft constraints — the general hard/soft distinction referenced throughout this page.
  • Handling infeasibility — what happens when none of the preceding can be satisfied for a given stop.
  • Data model — an overview of capacities, skills, breaks, time windows, and stops, each linking to its schema in the API reference.