● How to use · Routing & Logistics
Order picking
Batch pick tasks onto trolleys and sequence them through the aisles so pickers walk less and trolleys stay within volume.
What it decides
For every item of every order, the solver picks a trolley and a position in that trolley's walking sequence.
Minimal example
from optimaru.order_picking.models import (
LocationModel, OrderModel, OrderPickingRequest, ProductModel, TrolleyModel, solve_request,
)
def shelf(column, shelving_row, side, row):
return LocationModel(column=column, shelving_row=shelving_row, side=side, row=row)
request = OrderPickingRequest(
timelimit=2,
random_seed=42,
trolleys=[
TrolleyModel(id="T1", bucket_count=2, bucket_capacity=48000, location=shelf("A", 1, "LEFT", 0)),
],
orders=[
OrderModel(id="O1", items=[
ProductModel(id="milk", volume=1232, location=shelf("D", 1, "RIGHT", 4)),
ProductModel(id="rice", volume=9000, location=shelf("B", 2, "LEFT", 7)),
]),
OrderModel(id="O2", items=[
ProductModel(id="soap", volume=800, location=shelf("B", 2, "RIGHT", 3)),
]),
],
)
solution = solve_request(request)
print(solution.feasible, solution.score, solution.total_distance)
for trolley_id, stops in solution.routes.items():
print(trolley_id, [stop.pick_task_id for stop in stops])
print(solution.unassigned, solution.order_split_count) The same use case as a Jupyter notebook, with charts and saved outputs: examples/order-picking.ipynb ↗
Input parameters
LocationModel
| Field | Meaning |
|---|
column required A to E.shelving_ row required side required LEFT or RIGHT.row required ProductModel
| Field | Meaning |
|---|
id required volume required location required OrderModel
| Field | Meaning |
|---|
id required items required TrolleyModel
| Field | Meaning |
|---|
id required bucket_ count required bucket_ capacity required location required initial_ route OrderPickingRequest
| Field | Meaning |
|---|
trolleys required orders required Solve parameters
What you pass to the solve call. Time limit, seed and parallel count are here.
| Parameter | Default | Meaning |
|---|---|---|
name | None | Optional label for the request. |
timelimit | 30.0 | Search budget in seconds, from 0 to 1e9. |
random_ | 0 | Seed for the search. |
num_ | 1 | Independent parallel starts. The best result wins. |
stop_ | False | Stop as soon as hard 0 is reached. |
solver_ | {} | SolverConfig fields by name, as a dict. It cannot set the time limit, seed, worker count or on_new_best. |
constraints | None | Which constraints to score, and how. Left unset, the defaults apply. |
All search options (27)
Pass these by name in solver_parameters.
| Parameter | Default | Meaning |
|---|---|---|
best_ | — | Stop early once the best score reaches this value. By default it never fires. |
distance_ | True | Draw move partners from the physically closest picks. |
distance_ | 0.5 | Probability of doing so. |
distance_ | 24 | Neighbours kept per pick. |
full_ | False | Check every incremental score against a full recompute. Slow; for debugging. |
late_ | 0 | Late-acceptance history length. 0 picks it from the instance size. |
list_ | 0.25 | Relative share of list swap moves. 0 disables them. |
on_ | None | Callback run on each new best solution. If it raises, the solve stops and raises the same exception. |
or_ | 0.1 | Relative share of Or-opt moves, which relocate a short segment. 0 disables them. |
order_ | True | Enable moves that gather a split order onto one trolley. |
parallel_ | 1 | Independent parallel starts, each with its own seed and the full budget. The best one wins. |
random_ | 0 | Seed for the search. |
relocate_ | 0.4 | Relative share of relocate moves. 0 disables them. |
ruin_ | True | Run adaptive ruin-and-recreate kicks when the search stagnates. |
ruin_ | 60 | Absolute cap on entities removed per kick. |
ruin_ | 0.3 | Largest share of the solution one kick removes. |
ruin_ | 0.1 | Smallest share of the solution one kick removes. |
ruin_ | 0.8 | How fast operator weights adapt. |
ruin_ | 5000 | Hill-climbing moves that polish each kick. Not counted against step_count_limit. |
ruin_ | [33.0, 9.0, 3.0, 0.0] | Operator rewards for a new best, a better, an accepted and a rejected result. |
ruin_ | 50000 | Steps without a new best before a kick. |
spent_ | 30.0 | Time budget in seconds, from 0 to 1e9. |
step_ | 0 | Stop after this many steps. 0 means no limit. |
tail_ | 0.1 | Relative share of tail swaps (2-opt*) between two lists. 0 disables them. |
two_ | 0.15 | Relative share of 2-opt moves. 0 disables them. |
unimproved_ | 0.0 | Stop after this many seconds without a new best. 0 means no limit. |
unimproved_ | 0 | Stop after this many steps without a new best. 0 means no limit. |
What comes back
solve_request returns an OrderPickingResponse. The decisions are in routes.
OrderPickingResponse
| Field | Meaning |
|---|
routes required pick_task_id, order_id, product_name, volume and location.unassigned distance_ by_ trolley required total_ distance required order_ split_ count required score required feasible required Constraints
Pick them by calling their classes from optimaru.order_picking.constraints, such as TrolleyCapacityCost(). Only what you pass is scored; pass nothing to keep the defaults. A list may name a constraint more than once, and each pick is scored on its own. Each one takes these parameters:
| Parameter | Default | Meaning |
|---|---|---|
weight | None | Multiplier on the constraint's cost, in units of the level in effect. Left unset, the default weight below applies. A constraint whose default weight is 0 is off until you give it a weight. |
level | None | "hard" makes the constraint a must and "soft" a preference, as do Level.HARD and Level.SOFT. Left unset, it keeps the level below. This use case has no medium level, so "medium" raises ValueError. A reward refuses "hard", and a fixed level refuses any change; both raise ValueError. |
exponent | 1.0 | Sign-preserving power on the cost, above 0, taken after offset. 2.0 squares it, so concentrated violations cost much more. It applies per unit, such as a vehicle or a day, or to the total of a constraint scored as one sum. |
offset | 0.0 | Subtracted from the cost x before the exponent, per unit or total like the exponent. It is in the cost's own measure: seconds, minutes, a count and so on. Any finite number of either sign, keyword only. clip decides what happens below it. |
clip | True | True makes offset a threshold: only the part beyond it counts, max(0, x - offset) ** exponent, so a cost at or below it adds nothing. False takes the literal (x - offset) ** exponent, sign kept: a unit below the offset counts negative, as a reward, even one whose cost is 0. On a level that counts toward hard, clip=False with a non-zero offset raises ValueError, since hard 0 must mean no violation. Keyword only. |
This continues the minimal example above.
from optimaru.order_picking.constraints import (
DistanceFromPreviousPickTaskCost, OrderSplitByTrolleyCost, TrolleyCapacityCost,
get_constraints,
)
picked = get_constraints([
TrolleyCapacityCost(),
DistanceFromPreviousPickTaskCost(),
OrderSplitByTrolleyCost(weight=5000),
])
print(solve_request(request, constraints=picked).score) | Name | Level | Default weight | What it does |
|---|---|---|---|
trolley_ | Hard | 1 | Buckets a trolley is short of. Orders never share a bucket, so each order rounds up on its own. |
distance_ | Soft | 1 | Distance from each pick to the next. For the first pick, the trolley's start stands in. |
distance_ | Soft | 1 | Distance from the last pick back to the start. An empty trolley costs nothing. |
order_ | Soft | 1000 | Number of (order, trolley) pairs, so an order on three trolleys costs three times one on a single trolley. |
Starting from an existing solution
This needs the latest release: pip install -U optimaru.
with_initial_solution(request, solution) returns a new request whose trolleys carry initial_route, a list of pick task ids.
This continues the minimal example above.
from optimaru.order_picking.models import with_initial_solution
seeded = with_initial_solution(request, solution) # or solution.model_dump(mode="json")
better = solve_request(seeded)
print(better.score, better.total_distance) - A complete solution skips construction: the search starts exactly from it. A partial one keeps what it gives, and only the pick tasks it leaves out are constructed.
- With
timelimit=0the solve stops at once, so a complete solution comes back as it went in. Use the time limit for this:step_count_limit = 0means no limit. - An unknown id or a task routed twice raises
ValueError. - A pick task id is
<order id>-<item position>, so keep each order'sitemsin the order they were solved in. Moved, the same id names a different item.
Exceptions and limits
- The warehouse is a fixed grid: columns A to E, shelving rows 1 to 3, two sides, and rows 0 to 10 in a shelving.
- Orders never share a bucket. A trolley needs the sum, over its orders, of each order's volume divided by
bucket_capacity, rounded up.