Skip to content
DuckDB community extension

anofox_optimize

Combinatorial decision algorithms as SQL — bin packing, knapsack, wave batching, sequencing, scheduling, assortment and portfolio selection

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL anofox_optimize FROM community;
LOAD anofox_optimize FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Cartons waiting to ship, and a container that holds 1000 units.

SQL
-- Cartons waiting to ship, and a container that holds 1000 units.
CREATE TABLE cartons AS SELECT * FROM VALUES
  (1, 420.0), (2, 380.0), (3, 260.0), (4, 240.0),
  (5, 190.0), (6, 180.0), (7, 150.0), (8, 130.0)
  AS t(carton_id, size);

-- How few containers hold everything? `best_of` runs every packing
-- algorithm in the family and returns whichever used the fewest bins.
SELECT opt_pack_best_of(list(size ORDER BY carton_id), 1000.0).bins_used AS containers
FROM cartons;

-- Which shipments go on a cheaper carrier that only takes 1000 units?
-- Value == weight, so this is subset-sum, and `exact` finds the perfect
-- fill that greedy rules miss.
SELECT opt_knapsack_exact(
         list(weight ORDER BY shipment_id),
         list(weight ORDER BY shipment_id),
         1000.0
       ).total_weight AS loaded_on_cheap_carrier
FROM (VALUES (1, 505.0), (2, 380.0), (3, 260.0), (4, 240.0), (5, 115.0))
     AS s(shipment_id, weight);

Provided by DataZooDE. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

anofox_optimize puts combinatorial decision algorithms behind DuckDB functions. Pack containers, choose an assortment, sequence a machine, allocate a portfolio — in SQL, against the tables the data already lives in. No solver process, no external service, no modelling language.

Every member of a family takes identical arguments, so swapping one identifier swaps the algorithm and nothing else:

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
DataZooDE/anofox-optimize
License
BSL 1.1
Maintainers
jrosskopf
Written in
C++
Build source
fc7bbd2205bb
Build definition
Community descriptor