Skip to content

Order picking (C++)

The C++ lives in optimaru/order_picking/cpp/; the paths below are relative to it, and its C++ tests are in tests/order_picking/cpp/.

Derived from the Timefold Quickstarts order-picking example (Apache-2.0; see the repository NOTICE). Only the domain and constraints are implemented here, on top of the generic engine (core/optimaru, header-only).

  • op/model/domain.hpp — the warehouse layout (Warehouse, the solution's warehouse: a grid of shelvings, by default 5 shelf columns x 3 rows, left/right sides, rows 0-10; or named locations with a DistanceTable), calculateDistance(warehouse, start, end) (two arguments: the default grid), domain structs, the sequence-shape SolutionTraits specialization (the trolley's pickTaskIndices is the decision: the ordered list of pick tasks it visits).
  • op/model/layout.hpp — makeGridWarehouse and makeNamedWarehouse (a layout with its numbers checked), checkLocation / checkLayout (a location, or every location of a solution, inside the warehouse; a named location is an index, and carries the tag of its warehouse when it was made with one: WarehouseLocation::named(index, &warehouse)) and ActiveDistances, the table of location-to-location distances a solve reads instead of computing (Warehouse::active; both kinds of layout, a grid up to 2048 distinct locations in use; parallel starts share one).
  • op/score/score_calculator.hpp — full recompute + derived values (trolleyIndex/previousPickTask/nextPickTask) recalculation + per-constraint totals (ConstraintTotals, members named after the registry names, at the components' kDefaultWeight).
  • op/constraints/ — one component per constraint: trolley_capacity_cost.hpp (TrolleyCapacityCost, hard 1), distance_from_previous_pick_task_cost.hpp (DistanceFromPreviousPickTaskCost, soft 1), distance_from_last_pick_task_to_path_origin_cost.hpp (DistanceFromLastPickTaskToPathOriginCost, soft 1), order_split_by_trolley_cost.hpp (OrderSplitByTrolleyCost, soft 1000) (+ common.hpp); op/constraints.hpp assembles the default set (defaultConstraints(), also the constraint_info() catalog).
  • op/score/incremental_calculator.hpp — before/after_list_edit hooks for per-trolley O(list) incremental scoring (checked against full recompute under ScoreChecks::Full).
  • op/solver.hpp — engine wrapper (sequence move mix + ALNS + warehouse-distance nearby).
  • op/model/demo_data.cpp — the demo warehouse, drawn from a seeded std::mt19937_64 (seed 37): 37-product catalog, 8 orders, 5 trolleys x 4 buckets x 48000 cm3).

Build / run

cmake -B build -DCMAKE_BUILD_TYPE=Release -DOPTIMARU_USE_CASES=order_picking
cmake --build build -j4
./build/order_picking/op_test         # per-constraint hand checks + incremental==full + ScoreChecks::Full solve + layouts
./build/order_picking/op_plugin_test  # plugin assembly == monolith, raw costs by hand, catalog, overrides
./build/order_picking/op_demo         # 10 s solve of the demo warehouse, reaches feasible (hard 0)