javascript-lp-solver 1.0.1 → 1.1.0

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.
Files changed (66) hide show
  1. package/README.md +80 -12
  2. package/dist/index.browser.mjs +4797 -1314
  3. package/dist/index.browser.mjs.map +1 -1
  4. package/dist/index.cjs +4812 -1311
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +765 -41
  7. package/dist/index.mjs +4812 -1311
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/solver.global.js +4797 -1314
  10. package/dist/solver.global.js.map +1 -1
  11. package/dist/types/expressions.d.ts +148 -0
  12. package/dist/types/external/lpsolve/main.d.ts +2 -7
  13. package/dist/types/external/lpsolve/reformat.d.ts +1 -6
  14. package/dist/types/external/main.d.ts +7 -0
  15. package/dist/types/implied-integers.d.ts +47 -0
  16. package/dist/types/main.d.ts +23 -7
  17. package/dist/types/model.d.ts +171 -0
  18. package/dist/types/polyopt.d.ts +21 -4
  19. package/dist/types/shims/external.d.ts +2 -6
  20. package/dist/types/solver.miplib.test.d.ts +1 -0
  21. package/dist/types/solver.netlib.test.d.ts +1 -0
  22. package/dist/types/solver.property.test.d.ts +1 -0
  23. package/dist/types/tableau/backup.d.ts +49 -0
  24. package/dist/types/tableau/bounds.d.ts +68 -0
  25. package/dist/types/tableau/bounds.test.d.ts +1 -0
  26. package/dist/types/tableau/branch-and-cut.d.ts +14 -0
  27. package/dist/types/tableau/cutting-strategies.d.ts +34 -0
  28. package/dist/types/tableau/determinism.test.d.ts +1 -0
  29. package/dist/types/tableau/dynamic-modification.d.ts +77 -11
  30. package/dist/types/tableau/enhanced-branch-and-cut.d.ts +22 -4
  31. package/dist/types/tableau/gomory.d.ts +48 -0
  32. package/dist/types/tableau/gomory.test.d.ts +1 -0
  33. package/dist/types/tableau/incremental-branch-and-cut.d.ts +24 -0
  34. package/dist/types/tableau/index.d.ts +1 -4
  35. package/dist/types/tableau/kernel.d.ts +119 -0
  36. package/dist/types/tableau/kernel.test.d.ts +1 -0
  37. package/dist/types/tableau/log.d.ts +14 -0
  38. package/dist/types/tableau/min-heap.d.ts +39 -0
  39. package/dist/types/tableau/mip-utils.d.ts +31 -55
  40. package/dist/types/tableau/mir.d.ts +65 -0
  41. package/dist/types/tableau/mir.test.d.ts +1 -0
  42. package/dist/types/tableau/presolve.d.ts +12 -10
  43. package/dist/types/tableau/pseudocosts.d.ts +42 -0
  44. package/dist/types/tableau/pseudocosts.test.d.ts +1 -0
  45. package/dist/types/tableau/root-presolve.d.ts +33 -0
  46. package/dist/types/tableau/root-presolve.test.d.ts +1 -0
  47. package/dist/types/tableau/simplex.d.ts +46 -0
  48. package/dist/types/tableau/solution.d.ts +31 -13
  49. package/dist/types/tableau/tableau.d.ts +153 -0
  50. package/dist/types/tableau/types.d.ts +45 -21
  51. package/dist/types/test-utils/problem-generator.d.ts +2 -2
  52. package/dist/types/types/solver.d.ts +119 -0
  53. package/package.json +11 -2
  54. package/scripts/ts-node-register.js +1 -1
  55. package/dist/solver.cjs.js +0 -4448
  56. package/dist/types/tableau/branching-strategies.d.ts +0 -4
  57. package/dist/types/tableau/integer-properties.d.ts +0 -4
  58. package/dist/types/tableau/lu-factorization.d.ts +0 -61
  59. package/dist/types/tableau/lu-simplex.d.ts +0 -32
  60. package/dist/types/tableau/milp-solution.d.ts +0 -7
  61. package/dist/types/tableau/parallel-branch-and-cut.d.ts +0 -39
  62. package/dist/types/tableau/sparse-matrix.d.ts +0 -98
  63. package/dist/types/tableau/sparse-simplex.d.ts +0 -30
  64. package/dist/types/types/api.d.ts +0 -5
  65. package/dist/types/wasm/index.d.ts +0 -42
  66. /package/dist/types/{tableau/sparse-matrix.test.d.ts → implied-integers.test.d.ts} +0 -0
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  - **Mixed-Integer Programming (MIP)**: Handle integer and binary variables via branch-and-cut
12
12
  - **Multi-Objective Optimization**: Find compromise solutions across multiple objectives
