OR-Tools
Optimisation with Google OR-Tools β routing, scheduling, assignment, flows and bin-packing
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available Β· $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/ortools/index.md to help me query OR-Tools with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Assign tasks at the lowest cost
Example output Β· captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker
| worker | task | cost |
|---|---|---|
| 0 | 1 | 76 |
| 1 | 0 | 35 |
| 2 | 2 | 90 |
Quick start
Choose where to run OR-Tools, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'ortools' AS ortools (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-ortools'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'ortools' AS ortools (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-ortools:0.5.0'
);
3. Run a query
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connectorβs deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'ortools' AS ortools
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker
Query Farm operates OR-Tools for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use ortools as the catalog alias for the query below.
4. Run a query
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until youβre ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'ortools' AS ortools (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-ortools'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'ortools' AS ortools (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-ortools:0.5.0'
);
Overview
Google OR-Tools optimization / constraint solving as SQL functions.
Prescriptive compute inside DuckDB: constraint programming, vehicle routing, scheduling, assignment, network flow, and packing as plain SQL functions.
This catalog turns Google OR-Tools into DuckDB table and scalar functions, so an operations, logistics, or planning team that already lives in DuckDB can solve optimization problems next to their data instead of standing up a separate Python optimization microservice with its own deploy, data copy, and ETL round-trip.
When to reach for it
Use it when a question is a decision problem rather than an aggregation -- matching supply to demand at least cost, sequencing work under precedence and resource limits, routing a fleet under capacity and time windows, maximizing the throughput of a network, or any hand-built constraint model mixing the global constraints (all-different, no-overlap, cumulative, circuit) that LP/MIP solvers such as the community highs extension stop short of. It is the decision-making complement to the predictive ML workers.
How it works
Build the cost, distance, demand, or capacity matrices using ordinary SQL joins and array_agg, hand them to a solver as integer list arguments (OR-Tools is an integer engine -- scale fractional data first), and get the optimal or best-found solution back as rows you can join straight back into the warehouse. Every solver returns a status column, and a problem with no solution returns exactly one status row rather than an empty result.
Data residency
The worker makes no outbound network calls -- pure local CPU, no API keys, no rate limits, no data egress. Your problem instances never leave the box. OR-Tools is Apache-2.0; the worker is MIT.
Catalog
Everything ortools exposes once attached β read straight from the worker's
released build.
main 2 tables Β· 12 functions
OR-Tools solvers: CP-SAT, routing, assignment, scheduling, flow, packing.
Schema examples (5)
Least-cost assignment of three workers to three tasks (returns each worker's chosen task and its cost).
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker;
| worker | task | cost |
|---|---|---|
| 0 | 1 | 76 |
| 1 | 0 | 35 |
| 2 | 2 | 90 |
Optimal travelling-salesperson tour over a 5-node distance matrix, in visit order.
SELECT seq, node, arrival
FROM ortools.main.solve_tsp(distance := [[0,2,9,10,1],[1,0,6,4,8],[15,7,0,8,3],[6,3,12,0,5],[9,8,4,7,0]]::BIGINT[][], start := 0)
ORDER BY seq;
List the bundled OR-Tools / solver component versions.
SELECT component, version FROM ortools.main.solver_info ORDER BY component;
Arc criticality: for each arc carrying flow in the 0->3 max-flow solution, re-solve with that arc removed (max_flow_value) and report the throughput lost. Losing arc 2->3 drops the max flow from 30 to 10; each of the other flow-carrying arcs costs 10.
SELECT f."from", f."to", f.flow,
ortools.main.max_flow_value(list_filter([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], lambda a: NOT (a[1] = f."from" AND a[2] = f."to")), 0, 3) AS flow_without_arc,
ortools.main.max_flow_value([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], 0, 3) - flow_without_arc AS flow_lost
FROM ortools.main.max_flow(arcs := [[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], source := 0, sink := 3) AS f
ORDER BY flow_lost DESC, f."from", f."to";
1 more example
Ship 12 units from node 0 to node 3 at minimum cost (68), and compare against the network's maximum 0->3 throughput from max_flow_value over the same arcs' capacities (17), leaving 5 units of headroom.
SELECT sum(flow) FILTER (WHERE "from" = 0) AS shipped,
sum(cost) AS total_cost,
ortools.main.max_flow_value(list_transform([[0,1,10,2],[0,2,8,5],[1,2,6,1],[1,3,5,4],[2,3,12,2]]::BIGINT[][], lambda a: a[1:3]), 0, 3) AS max_shippable,
max_shippable - shipped AS headroom
FROM ortools.main.min_cost_flow(arcs := [[0,1,10,2],[0,2,8,5],[1,2,6,1],[1,3,5,4],[2,3,12,2]]::BIGINT[][], supplies := [[0,12],[3,-12]]::BIGINT[][])
ORDER BY total_cost;
last_solve_stats
Statistics of the most recent solve on this worker process, one row per metric (NULL values until the first solve).
Read every metric of the most recent solve on this worker.
SELECT metric, value FROM ortools.main.last_solve_stats ORDER BY metric;
Fetch just the status of the most recent solve.
SELECT value FROM ortools.main.last_solve_stats WHERE metric = 'status';
solver_info
Bundled OR-Tools / worker / dialect versions, one row per component (no arguments).
List every bundled component and its version.
SELECT component, version FROM ortools.main.solver_info ORDER BY component;
Fetch just the OR-Tools engine version.
SELECT version FROM ortools.main.solver_info WHERE component = 'ortools';
max_flow_value (arcs BIGINT[][], source BIGINT, sink BIGINT)
The scalar maximum-flow value from source to sink over a capacitated network (arcs as a [[from, to, capacity], ...] LIST). Backed by OR-Tools SimpleMaxFlow.
Max-flow value from node 0 to node 3 (= 30).
SELECT ortools.main.max_flow_value([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], 0, 3);
max_flow (arcs := BIGINT[][], sink := BIGINT, source := BIGINT)
Maximum flow from a source to a sink over a capacitated network. Backed by OR-Tools SimpleMaxFlow. Returns one row per arc with positive flow; see max_flow_value for the scalar total.
Max flow from node 0 to node 3 (value 30).
SELECT sum(flow) FILTER (WHERE "from" = 0) AS out_of_source
FROM ortools.main.max_flow(arcs := [[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], source := 0, sink := 3);
Arc criticality: for each arc carrying flow in the 0->3 max-flow solution, re-solve with that arc removed (max_flow_value) and report the throughput lost. Losing arc 2->3 drops the max flow from 30 to 10; each of the other flow-carrying arcs costs 10.
SELECT f."from", f."to", f.flow,
ortools.main.max_flow_value(list_filter([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], lambda a: NOT (a[1] = f."from" AND a[2] = f."to")), 0, 3) AS flow_without_arc,
ortools.main.max_flow_value([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], 0, 3) - flow_without_arc AS flow_lost
FROM ortools.main.max_flow(arcs := [[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], source := 0, sink := 3) AS f
ORDER BY flow_lost DESC, f."from", f."to";
min_cost_flow (arcs := BIGINT[][], supplies := BIGINT[][])
Minimum-cost flow: route supply to demand over a capacitated, costed network at minimum total cost. Backed by OR-Tools SimpleMinCostFlow. Returns one row per arc with positive flow.
Min-cost flow of 20 units out of node 0 to sinks 3 (5 units) and 4 (15 units) -- the canonical OR-Tools instance, optimal total cost 150.
SELECT "from", "to", flow, cost
FROM ortools.main.min_cost_flow(arcs := [[0,1,15,4],[0,2,8,4],[1,2,20,2],[1,3,4,2],[1,4,10,6],[2,3,15,1],[2,4,4,3],[3,4,20,2],[4,2,5,3]]::BIGINT[][], supplies := [[0,20],[3,-5],[4,-15]]::BIGINT[][])
ORDER BY "from", "to";
Ship 12 units from node 0 to node 3 at minimum cost (68), and compare against the network's maximum 0->3 throughput from max_flow_value over the same arcs' capacities (17), leaving 5 units of headroom.
SELECT sum(flow) FILTER (WHERE "from" = 0) AS shipped,
sum(cost) AS total_cost,
ortools.main.max_flow_value(list_transform([[0,1,10,2],[0,2,8,5],[1,2,6,1],[1,3,5,4],[2,3,12,2]]::BIGINT[][], lambda a: a[1:3]), 0, 3) AS max_shippable,
max_shippable - shipped AS headroom
FROM ortools.main.min_cost_flow(arcs := [[0,1,10,2],[0,2,8,5],[1,2,6,1],[1,3,5,4],[2,3,12,2]]::BIGINT[][], supplies := [[0,12],[3,-12]]::BIGINT[][])
ORDER BY total_cost;
solve_assignment (cost := BIGINT[][], maximize := BOOLEAN)
Linear sum assignment: match workers to tasks over sparse [worker, task, cost] arcs, minimizing (or maximizing) total cost. Backed by OR-Tools SimpleLinearSumAssignment.
Assign 3 workers to 3 tasks minimizing total cost (unique optimum 0->1, 1->0, 2->2).
SELECT worker, task, cost
FROM ortools.main.solve_assignment(cost := [[0,0,90],[0,1,76],[0,2,75],[1,0,35],[1,1,85],[1,2,55],[2,0,125],[2,1,95],[2,2,90]]::BIGINT[][], maximize := false)
ORDER BY worker;
| worker | task | cost |
|---|---|---|
| 0 | 1 | 76 |
| 1 | 0 | 35 |
| 2 | 2 | 90 |
Maximize total value instead of minimizing cost.
SELECT worker, task, cost, status
FROM ortools.main.solve_assignment(cost := [[0,0,8],[0,1,7],[1,0,6],[1,1,9]]::BIGINT[][], maximize := true)
ORDER BY worker;
solve_bin_packing (bin_capacity := BIGINT, random_seed := BIGINT, sizes := BIGINT[], time_limit_s := DOUBLE)
1-D bin packing: assign items to the fewest identical fixed-capacity bins. CP-SAT model minimizing the number of open bins. Returns the item -> bin assignment.
Pack six items into the fewest bins of capacity 10 (optimum 3 bins).
SELECT count(DISTINCT bin) AS bins
FROM ortools.main.solve_bin_packing(sizes := [3,5,2,7,1,4]::BIGINT[], bin_capacity := 10, time_limit_s := 5.0);
solve_bin_packing_bins (bin_capacity := BIGINT, random_seed := BIGINT, sizes := BIGINT[], time_limit_s := DOUBLE)
Per-bin rollup of the bin-packing solution: one row per open bin with the count of items it holds. Same inputs as solve_bin_packing.
Per-bin item counts for a six-item pack into capacity-10 bins.
SELECT bin, used
FROM ortools.main.solve_bin_packing_bins(sizes := [3,5,2,7,1,4]::BIGINT[], bin_capacity := 10)
ORDER BY bin;
solve_cpsat (enumerate_all := BOOLEAN, model := VARCHAR, num_workers := BIGINT, project := VARCHAR, random_seed := BIGINT, time_limit_s := DOUBLE)
Solve an arbitrary CP-SAT constraint-programming model expressed as a versioned JSON document (variables, constraints, objective). Returns one row per variable plus solve metadata. The general escape hatch for constraints highs/LP cannot express.
0/1 knapsack as a CP-SAT model: maximize value within a weight budget (optimum 40).
SELECT var, value, status, objective
FROM ortools.main.solve_cpsat(model := '{"version":1,"variables":[{"kind":"bool","name":"a"},{"kind":"bool","name":"b"},{"kind":"bool","name":"c"}],"constraints":[{"type":"linear","expr":{"sum":[{"coef":5,"var":"a"},{"coef":10,"var":"b"},{"coef":15,"var":"c"}]},"op":"<=","rhs":20}],"objective":{"sense":"maximize","terms":[{"coef":10,"var":"a"},{"coef":20,"var":"b"},{"coef":30,"var":"c"}]}}')
ORDER BY var;
Single-machine no-overlap schedule minimizing makespan (optimum 10).
SELECT objective, status
FROM ortools.main.solve_cpsat(model := '{"version":1,"variables":[{"kind":"int","name":"s0","lb":0,"ub":20},{"kind":"int","name":"e0","lb":0,"ub":20},{"kind":"int","name":"s1","lb":0,"ub":20},{"kind":"int","name":"e1","lb":0,"ub":20},{"kind":"int","name":"s2","lb":0,"ub":20},{"kind":"int","name":"e2","lb":0,"ub":20},{"kind":"interval","name":"i0","start":{"var":"s0"},"size":{"const":3},"end":{"var":"e0"}},{"kind":"interval","name":"i1","start":{"var":"s1"},"size":{"const":5},"end":{"var":"e1"}},{"kind":"interval","name":"i2","start":{"var":"s2"},"size":{"const":2},"end":{"var":"e2"}},{"kind":"int","name":"makespan","lb":0,"ub":20}],"constraints":[{"type":"no_overlap","intervals":["i0","i1","i2"]},{"type":"max_equality","target":{"var":"makespan"},"exprs":[{"var":"e0"},{"var":"e1"},{"var":"e2"}]}],"objective":{"sense":"minimize","terms":[{"coef":1,"var":"makespan"}]}}', time_limit_s := 5.0)
LIMIT 1;
solve_jobshop (horizon := BIGINT, random_seed := BIGINT, tasks := BIGINT[][], time_limit_s := DOUBLE)
Job-shop scheduling: schedule the tasks of several jobs on shared machines (tasks of a job run in order, one task per machine at a time) to minimize the makespan. CP-SAT.
Two-job, two-machine job shop minimizing makespan (optimum 7).
SELECT job, task, machine, start, "end", makespan
FROM ortools.main.solve_jobshop(tasks := [[0,0,0,3],[0,1,1,2],[1,0,1,2],[1,1,0,4]]::BIGINT[][], time_limit_s := 5.0)
ORDER BY job, task;
solve_knapsack (capacities := BIGINT[], item_values := BIGINT[], weights := BIGINT[][])
Multi-dimensional 0/1 knapsack: choose items to maximize total value subject to one or more capacity dimensions. Backed by OR-Tools KnapsackSolver (branch and bound).
Single-dimension 0/1 knapsack: pick items maximizing value within capacity 40 (optimum 80).
SELECT item, chosen
FROM ortools.main.solve_knapsack(item_values := [10,20,30,40,50]::BIGINT[], weights := [[5],[10],[15],[20],[25]]::BIGINT[][], capacities := [40]::BIGINT[])
ORDER BY item;
Two-dimensional knapsack: each item has a weight and a volume, packed under both a weight budget (50) and a volume budget (5) at once -- one `weights` column per dimension.
SELECT item, chosen, status
FROM ortools.main.solve_knapsack(item_values := [60,100,120]::BIGINT[], weights := [[10,2],[20,3],[30,4]]::BIGINT[][], capacities := [50,5]::BIGINT[])
ORDER BY item;
solve_rcpsp (precedences := BIGINT[][], random_seed := BIGINT, resources := BIGINT[][], tasks := BIGINT[][], time_limit_s := DOUBLE)
Resource-constrained project scheduling (RCPSP): schedule tasks with durations, precedences, and per-resource capacity (renewable) to minimize makespan. CP-SAT cumulative.
Four-task project, one resource of capacity 2, with two precedences.
SELECT task, start, "end", makespan, status
FROM ortools.main.solve_rcpsp(tasks := [[0,3,2],[1,2,1],[2,4,2],[3,2,1]]::BIGINT[][], precedences := [[0,2],[1,3]]::BIGINT[][], resources := [[0,2]]::BIGINT[][], time_limit_s := 5.0)
ORDER BY task;
solve_tsp (distance := BIGINT[][], first_solution_strategy := VARCHAR, local_search_metaheuristic := VARCHAR, random_seed := BIGINT, start := BIGINT, time_limit_s := DOUBLE)
Travelling salesperson: shortest single-vehicle tour visiting every node once and returning to the start, over a distance matrix. OR-Tools routing library.
5-node TSP from a dense distance matrix; shortest tour length 17.
SELECT seq, node, arrival
FROM ortools.main.solve_tsp(distance := [[0,2,9,10,1],[1,0,6,4,8],[15,7,0,8,3],[6,3,12,0,5],[9,8,4,7,0]]::BIGINT[][], start := 0, time_limit_s := 1.0)
ORDER BY seq;
Same problem from the sparse `[from, to, meters]` edge-list form (build it with `array_agg([f, t, m])`) instead of a dense matrix -- here a complete 4-node graph.
SELECT seq, node, arrival
FROM ortools.main.solve_tsp(distance := [[0,1,1],[0,2,4],[0,3,2],[1,0,1],[1,2,1],[1,3,5],[2,0,4],[2,1,1],[2,3,1],[3,0,2],[3,1,5],[3,2,1]]::BIGINT[][], start := 0, time_limit_s := 1.0)
ORDER BY seq;
solve_vrp (allow_dropping := BOOLEAN, demand := BIGINT[][], depot := BIGINT, distance := BIGINT[][], drop_penalty := BIGINT, first_solution_strategy := VARCHAR, lns_time_limit_s := DOUBLE, local_search_metaheuristic := VARCHAR, num_vehicles := BIGINT, pickup_delivery := BIGINT[][], random_seed := BIGINT, service_time := BIGINT[][], settings_json := VARCHAR, solution_limit := BIGINT, span_cost_coefficient := BIGINT, time_limit_s := DOUBLE, time_windows := BIGINT[][], travel_time := BIGINT[][], vehicle_capacity := BIGINT)
Vehicle routing problem: route a fleet from a depot to serve stops at minimum total distance, with optional capacity dimensions, time windows, service/travel time, pickup-delivery pairs, droppable stops, and route balancing. OR-Tools routing library.
Capacitated VRP: 1 depot, 3 stops of demand 1, 2 vehicles of capacity 2 (optimal distance 6).
SELECT route_id, seq, node, arrival, load_0
FROM ortools.main.solve_vrp(distance := [[0,1,1],[0,2,1],[0,3,2],[1,0,1],[1,2,1],[1,3,2],[2,0,1],[2,1,1],[2,3,1],[3,0,2],[3,1,2],[3,2,1]]::BIGINT[][], demand := [[1,1],[2,1],[3,1]]::BIGINT[][], num_vehicles := 2, vehicle_capacity := 2, depot := 0, time_limit_s := 1.0)
ORDER BY route_id, seq;
Try these queries
Optimal travelling-salesperson tour over a 5-node distance matrix, in visit order.
SELECT seq, node, arrival
FROM ortools.main.solve_tsp(distance := [[0,2,9,10,1],[1,0,6,4,8],[15,7,0,8,3],[6,3,12,0,5],[9,8,4,7,0]]::BIGINT[][], start := 0)
ORDER BY seq
Uses solve_tsp
List the bundled OR-Tools / solver component versions.
SELECT component, version FROM ortools.main.solver_info ORDER BY component
Uses solver_info
Arc criticality: for each arc carrying flow in the 0->3 max-flow solution, re-solve with that arc removed (max_flow_value) and report the throughput lost. Losing arc 2->3 drops the max flow from 30 to 10; each of the other flow-carrying arcs costs 10.
SELECT f."from", f."to", f.flow,
ortools.main.max_flow_value(list_filter([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], lambda a: NOT (a[1] = f."from" AND a[2] = f."to")), 0, 3) AS flow_without_arc,
ortools.main.max_flow_value([[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], 0, 3) - flow_without_arc AS flow_lost
FROM ortools.main.max_flow(arcs := [[0,1,20],[0,2,30],[1,2,10],[1,3,10],[2,3,20]]::BIGINT[][], source := 0, sink := 3) AS f
ORDER BY flow_lost DESC, f."from", f."to"
Read every metric of the most recent solve on this worker.
SELECT metric, value FROM ortools.main.last_solve_stats ORDER BY metric
Uses last_solve_stats
Run a solve, then read back the statistics of that solve.
SELECT count(*) FROM ortools.main.solve_assignment(cost := [[0,0,1],[1,1,1]]::BIGINT[][], maximize := false);
SELECT metric, value FROM ortools.main.last_solve_stats ORDER BY metric;
Capacitated VRP: 1 depot, 3 stops of demand 1, 2 vehicles of capacity 2 (optimal distance 6).
SELECT route_id, seq, node, arrival, load_0
FROM ortools.main.solve_vrp(distance := [[0,1,1],[0,2,1],[0,3,2],[1,0,1],[1,2,1],[1,3,2],[2,0,1],[2,1,1],[2,3,1],[3,0,2],[3,1,2],[3,2,1]]::BIGINT[][], demand := [[1,1],[2,1],[3,1]]::BIGINT[][], num_vehicles := 2, vehicle_capacity := 2, depot := 0, time_limit_s := 1.0)
ORDER BY route_id, seq
Uses solve_vrp
17 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- Pack items of sizes [3,5,2,7,1,4] into bins that each hold at most 10. What is the fewest number of bins needed? Return a single number.
- Pack items of sizes [3,5,2,7,1,4] into bins of capacity 10. Using the per-bin rollup, how many bins end up holding at least one item? Return a single number.
- Which version of Google OR-Tools does this worker bundle? Find the version string it reports for its OR-Tools engine.
- Run any solve (for example a small assignment), then inspect the statistics of the most recent solve this worker handled and report that solve's status.
OR-Tools is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Anomaly
Statistics & ML
Find outliers, discords, repeated motifs and change points in numeric series from SQL
Causal
Statistics & ML
Estimate treatment effects (ATE, ATT) and propensity scores from observational data with IPW, regression adjustment, and AIPW
Explain
Statistics & ML
Explain scikit-learn and XGBoost model predictions with per-row SHAP values and global feature importance