Skip to content

Commit 1204a1f

Browse files
committed
Release 0.9.1
1 parent 18fc171 commit 1204a1f

3 files changed

Lines changed: 105 additions & 133 deletions

File tree

README.md

Lines changed: 62 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ as multithreaded WebAssembly.
2626
Used in [PragmaPlanner](https://pragmaplanner.com/?utm_source=or-tools-wasm&utm_medium=readme&utm_campaign=used_in)
2727

2828
<p>
29-
<img src="docs/media/network_design.gif" alt="Network design optimization in PragmaPlanner" width="24%">
30-
<img src="docs/media/vrp.gif" alt="Vehicle routing optimization in PragmaPlanner" width="24%">
31-
<img src="docs/media/steel_mill_slab.png" alt="Steel mill slab optimization in PragmaPlanner" width="24%">
29+
<img src="docs/media/factory_floor.gif" alt="Factory floor optimization in PragmaPlanner" height="180">
30+
<img src="docs/media/sudoku.gif" alt="Sudoku optimization example in PragmaPlanner" height="180">
3231
</p>
3332
<p>
34-
<img src="docs/media/factory_floor.gif" alt="Factory floor optimization in PragmaPlanner" width="48%">
35-
<img src="docs/media/sudoku.gif" alt="Sudoku optimization example in PragmaPlanner" width="24%">
33+
<img src="docs/media/network_design.gif" alt="Network design optimization in PragmaPlanner" height="160">
34+
<img src="docs/media/vrp.gif" alt="Vehicle routing optimization in PragmaPlanner" height="160">
35+
<img src="docs/media/steel_mill_slab.png" alt="Steel mill slab optimization in PragmaPlanner" height="160">
3636
</p>
3737

3838
## Usage
@@ -50,11 +50,9 @@ Install from npm:
5050
npm install or-tools-wasm
5151
```
5252

53-
Import the solver API you need from its subpath:
54-
55-
```ts
56-
import { CpSat } from 'or-tools-wasm/cp-sat';
57-
```
53+
> [!WARNING]
54+
> Browser builds require cross-origin isolation headers for WebAssembly threads.
55+
> See [Browser requirements](#browser-requirements) below.
5856
5957
Public solver APIs live under solver-scoped subpaths:
6058

@@ -70,45 +68,32 @@ import { SetCoverModel } from 'or-tools-wasm/set-cover';
7068
import { RcpspModelBuilder } from 'or-tools-wasm/rcpsp';
7169
```
7270

73-
Create or serialize an OR-Tools proto model, validate it, then solve it:
71+
Build a CP-SAT model and solve it:
7472

7573
```ts
76-
const model = {
77-
name: 'choose_one',
78-
variables: [
79-
{ name: 'x', domain: [0, 1] },
80-
{ name: 'y', domain: [0, 1] },
81-
],
82-
constraints: [
83-
{
84-
name: 'exactly_one',
85-
linear: {
86-
vars: [0, 1],
87-
coeffs: [1, 1],
88-
domain: [1, 1],
89-
},
90-
},
91-
],
92-
objective: {
93-
vars: [0, 1],
94-
coeffs: [1, 2],
95-
},
96-
};
97-
98-
const modelBytes = await CpSat.createModel(model);
99-
const validation = await CpSat.validate(modelBytes);
100-
101-
if (!validation.ok) {
102-
throw new Error(validation.message);
103-
}
104-
105-
const result = await CpSat.solve(modelBytes, {
106-
numSearchWorkers: 1,
107-
});
74+
const model = new CpModel();
75+
76+
const desks = model.newIntVar(0, 4, 'desks');
77+
const tables = model.newIntVar(0, 3, 'tables');
10878

109-
console.log(result.response);
79+
model.addLinearConstraint(desks.times(3).plus(tables.times(4)), 0, 12);
80+
model.maximize(desks.times(20).plus(tables.times(30)));
81+
82+
const solver = new CpSolver();
83+
const status = await solver.solve(model, { numSearchWorkers: 1 });
84+
85+
console.log(solver.statusName(status));
86+
console.log({
87+
desks: solver.value(desks),
88+
tables: solver.value(tables),
89+
profit: solver.objectiveValue(),
90+
});
11091
```
11192

93+
## API reference
94+
95+
See [docs/api.md](docs/api.md) for the full TypeScript API reference.
96+
11297
## Benchmarking
11398

11499
See [benchmarking/](benchmarking/).
@@ -118,9 +103,9 @@ See [benchmarking/](benchmarking/).
118103
| OR-Tools surface | or-tools-wasm | Description |
119104
| --- | --- | --- |
120105
| CP-SAT || Constraint and integer optimization for Boolean, integer, scheduling, and logical models. |
121-
| Routing || Vehicle routing, TSP, pickup-delivery, capacity, dimension, and time-window search. |
106+
| Routing || Vehicle routing (VRP), TSP, pickup-delivery, capacity, dimension, and time-window search. |
122107
| MPSolver API || Linear and mixed-integer programming wrapper; this package includes GLOP LP, CLP LP, GLPK LP/MIP, SCIP MIP, CBC MIP, BOP MIP, Knapsack MIP, and SAT MIP backends. |
123-
| MathOpt API || Unified modeling and solve API; this package includes GLOP, GLPK, GSCIP, CP-SAT, and PDLP backends. |
108+
| MathOpt API || Unified modeling and solve API with incremental solving and callback support; this package includes GLOP, GLPK, GSCIP, CP-SAT, and PDLP backends. |
124109
| GLOP || Google's simplex linear programming solver. |
125110
| PDLP || First-order LP and convex diagonal quadratic solver for very large models. |
126111
| SAT integer programming || CP-SAT-backed integer programming backend for pure integer linear models. |
@@ -134,15 +119,15 @@ See [benchmarking/](benchmarking/).
134119
| Assignment algorithms || Linear-sum assignment through the dedicated Network Flow API. |
135120
| Set cover || Dedicated weighted set cover model, invariant, and heuristic search API. |
136121
| RCPSP || CP-SAT-backed resource-constrained project scheduling model, parser, and visual scheduling surface. |
137-
| Linear Solver ModelBuilder | | Python-like `linear_solver.model_builder` API for ergonomic LP/MIP modeling, import/export helpers, and backend solve helpers. |
138-
| MathOpt incremental/callback APIs || Incremental solving is exposed for MathOpt models with tracked updates for common LP/MIP model edits, rejected-update fallback, repeated LP updates, and GSCIP incremental message logging. Indicator constraints, message callbacks, solve interrupters, common solve parameters, typed model solve parameters with solve filters, Python-style solve-result accessors including ray/basis helpers for real solve results, `removeNames` duplicate-name solving, and typed backend parameters for GSCIP, GLOP, CP-SAT, PDLP, and GLPK are exposed. Python-only context managers and constructed result parser/proto-object helpers are outside the current TypeScript contract. |
122+
| Linear Solver ModelBuilder | | Ergonomic LP/MIP modeling API with import/export helpers and backend solve helpers. |
139123

140124
Unchecked rows are planned OR-Tools targets that are not exposed by this package
141125
yet. Commercial and large third-party native backends such as Gurobi, CPLEX,
142126
XPRESS, HiGHS, OSQP, ECOS, and SCS are not planned.
143127

144-
The TypeScript API mirrors the public OR-Tools API shape where it maps cleanly
145-
to WebAssembly. CP-SAT exposes both a Python-like high-level builder and the
128+
The TypeScript API mirrors the public OR-Tools Python API shape where it maps
129+
cleanly to WebAssembly, and the fixture suite tracks Python API behavior for
130+
the exposed solver surfaces. CP-SAT exposes both a high-level builder and the
146131
proto-first `CpSat` API, routing exposes the familiar `RoutingIndexManager` and
147132
`RoutingModel` APIs, MPSolver exposes the `pywraplp`-style solver API, and
148133
MathOpt exposes a TypeScript model builder.
@@ -152,78 +137,43 @@ imports, with no manual copying into `public/` or `static/` required.
152137

153138
## Fixture test matrix
154139

155-
`npm --prefix package run test:fixtures` is the full fixture matrix. It runs the shared solver
156-
cases through Vite, Webpack, Rollup, Deno, Node, and Bun. Browser fixtures cover
157-
dev and static serving where the bundler supports both, Chromium and Firefox,
158-
direct runtime execution, the browser worker bridge, and solver thread settings
159-
where the solver supports them.
140+
Run the full fixture matrix:
160141

161-
For focused iteration, use `npm --prefix package run test:fixtures:browser`,
162-
`npm --prefix package run test:fixtures:runtime`, or an individual fixture script such as
163-
`npm --prefix package run test:fixture:node`. The full matrix is the comprehensive check before
164-
landing solver API, worker bridge, threading, or packaging changes.
142+
```sh
143+
npm --prefix package run test:fixtures
144+
```
165145

166-
## API reference
146+
This runs the shared solver cases through Vite, Webpack, Rollup, Deno, Node,
147+
and Bun. Browser fixtures cover dev and static serving where the bundler
148+
supports both, Chromium and Firefox, direct runtime execution, the browser
149+
worker bridge, and solver thread settings where supported.
150+
151+
For focused iteration:
152+
153+
```sh
154+
npm --prefix package run test:fixtures:browser
155+
npm --prefix package run test:fixtures:runtime
156+
npm --prefix package run test:fixture:node
157+
```
167158

168-
See [docs/api.md](docs/api.md) for the full TypeScript API reference covering
169-
CP-SAT, routing, MPSolver, MathOpt, PDLP, RCPSP, worker behavior, generated
170-
protobuf types, and native object cleanup.
159+
Run the full matrix before landing solver API, worker bridge, threading, or
160+
packaging changes.
171161

172162
## Browser requirements
173163

174-
Browser builds use WebAssembly threads, SIMD, and `SharedArrayBuffer`. Pages
175-
must be served with cross-origin isolation enabled:
164+
Browser builds use WebAssembly threads, so pages must be served with
165+
cross-origin isolation enabled:
176166

177167
```http
178168
Cross-Origin-Opener-Policy: same-origin
179169
Cross-Origin-Embedder-Policy: require-corp
180170
```
181171

182-
Without these headers, browsers may block `SharedArrayBuffer`, and solving can
183-
fail during WebAssembly runtime or worker startup.
172+
Without these headers, solving can fail during WebAssembly runtime or worker
173+
startup.
184174

185-
Browser solves can run through a hidden worker bridge, so the main thread stays
186-
available for rendering, input, progress UI, and cancellation. The shared worker
187-
bridge controls apply across CP-SAT, routing, MPSolver, Knapsack, Network Flow,
188-
Set Cover, RCPSP, MathOpt, and PDLP:
189-
190-
```ts
191-
import { isWorkerBridgeEnabled, setWorkerBridgeEnabled } from 'or-tools-wasm/cp-sat';
192-
193-
setWorkerBridgeEnabled(true);
194-
console.log(isWorkerBridgeEnabled());
195-
```
196-
197-
Worker bridge support is separate from solver threading. For example, GLPK and
198-
BOP are single-threaded in this package but can still run through the browser
199-
worker bridge, while CP-SAT, SAT, SCIP/GSCIP, CBC, RCPSP, and other
200-
threaded-capable paths may also accept solver thread settings. Knapsack and
201-
Network Flow can run through the worker bridge but do not expose solver thread
202-
settings. Set Cover is also single-threaded and worker-bridge capable. The package loads solver
203-
runtimes on demand; application code does not need to choose between JSPI and
204-
Asyncify manually.
205-
206-
For Vite dev and preview servers, set the headers in `vite.config.ts`:
207-
208-
```ts
209-
// vite.config.ts
210-
import { defineConfig } from 'vite';
211-
212-
export default defineConfig({
213-
server: {
214-
headers: {
215-
'Cross-Origin-Opener-Policy': 'same-origin',
216-
'Cross-Origin-Embedder-Policy': 'require-corp',
217-
},
218-
},
219-
preview: {
220-
headers: {
221-
'Cross-Origin-Opener-Policy': 'same-origin',
222-
'Cross-Origin-Embedder-Policy': 'require-corp',
223-
},
224-
},
225-
});
226-
```
175+
See [Bundler configuration](#bundler-configuration) for Vite, Webpack, and
176+
Rollup setup.
227177

228178
## Bundler configuration
229179

@@ -240,26 +190,9 @@ Deno needs permissions to read package assets and inspect CPU count:
240190
deno run --allow-read --allow-sys=cpus your-script.ts
241191
```
242192

243-
Node, Deno, and Bun use the JSPI runtime when `WebAssembly.promising` is
244-
available and fall back to the Asyncify runtime otherwise.
245-
246-
## Development
247-
248-
```sh
249-
npm --prefix package install
250-
npm --prefix package run dev
251-
npm --prefix package run build
252-
npm --prefix package run preview
253-
```
254-
255-
`npm --prefix package run dev` / `npm --prefix package run start` builds the library and launches the demo site.
256-
`npm --prefix package run build` runs the full WebAssembly, package, and static site build.
257-
258-
The Emscripten SDK is tracked as a pinned `emsdk` git submodule. The build
259-
script initializes that submodule automatically if needed, so a normal clone can
260-
run `npm --prefix package run build` directly after `npm --prefix package install`. If you prefer to fetch
261-
submodules up front, clone with `--recurse-submodules` or run
262-
`git submodule update --init --recursive`.
193+
Node uses the JSPI runtime when `WebAssembly.promising` is available and falls
194+
back to Asyncify otherwise. Deno and Bun use the package's Asyncify runtime
195+
path.
263196

264197
## Upstream OR-Tools
265198

package/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package.json

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "or-tools-wasm",
33
"private": false,
4-
"version": "0.9.0",
4+
"version": "0.9.1",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",
@@ -169,5 +169,44 @@
169169
"vite-plugin-dts": "^4.5.4",
170170
"vite-plugin-top-level-await": "^1.6.0",
171171
"vite-plugin-wasm": "^3.5.0"
172-
}
172+
},
173+
"keywords": [
174+
"or-tools",
175+
"ortools",
176+
"google-or-tools",
177+
"optimization",
178+
"operations-research",
179+
"constraint-programming",
180+
"constraint-solver",
181+
"cp-sat",
182+
"sat",
183+
"linear-programming",
184+
"integer-programming",
185+
"mixed-integer-programming",
186+
"mip",
187+
"milp",
188+
"mathopt",
189+
"vehicle-routing",
190+
"vrp",
191+
"tsp",
192+
"route-optimization",
193+
"scheduling",
194+
"timetabling",
195+
"assignment",
196+
"bin-packing",
197+
"knapsack",
198+
"network-flow",
199+
"wasm",
200+
"webassembly",
201+
"typescript",
202+
"javascript",
203+
"browser",
204+
"solver",
205+
"combinatorial-optimization",
206+
"mathematical-optimization",
207+
"job-shop-scheduling",
208+
"delivery-routing",
209+
"client-side"
210+
],
211+
"description": "Google OR-Tools compiled to WebAssembly for TypeScript, JavaScript, browser and Node. Supports CP-SAT, Routing, MIP, MathOpt, vehicle routing, scheduling, linear programming and constraint optimization."
173212
}

0 commit comments

Comments
 (0)