@ohtaman/washi 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +22 -24
- package/README.md +20 -22
- package/README.zh-CN.md +25 -27
- package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
- package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
- package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
- package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
- package/dist/browser/solvers/highs.js +1414 -0
- package/dist/browser/washi.js +1090 -1473
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/solvers/glpk.js +34 -32
- package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
- package/dist/lib/solvers/highs.js +410 -0
- package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
- package/dist/lib/solvers/pumpkin-worker.js +1 -1
- package/dist/lib/solvers/pumpkin.js +247 -1146
- package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
- package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
- package/dist/lib/solvers/z3.js +125 -123
- package/dist/lib/washi.js +2426 -1340
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +0 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +6 -7
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +2 -1
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +33 -14
- package/docs/examples/ecommerce-coupons.md +17 -9
- package/docs/examples/index.md +34 -30
- package/docs/examples/knapsack.md +11 -5
- package/docs/examples/portfolio-qp.md +21 -8
- package/docs/examples/production.md +10 -5
- package/docs/examples/project-scheduling.md +25 -12
- package/docs/examples/shift-scheduling.md +27 -19
- package/docs/examples/smt-security.md +27 -12
- package/docs/examples/transportation.md +23 -13
- package/docs/examples/traveling-salesperson.md +34 -22
- package/docs/examples/unsat-core.md +27 -15
- package/docs/examples/vehicle-routing.md +74 -28
- package/docs/getting-started/ai-agents.md +129 -90
- package/docs/getting-started/coding-agents.md +60 -41
- package/docs/getting-started/cross-origin.md +27 -14
- package/docs/getting-started/index.md +23 -16
- package/docs/getting-started/runtimes.md +70 -40
- package/docs/guide/constraint-programming.md +74 -44
- package/docs/guide/constraints.md +71 -39
- package/docs/guide/decomposition.md +72 -42
- package/docs/guide/expressions.md +79 -48
- package/docs/guide/formulation-tips.md +46 -27
- package/docs/guide/objectives.md +55 -31
- package/docs/guide/unsat-core.md +56 -53
- package/docs/guide/variables.md +61 -28
- package/docs/solvers/custom-solver.md +155 -119
- package/docs/solvers/glpk.md +58 -17
- package/docs/solvers/highs.md +115 -43
- package/docs/solvers/index.md +33 -26
- package/docs/solvers/pumpkin.md +71 -63
- package/docs/solvers/z3.md +63 -25
- package/llms-full.txt +1623 -953
- package/llms.txt +125 -93
- package/package.json +29 -20
- package/skills/washi/SKILL.md +43 -22
- package/dist/browser/solvers/pumpkin.min.js +0 -1
- package/dist/lib/registry-dx7x4e5c.js +0 -1694
- /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
- /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
- /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
- /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
- /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
- /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
- /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
- /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
- /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
# Coding with AI Agents
|
|
2
2
|
|
|
3
|
-
This guide
|
|
3
|
+
This guide explains how to configure AI coding agents to build, verify, and package `@ohtaman/washi` optimization and constraint models. It covers tools such as Claude Code, Cursor, Codex, Antigravity, Gemini CLI, and Windsurf.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## 1. Setup
|
|
8
8
|
|
|
9
|
-
Setting up WaSHI with a coding agent has two
|
|
9
|
+
Setting up WaSHI with a coding agent has two parts. First, install the runtime library in your project. Second, connect your agent to WaSHI's API reference and verification workflow.
|
|
10
10
|
|
|
11
11
|
### Install the Runtime Library
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Installing `@ohtaman/washi` bundles **HiGHS** for linear, mixed-integer, and convex quadratic programming (`LP`/`MIP`/`QP`), along with **Pumpkin** for Constraint Programming (`CP`), with zero external dependencies:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install @ohtaman/washi
|
|
17
17
|
|
|
18
|
-
# Optional
|
|
18
|
+
# Optional dependencies for Z3 (SMT / continuous logic) or GLPK:
|
|
19
19
|
# npm install z3-solver
|
|
20
20
|
# npm install glpk.js
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
### Connect Your Coding Agent
|
|
24
24
|
|
|
25
|
-
Choose the
|
|
25
|
+
Choose the integration method that matches your tool:
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- Complete single-file API & example reference: `https://washi.ohtaman.dev/llms-full.txt`
|
|
35
|
-
- **Context7 MCP**:
|
|
36
|
-
- Reference library ID: `/ohtaman/washi`
|
|
27
|
+
| Method | Best For | Setup |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| **Agent Skill** *(Recommended)* | Claude Code, Cursor, Codex, Antigravity, Gemini CLI | Run `npx skills add ohtaman/washi` |
|
|
30
|
+
| **IDE `@Docs` Index** | Cursor, Windsurf | Add `https://washi.ohtaman.dev/llms.txt` or `https://washi.ohtaman.dev/llms-full.txt` |
|
|
31
|
+
| **Context7 MCP** | MCP-enabled agents | Reference library ID `/ohtaman/washi` |
|
|
32
|
+
|
|
33
|
+
Installing the Agent Skill places `SKILL.md` into your agent's skills directory. It teaches your agent solver selection, `expr` modeling, and debugging with `m.toLpString()`, `m.verify()`, and `m.check()`.
|
|
37
34
|
|
|
38
35
|
---
|
|
39
36
|
|
|
@@ -53,17 +50,24 @@ Requirements:
|
|
|
53
50
|
|
|
54
51
|
When you run this prompt, the agent executes three steps locally:
|
|
55
52
|
|
|
56
|
-
1. **Formulates the model**:
|
|
57
|
-
2. **Solves in Node.js via WebAssembly**:
|
|
58
|
-
3. **Independently verifies the solution**: Checks `m.hasPrimalSolution` and calls `m.verify()
|
|
53
|
+
1. **Formulates the model**: Declares 0-1 binary variables with `m.binary()`, linear expressions with `` expr`...` `` and `sum()`, named constraints, and a minimization objective.
|
|
54
|
+
2. **Solves in Node.js via WebAssembly**: Runs the script (for example via `npx tsx schedule.ts`) using the bundled HiGHS WebAssembly binary. No Python runtime or native solver installation is needed.
|
|
55
|
+
3. **Independently verifies the solution**: Checks `m.hasPrimalSolution` and calls `m.verify()`. This confirms variable bounds, integrality, and constraint satisfaction before printing results.
|
|
59
56
|
|
|
60
57
|
---
|
|
61
58
|
|
|
62
59
|
## 3. Problem Classes & Ready-to-Use Prompts
|
|
63
60
|
|
|
64
|
-
|
|
61
|
+
Match your task to the problem class and solver below, then customize the corresponding prompt template:
|
|
62
|
+
|
|
63
|
+
| Problem Class | Recommended Solver | Key Primitives |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| Assignment, timetabling, 0-1 selection (`MILP` / `0-1 MIP`) | Bundled **HiGHS** | `m.binary()`, `sum()`, `dot()` |
|
|
66
|
+
| Task scheduling with shared resources (`CP`) | Bundled **Pumpkin** | `disjoint()`, `cumulative()`, `distinct()` |
|
|
67
|
+
| Target balancing & variance minimization (Convex `QP`) | Bundled **HiGHS** | `m.continuous()`, `` expr`...^2` `` |
|
|
68
|
+
| Rule conflict diagnosis (`unsatCore`) | Bundled **Pumpkin** or optional **Z3** | `m.check()` |
|
|
65
69
|
|
|
66
|
-
###
|
|
70
|
+
### Reviewer Assignment & Load Balancing (MILP — Bundled HiGHS)
|
|
67
71
|
|
|
68
72
|
```text
|
|
69
73
|
Using @ohtaman/washi (bundled HiGHS), assign 24 pull-request / RFC submissions to 6 engineers so each submission gets 2 distinct reviewers.
|
|
@@ -85,10 +89,10 @@ Rules:
|
|
|
85
89
|
- Give every constraint a clear name and confirm m.verify().valid === true.
|
|
86
90
|
```
|
|
87
91
|
|
|
88
|
-
### Task Scheduling with Precedence & Shared Resources (CP
|
|
92
|
+
### Task Scheduling with Precedence & Shared Resources (CP — Bundled Pumpkin)
|
|
89
93
|
|
|
90
94
|
```text
|
|
91
|
-
Using @ohtaman/washi and its bundled CP solver (
|
|
95
|
+
Using @ohtaman/washi and its bundled CP solver ({ solver: "pumpkin" }), schedule 10 release-pipeline tasks with integer start times (lb: 0, ub: 120) and fixed durations to minimize total makespan.
|
|
92
96
|
Rules:
|
|
93
97
|
- Enforce finish-to-start precedence edges between dependent tasks.
|
|
94
98
|
- Tasks using the staging benchmark cluster cannot overlap (use disjoint).
|
|
@@ -98,10 +102,10 @@ Rules:
|
|
|
98
102
|
|
|
99
103
|
### Target-Balancing & Variance Minimization (Convex QP — Bundled HiGHS)
|
|
100
104
|
|
|
101
|
-
Built-in HiGHS solves convex quadratic objectives over continuous variables (`m.continuous`):
|
|
105
|
+
Built-in HiGHS solves convex quadratic objectives over continuous variables (`m.continuous()`):
|
|
102
106
|
|
|
103
107
|
```text
|
|
104
|
-
Using @ohtaman/washi (bundled HiGHS), allocate a continuous total budget of 1.0 across 5 regional compute pools using m.continuous variables (lb: 0.05, ub: 0.50).
|
|
108
|
+
Using @ohtaman/washi (bundled HiGHS), allocate a continuous total budget of 1.0 across 5 regional compute pools using m.continuous() variables (lb: 0.05, ub: 0.50).
|
|
105
109
|
Target weights are [0.30, 0.25, 0.20, 0.15, 0.10], plus a policy cap that regions 0 and 1 combined cannot exceed 0.48.
|
|
106
110
|
Minimize the sum of squared deviations expr`sum((${w} - ${target})^2)` subject to sum(w) == 1.0 and the regional cap, then verify m.verify().valid === true.
|
|
107
111
|
```
|
|
@@ -109,50 +113,65 @@ Minimize the sum of squared deviations expr`sum((${w} - ${target})^2)` subject t
|
|
|
109
113
|
### Rule & Configuration Conflict Diagnosis (Infeasibility / Unsat Core)
|
|
110
114
|
|
|
111
115
|
```text
|
|
112
|
-
Using @ohtaman/washi
|
|
116
|
+
Using @ohtaman/washi, check whether a set of deployment and feature-flag rules over bounded integer and boolean variables is satisfiable via await m.check({ solver: "pumpkin" }).
|
|
113
117
|
Include a sample test case with contradictory named rules, print res.status and res.unsatCore (or res.conflicts), and show which named rules conflict with each other.
|
|
114
118
|
```
|
|
115
119
|
|
|
116
120
|
> [!NOTE]
|
|
117
|
-
> `await m.check()` works
|
|
121
|
+
> `await m.check()` works with default **HiGHS**, which reports conflicting constraint names in `res.conflicts`.
|
|
122
|
+
>
|
|
123
|
+
> To extract an exact unsatisfiable core (`res.unsatCore`), choose the solver by variable domain:
|
|
124
|
+
> - **Bounded integers and booleans**: Pass `{ solver: "pumpkin" }` (bundled with `@ohtaman/washi`; no extra import or browser `COOP`/`COEP` headers required).
|
|
125
|
+
> - **Continuous or fractional arithmetic**: Install `z3-solver` and import `@ohtaman/washi/solvers/z3`.
|
|
118
126
|
|
|
119
127
|
---
|
|
120
128
|
|
|
121
129
|
## 4. Packaging & Deployment Prompts (Browser, Desktop & Mobile)
|
|
122
130
|
|
|
123
|
-
Once a CLI script produces verified results,
|
|
131
|
+
Once a CLI script produces verified results, ask your agent to package the same model as a local HTML tool or an offline app.
|
|
124
132
|
|
|
125
|
-
### Zero-Server Single-File `.html` Tool (`file://`
|
|
133
|
+
### Zero-Server Single-File `.html` Tool (Double-Click via `file://`)
|
|
126
134
|
|
|
127
135
|
```text
|
|
128
|
-
Package this @ohtaman/washi optimization model into a
|
|
136
|
+
Package this @ohtaman/washi optimization model into a standalone .html file with inline HTML, CSS, and JavaScript so team members can open it directly by double-clicking (file://).
|
|
129
137
|
- Load WaSHI from https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js (global window.Washi).
|
|
130
138
|
- Provide a textarea / CSV file input, a "Solve" button, a table displaying the optimal assignment, and a conflict report using await m.check() if status is "Infeasible".
|
|
131
139
|
- Verify every feasible solve with m.verify().
|
|
132
140
|
```
|
|
133
141
|
|
|
134
|
-
|
|
135
|
-
- Opening the `.html` file directly via `file://` (no local HTTP server) works out of the box when loading `washi.min.js` (and `solvers/pumpkin.min.js` when using Pumpkin) from an HTTPS CDN, because WaSHI detects opaque origins (`window.origin === "null"`) and automatically runs HiGHS and Pumpkin on the main thread.
|
|
136
|
-
- Self-hosted local `.wasm` files (which browsers block on `file://` under `fetch()` CORS rules) and **Z3** (`SharedArrayBuffer` requiring `COOP`/`COEP` headers) require serving over `http://` or `https://`.
|
|
142
|
+
**`file://` runtime notes**: Loading `washi.min.js` from an HTTPS CDN runs directly on `file://`—under `window.origin === "null"`, WaSHI automatically falls back to main-thread execution. Self-hosted `.wasm` files require `http://` or `https://`, and browser Z3 requires Cross-Origin Isolation; see [Runtime Environments](./runtimes.md) and [Cross-Origin Isolation](./cross-origin.md).
|
|
137
143
|
|
|
138
144
|
### Offline Desktop & Mobile Apps (Vite + Tauri / Capacitor / PWA)
|
|
139
145
|
|
|
140
146
|
```text
|
|
141
|
-
Wrap this Vite + TypeScript @ohtaman/washi application as an offline desktop/mobile app using bundled HiGHS (or
|
|
147
|
+
Wrap this Vite + TypeScript @ohtaman/washi application as an offline desktop/mobile app using bundled HiGHS (or { solver: "pumpkin" }) with zero backend server and zero native solver compilation.
|
|
142
148
|
- Keep all solver execution client-side via @ohtaman/washi.
|
|
143
149
|
- Configure Content Security Policy to allow WebAssembly compilation ('wasm-unsafe-eval' in script-src) and Web Workers (worker-src 'self' blob:).
|
|
144
150
|
```
|
|
145
151
|
|
|
146
|
-
|
|
152
|
+
**WebView notes**: Standard Vite builds bundle your solver `.wasm` assets for offline execution in Tauri, Capacitor, and PWAs. Allow `'wasm-unsafe-eval'` in `script-src` (plus `worker-src 'self' blob:` for Web Workers); see [Runtime Environments](./runtimes.md) for a `tauri.conf.json` example.
|
|
147
153
|
|
|
148
154
|
---
|
|
149
155
|
|
|
150
156
|
## 5. Iterating & Debugging with Your Agent
|
|
151
157
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
### Name Every Constraint and Verify Every Solve
|
|
159
|
+
|
|
160
|
+
Ask your agent to pass a descriptive name to `m.constraint(c, "rule_name")` and `m.indicator(b, c, { name: "rule_name" })`, then assert `m.verify().valid === true`. Unnamed constraints default to auto-generated IDs (`c_1`, `c_2` for linear constraints; `lc_1`, `lc_2` for logical constraints), which makes conflict reports harder to read.
|
|
161
|
+
|
|
162
|
+
### Diagnose `"Infeasible"` Models with `m.check()`
|
|
163
|
+
|
|
164
|
+
When adding a new rule makes `m.solve()` return `"Infeasible"`, send a follow-up prompt like this:
|
|
165
|
+
|
|
166
|
+
```text
|
|
167
|
+
Adding the new constraints made m.solve() return "Infeasible".
|
|
168
|
+
Run await m.check() (or await m.check({ solver: "pumpkin" }) for bounded integer/boolean models), print res.conflicts / res.unsatCore, explain in plain terms which named rules and variable bounds contradict each other, and propose which non-rigid constraints should be converted into soft constraints with non-negative slack penalty variables.
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Inspect `m.toLpString()` and Variable Bounds Before Production
|
|
172
|
+
|
|
173
|
+
Have your agent print `m.toLpString()` on a small test fixture before shipping. Confirm three items:
|
|
174
|
+
|
|
175
|
+
- **Finite bounds (`lb` / `ub`)**: Variables inside `m.indicator()` require finite bounds whenever `M` is omitted.
|
|
176
|
+
- **Objective sense**: Check that `Maximize` vs. `Minimize` matches your business goal.
|
|
177
|
+
- **Constraint operators**: Verify that every `<=`, `>=`, and `=` operator and direction matches your intent.
|
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
# Cross-Origin Isolation (Z3 & Browsers)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Running the Z3 solver in a browser requires two browser security conditions: a **Secure Context** and **Cross-Origin Isolation**. Together, they enable `SharedArrayBuffer` for Z3's multithreaded WebAssembly build.
|
|
4
4
|
|
|
5
5
|
> [!TIP]
|
|
6
|
-
> **Not needed for HiGHS, Pumpkin, GLPK, or Node.js**: Bundled
|
|
6
|
+
> **Not needed for HiGHS, Pumpkin, GLPK, or Node.js**: Bundled HiGHS and Pumpkin, as well as the GLPK plugin, never use `SharedArrayBuffer` and work in standard browser contexts. Running Z3 in Node.js also requires no HTTP headers. You only need this guide when using Z3 in a browser.
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
## Why
|
|
10
|
+
## Why Are These Preconditions Required?
|
|
11
11
|
|
|
12
|
-
Z3's WebAssembly
|
|
12
|
+
Z3's WebAssembly binary uses POSIX threads (`pthreads`) backed by `SharedArrayBuffer` and Web Workers. To mitigate Spectre-style side-channel attacks, modern browsers disable `SharedArrayBuffer` by default.
|
|
13
|
+
|
|
14
|
+
Browsers re-enable `SharedArrayBuffer` only when both conditions hold on the top-level document:
|
|
15
|
+
|
|
16
|
+
1. **Secure Context**: The page must load over `https://` or `http://localhost` (including `127.0.0.1` and `[::1]`) so `window.isSecureContext === true`. Plain `http://` LAN IP addresses do not qualify.
|
|
17
|
+
2. **Cross-Origin Isolation**: The document must opt into isolation headers so `window.crossOriginIsolated === true`.
|
|
13
18
|
|
|
14
19
|
---
|
|
15
20
|
|
|
16
21
|
## Required HTTP Response Headers
|
|
17
22
|
|
|
18
|
-
Serve the top-level HTML document with:
|
|
23
|
+
Serve the top-level HTML document with these two response headers:
|
|
24
|
+
|
|
25
|
+
- **Cross-Origin-Opener-Policy (`COOP`)**: `same-origin`
|
|
26
|
+
- **Cross-Origin-Embedder-Policy (`COEP`)**: `require-corp`
|
|
19
27
|
|
|
20
28
|
```http
|
|
21
29
|
Cross-Origin-Opener-Policy: same-origin
|
|
22
30
|
Cross-Origin-Embedder-Policy: require-corp
|
|
23
31
|
```
|
|
24
32
|
|
|
25
|
-
If your page loads
|
|
33
|
+
If your page loads scripts, images, or `.wasm` files from another origin, those responses must include `Cross-Origin-Resource-Policy: cross-origin` (`CORP`) or valid CORS headers (`Access-Control-Allow-Origin`), depending on the request mode.
|
|
26
34
|
|
|
27
35
|
> [!NOTE]
|
|
28
|
-
> Chromium and Firefox also
|
|
36
|
+
> Chromium and Firefox also accept `Cross-Origin-Embedder-Policy: credentialless`, which relaxes `CORP` requirements on cross-origin subresources. **Safari (WebKit) does not support `credentialless`**, so use `require-corp` if you support Safari or iOS.
|
|
29
37
|
|
|
30
38
|
---
|
|
31
39
|
|
|
@@ -33,7 +41,7 @@ If your page loads cross-origin subresources (such as scripts, images, or WASM f
|
|
|
33
41
|
|
|
34
42
|
### 1. Vite (`vite.config.ts`)
|
|
35
43
|
|
|
36
|
-
Configure both the
|
|
44
|
+
Configure both the `vite` dev server and `vite preview` server:
|
|
37
45
|
|
|
38
46
|
```typescript
|
|
39
47
|
import { defineConfig } from "vite";
|
|
@@ -56,7 +64,7 @@ export default defineConfig({
|
|
|
56
64
|
|
|
57
65
|
### 2. Cloudflare Pages / Netlify (`public/_headers`)
|
|
58
66
|
|
|
59
|
-
Place a `_headers` file in `public/` so
|
|
67
|
+
Place a `_headers` file in `public/` so your build copies it to the site root:
|
|
60
68
|
|
|
61
69
|
```text
|
|
62
70
|
/*
|
|
@@ -85,7 +93,7 @@ const nextConfig = {
|
|
|
85
93
|
module.exports = nextConfig;
|
|
86
94
|
```
|
|
87
95
|
|
|
88
|
-
### 4. Custom Node.js
|
|
96
|
+
### 4. Express (Custom Node.js Server)
|
|
89
97
|
|
|
90
98
|
```javascript
|
|
91
99
|
app.use((req, res, next) => {
|
|
@@ -97,19 +105,24 @@ app.use((req, res, next) => {
|
|
|
97
105
|
|
|
98
106
|
### 5. Static Hosting without Header Control (e.g., GitHub Pages)
|
|
99
107
|
|
|
100
|
-
Platforms like GitHub Pages do not
|
|
108
|
+
Platforms like GitHub Pages do not let you customize HTTP response headers. You can use **`coi-serviceworker`** to inject `COOP` and `COEP` headers from a client-side Service Worker. Note that Service Workers themselves also require a Secure Context (`https://` or `http://localhost`).
|
|
101
109
|
|
|
102
|
-
1.
|
|
110
|
+
1. Copy `coi-serviceworker.js` from [`coi-serviceworker`](https://github.com/gzuidhof/coi-serviceworker) or WaSHI's reference [`public/coi-serviceworker.js`](https://github.com/ohtaman/washi/blob/main/public/coi-serviceworker.js) to your site root.
|
|
103
111
|
2. Load it in your HTML `<head>`:
|
|
104
112
|
|
|
105
113
|
```html
|
|
106
114
|
<script src="/coi-serviceworker.js"></script>
|
|
107
115
|
```
|
|
108
116
|
|
|
109
|
-
On the first visit, the Service Worker registers and reloads the page once
|
|
117
|
+
On the first visit, the Service Worker registers and reloads the page once so `window.crossOriginIsolated` becomes `true`.
|
|
110
118
|
|
|
111
119
|
---
|
|
112
120
|
|
|
113
121
|
## Runtime Check in WaSHI
|
|
114
122
|
|
|
115
|
-
|
|
123
|
+
Before initializing Z3 in a browser, WaSHI validates both preconditions in order:
|
|
124
|
+
|
|
125
|
+
| Check | Failure Condition | Result |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| **Secure Context** | `!window.isSecureContext` and hostname is not `localhost`, `127.0.0.1`, or `[::1]` | `solve()` / `check()` immediately rejects with an HTTPS or `localhost` requirement error. |
|
|
128
|
+
| **Cross-Origin Isolation** | `SharedArrayBuffer` is missing or `window.crossOriginIsolated !== true` | `solve()` / `check()` immediately rejects listing the required `COOP` and `COEP` headers instead of hanging. |
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
# Introduction & Installation
|
|
2
2
|
|
|
3
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings
|
|
3
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript. You can write linear, quadratic, and logical expressions with tagged templates (`expr`) and model mathematical optimization and constraint programming problems directly in **Node.js (18+)** and modern browsers.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## 📦 Installation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Installing `@ohtaman/washi` bundles two zero-dependency solvers out of the box, with two additional solvers available as optional dependencies:
|
|
10
|
+
|
|
11
|
+
| Solver | Install | Problem Classes & Capabilities |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| **HiGHS** *(default)* | Bundled in `@ohtaman/washi` (no extra import; subpath `@ohtaman/washi/solvers/highs`) | Linear, mixed-integer, and convex quadratic programming — `LP`, `MIP`, and `QP`. |
|
|
14
|
+
| **Pumpkin** | Bundled in `@ohtaman/washi` (`{ solver: "pumpkin" }`, no extra import; subpath `@ohtaman/washi/solvers/pumpkin`) | Constraint Programming (`CP`) and exact `unsatCore` conflict diagnosis on bounded integers and booleans. |
|
|
15
|
+
| **Z3** | Optional (`z3-solver`) | Satisfiability Modulo Theories (`SMT`), continuous logic, and exact `unsatCore` diagnosis (including continuous variables). |
|
|
16
|
+
| **GLPK** | Optional (`glpk.js`) | Alternative `LP` and `MIP` solver under the GPL-3.0 license. |
|
|
10
17
|
|
|
11
18
|
::: code-group
|
|
12
19
|
|
|
@@ -28,20 +35,20 @@ bun add @ohtaman/washi
|
|
|
28
35
|
|
|
29
36
|
:::
|
|
30
37
|
|
|
31
|
-
Install optional
|
|
38
|
+
Install optional dependencies when you need **Z3** or **GLPK**:
|
|
32
39
|
|
|
33
40
|
```bash
|
|
34
|
-
npm install z3-solver #
|
|
35
|
-
npm install glpk.js #
|
|
41
|
+
npm install z3-solver # Optional: SMT logic and unsatCore diagnosis for models with continuous variables
|
|
42
|
+
npm install glpk.js # Optional: GLPK solver (GPL-3.0)
|
|
36
43
|
```
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
In browsers, Z3 requires a Secure Context and Cross-Origin Isolation headers — `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy`, abbreviated `COOP`/`COEP`. See [Cross-Origin Isolation](./cross-origin.md) for server setup.
|
|
39
46
|
|
|
40
47
|
---
|
|
41
48
|
|
|
42
49
|
## 🚀 Quick Start
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
The production-planning model below maximizes profit from desks and chairs under wood and labor limits:
|
|
45
52
|
|
|
46
53
|
```typescript
|
|
47
54
|
import { Model, expr, maximize } from "@ohtaman/washi";
|
|
@@ -57,7 +64,7 @@ m.objective(maximize(expr`30 * ${desks} + 50 * ${chairs}`));
|
|
|
57
64
|
m.constraint(expr`${desks} + 2 * ${chairs} <= 40`, "wood_capacity");
|
|
58
65
|
m.constraint(expr`2 * ${desks} + ${chairs} <= 50`, "labor_capacity");
|
|
59
66
|
|
|
60
|
-
// 3. Solve (
|
|
67
|
+
// 3. Solve (bundled HiGHS WebAssembly) and verify the solution
|
|
61
68
|
const status = await m.solve();
|
|
62
69
|
if (m.hasPrimalSolution) {
|
|
63
70
|
const report = m.verify();
|
|
@@ -66,9 +73,9 @@ if (m.hasPrimalSolution) {
|
|
|
66
73
|
}
|
|
67
74
|
```
|
|
68
75
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
- **Finite bounds**: Supply finite `lb` and `ub` bounds on `m.continuous()` and `m.integer()` variables whenever known; they tighten MIP formulations and are required by `m.indicator()` when `M` is omitted.
|
|
77
|
+
- **Explicit registration & naming**: Constructing an expression with `` expr`...` `` does not attach it to the model until you call `m.objective()` or `m.constraint()`. Passing descriptive constraint names makes `m.check()` conflict reports readable.
|
|
78
|
+
- **Safe reading & verification**: Check `m.hasPrimalSolution` before reading `.value`, then call `m.verify()` to independently confirm bounds, integrality, and constraints.
|
|
72
79
|
|
|
73
80
|
---
|
|
74
81
|
|
|
@@ -76,11 +83,11 @@ if (m.hasPrimalSolution) {
|
|
|
76
83
|
|
|
77
84
|
### Choose Your Workflow
|
|
78
85
|
|
|
79
|
-
- **Build with an AI Coding Agent**: [Coding with AI Agents](./coding-agents.md) —
|
|
80
|
-
- **Write Models
|
|
86
|
+
- **Build with an AI Coding Agent**: [Coding with AI Agents](./coding-agents.md) — Skill setup via `npx skills add ohtaman/washi`, `llms.txt` / Context7, and ready-to-use prompt templates.
|
|
87
|
+
- **Write Models in TypeScript**: [Modeling Guide](../guide/variables.md) — Variable containers, `sum` and `dot` aggregations, logical constraints, and conflict diagnosis.
|
|
81
88
|
|
|
82
89
|
### Reference & Examples
|
|
83
90
|
|
|
84
|
-
- **[Examples & API Finder](../examples/)**: 12 runnable optimization and SMT recipes—from shift scheduling
|
|
85
|
-
- **[Solvers Overview](../solvers/)**:
|
|
86
|
-
- **[Runtime Environments](./runtimes.md)**: Setup details for Node.js, Vite
|
|
91
|
+
- **[Examples & API Finder](../examples/)**: 12 runnable optimization, CP, and SMT recipes—from shift scheduling to portfolio QP.
|
|
92
|
+
- **[Solvers Overview](../solvers/)**: Side-by-side comparison of bundled HiGHS and Pumpkin against optional Z3 and GLPK.
|
|
93
|
+
- **[Runtime Environments](./runtimes.md)**: Setup details for Node.js, Vite/Next.js, CDNs, standalone HTML, and desktop/mobile WebViews.
|