13
13
  - **JSON Model Format**: Define problems as simple JavaScript objects
14
- - **Zero Dependencies**: Pure JavaScript/TypeScript with no external solver required
14
+ - **Zero Dependencies**: Pure JavaScript/TypeScript with no external solver required (a small embedded WebAssembly SIMD kernel speeds up pivots where available, with a JS fallback)
15
15
  - **Universal**: Works in Node.js, browsers, and Web Workers
16
16
 
17
17
  ## Installation
@@ -107,7 +107,10 @@ const model = {
107
107
  };
108
108
  ```
109
109
 
110
- To set upper bounds on variables, add them as constraints:
110
+ To set upper bounds on variables, add them as single-variable constraints.
111
+ For integer programs the solver turns these (and the implicit `<= 1` of
112
+ `binaries`) into column bounds instead of tableau rows, so they cost almost
113
+ nothing:
111
114
 
112
115
  ```javascript
113
116
  const model = {
@@ -169,15 +172,78 @@ worker.postMessage(model);
169
172
 
170
173
  ## Performance
171
174
 
172
- Representative benchmarks (Intel i5-10400 @ 2.9GHz, Node.js 22, 10 runs averaged):
173
-
174
- | Problem | Variables | Constraints | Integers | Avg Time |
175
- | ---------------- | --------- | ----------- | -------- | -------- |
176
- | Large Farm MIP | 100 | 35 | 100 | 67ms |
177
- | Monster LP | 552 | 600 | 0 | 5ms |
178
- | Monster II MIP | 924 | 888 | 112 | 121ms |
179
- | Stock Cutting | 31 | 5 | 31 | 7ms |
180
- | Vendor Selection | 1640 | 1641 | 40 | 606ms |
175
+ Measured on an Apple M4 Max, Node.js 24. "v1.0.3" is the release before the
176
+ 2026-10 solver work; "#169" is master after the first round (PRs #168, #169);
177
+ "#170" adds the second round; "Now" adds the third (c-MIR cuts; see
178
+ [LESSONS.md](./LESSONS.md)). The reference
179
+ is [HiGHS](https://highs.dev) compiled to WebAssembly (the npm `highs`
180
+ package, single thread), the strongest solver that runs in the same place.
181
+
182
+ **Bundled problems** (`test/test-sanity`, median of repeated runs):
183
+
184
+ | Problem | Variables | Constraints | Integers | v1.0.3 | #169 | #170 | Now |
185
+ | ---------------- | --------- | ----------- | -------- | ------- | ------- | ------- | ------- |
186
+ | Vendor Selection | 1640 | 1641 | 40 | 155 ms | 156 ms | 348 ms | 362 ms |
187
+ | Monster II MIP | 924 | 888 | 112 | 19.8 ms | 11.3 ms | 4.0 ms | 5.2 ms |
188
+ | Large Farm MIP\* | 100 | 35 | 100 | 19.2 ms | 11.7 ms | 2.0 ms | 2.1 ms |
189
+ | Knapsack 1 | 50 | 1 | 50 | - | 0.45 ms | 0.17 ms | 0.17 ms |
190
+ | Monster LP | 552 | 600 | 0 | 1.0 ms | 1.1 ms | 1.1 ms | 1.0 ms |
191
+ | Stock Cutting | 31 | 5 | 31 | 0.72 ms | 0.05 ms | 0.08 ms | 0.08 ms |
192
+
193
+ \* Runs with `tolerance: 0.005`, so every version stops at a solution within 0.5% of the bound.
194
+
195
+ **Classic test sets** (converted from MPS, 30 s limit per problem). A problem
196
+ counts as solved only if the returned solution vector is feasible, integral
197
+ and optimal when recomputed independently with HiGHS:
198
+
199
+ | Test set | v1.0.3 | #169 | #170 | Now |
200
+ | --------------------- | --------------------------------------- | -------------------------------- | ---------- | -------------- |
201
+ | 25 Netlib LPs | 19 correct (5 hang, 1 false infeasible) | 25 correct | 25 correct | **25 correct** |
202
+ | 30 MIPLIB 3 MIPs | 9 solved | 12 solved (2 more wrong vectors) | 21 solved | **23 solved** |
203
+ | ... within 60 s | | | 23 solved | **27 solved** |
204
+ | SPY option-spread MIP | did not finish in 120 s | 5.4 s | 2.3 s | **0.4 s** |
205
+ | 4 soccer rotations | none finish in 60 s | none finish in 60 s | 0.2-2.2 s | **0.2-2.4 s** |
206
+
207
+ The first round's README also listed MIPLIB noswot as solved; that answer was
208
+ wrong (its vector recomputes to -19 with violated rows, while HiGHS proves -41).
209
+
210
+ | MIPLIB 3 instance | v1.0.3 | #169 | #170 | Now | HiGHS-WASM |
211
+ | ----------------- | ------ | ------ | ------ | ------ | ---------- |
212
+ | stein27 | 10.8 s | 0.1 s | 0.1 s | 0.1 s | 0.43 s |
213
+ | p0201 | 26.6 s | wrong | 0.5 s | 0.5 s | 0.52 s |
214
+ | mod008 | 8.0 s | 0.5 s | 0.2 s | 0.2 s | 0.71 s |
215
+ | egout | 13.8 s | 1.7 s | 0.03 s | 0.03 s | 0.06 s |
216
+ | lseu | 7.0 s | 1.8 s | 0.2 s | 0.1 s | 0.16 s |
217
+ | khb05250 | 4.8 s | 1.6 s | 0.2 s | 0.2 s | 0.26 s |
218
+ | bell3a | > 30 s | 10.2 s | 0.8 s | 1.3 s | 0.58 s |
219
+ | dcmulti | > 30 s | 11.7 s | 1.7 s | 2.5 s | 1.13 s |
220
+ | enigma | > 30 s | wrong | 1.9 s | 2.0 s | 0.31 s |
221
+ | bell5 | > 30 s | > 30 s | 3.1 s | 2.6 s | 0.29 s |
222
+ | fixnet6 | > 30 s | > 30 s | 3.5 s | 4.2 s | 1.66 s |
223
+ | p0548 | > 30 s | > 30 s | 5.5 s | 2.0 s | 0.12 s |
224
+ | gesa2 | > 30 s | > 30 s | > 30 s | 9.4 s | 0.42 s |
225
+ | blend2 | > 30 s | > 30 s | > 30 s | 12.7 s | 1.08 s |
226
+ | mas76 | > 30 s | > 30 s | 9.6 s | 9.6 s | > 120 s |
227
+ | 60 s limit: | | | | | |
228
+ | mod010 | > 60 s | > 60 s | > 60 s | 31 s | 0.48 s |
229
+ | fiber | > 60 s | > 60 s | > 60 s | 49 s | 0.69 s |
230
+ | misc07 | > 60 s | > 60 s | 48 s | 49 s | 17.0 s |
231
+ | pk1 | > 60 s | > 60 s | 54 s | 56 s | > 120 s |
232
+
233
+ Still out of reach: noswot, qnet1 and vpm2 (HiGHS-WASM: noswot 52 s, the
234
+ others 0.4-1.3 s).
235
+
236
+ What changed in the third round: root c-MIR cuts on the original rows
237
+ (Marchand-Wolsey, with variable-upper-bound substitution and refinements
238
+ following HiGHS's separator), whose cuts are checked against sampled
239
+ feasible points in the tests.
240
+
241
+ What changed in the second round: LP numerics (a Harris dual ratio test,
242
+ consistent tolerances, row equilibration), Devex pricing, reliability
243
+ branching, root Gomory cuts, root presolve (bound propagation and big-M
244
+ coefficient tightening), reduced-cost fixing, implied-integer detection and
245
+ objective integrality by total unimodularity. Details, measurements and dead
246
+ ends are in [LESSONS.md](./LESSONS.md).
181
247
 
182
248
  ## Documentation
183
249
 
@@ -228,7 +294,9 @@ npm run docs
228
294
  The test suite uses [Vitest](https://vitest.dev/) and includes:
229
295
 
230
296
  - **Unit tests**: Cover utilities, data structures, and isolated components
231
- - **Integration tests**: Run the solver against 47 real-world problems (Berlin Airlift, Knapsack, Farm MIP, etc.)
297
+ - **Integration tests**: Run the solver against 47 real-world problems (Berlin Airlift, Knapsack, Farm MIP, etc.). MIP and feasibility models are verified (objective, feasibility, integrality) rather than pinned to one of several optimal solutions
298
+ - **Netlib regressions**: 11 classic LPs with HiGHS-verified optima (`test/netlib`), each solved in a child process with a timeout so a hang fails instead of freezing the run
299
+ - **Determinism**: solving without a `timeout` never reads the clock, so the same model always explores the same tree
232
300
  - **Stress tests**: Use seeded random problem generation (LP, MIP, knapsack, set cover, transportation) to test solver robustness without large static test files
233
301
 
234
302
  Coverage thresholds are enforced: 60% statements/lines/functions, 45% branches.