@ohtaman/washi 0.4.0 → 0.5.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 (97) hide show
  1. package/README.ja.md +100 -107
  2. package/README.md +98 -105
  3. package/README.zh-CN.md +101 -108
  4. package/dist/browser/highs-worker.js +21 -3
  5. package/dist/browser/loader-CtaDHef_.js +273 -0
  6. package/dist/browser/solvers/glpk.js +433 -286
  7. package/dist/browser/solvers/glpk.min.js +1 -1
  8. package/dist/browser/solvers/z3.js +1002 -981
  9. package/dist/browser/solvers/z3.min.js +2 -2
  10. package/dist/browser/washi.js +2129 -676
  11. package/dist/browser/washi.min.js +4 -4
  12. package/dist/lib/highs-worker.js +21 -3
  13. package/dist/lib/loader-DmNC_UNk.js +279 -0
  14. package/dist/lib/registry-BEfvpZW3.js +951 -0
  15. package/dist/lib/solvers/glpk.js +201 -90
  16. package/dist/lib/solvers/z3.js +399 -259
  17. package/dist/lib/washi.js +1627 -988
  18. package/dist/types/index.d.ts +4 -4
  19. package/dist/types/index.d.ts.map +1 -1
  20. package/dist/types/modeler/big-m.d.ts +75 -0
  21. package/dist/types/modeler/big-m.d.ts.map +1 -0
  22. package/dist/types/modeler/boolean-expr.d.ts +103 -14
  23. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  24. package/dist/types/modeler/constraint.d.ts +36 -9
  25. package/dist/types/modeler/constraint.d.ts.map +1 -1
  26. package/dist/types/modeler/expression.d.ts +113 -28
  27. package/dist/types/modeler/expression.d.ts.map +1 -1
  28. package/dist/types/modeler/index.d.ts +10 -6
  29. package/dist/types/modeler/index.d.ts.map +1 -1
  30. package/dist/types/modeler/lp-writer.d.ts +27 -2
  31. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  32. package/dist/types/modeler/model.d.ts +478 -131
  33. package/dist/types/modeler/model.d.ts.map +1 -1
  34. package/dist/types/modeler/objective.d.ts +59 -0
  35. package/dist/types/modeler/objective.d.ts.map +1 -0
  36. package/dist/types/modeler/parser.d.ts +34 -10
  37. package/dist/types/modeler/parser.d.ts.map +1 -1
  38. package/dist/types/modeler/quad-expr.d.ts +26 -7
  39. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  40. package/dist/types/modeler/solution-validator.d.ts +93 -0
  41. package/dist/types/modeler/solution-validator.d.ts.map +1 -0
  42. package/dist/types/modeler/solvers/glpk/solver.d.ts +26 -2
  43. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  44. package/dist/types/modeler/solvers/highs/loader.d.ts +36 -11
  45. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  46. package/dist/types/modeler/solvers/highs/solver.d.ts +11 -4
  47. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  48. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  49. package/dist/types/modeler/solvers/mock.d.ts +14 -5
  50. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  51. package/dist/types/modeler/solvers/types.d.ts +71 -11
  52. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  53. package/dist/types/modeler/solvers/z3/loader.d.ts +2 -3
  54. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  55. package/dist/types/modeler/solvers/z3/solver.d.ts +15 -5
  56. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  57. package/dist/types/modeler/types.d.ts +59 -1
  58. package/dist/types/modeler/types.d.ts.map +1 -1
  59. package/dist/types/modeler/validation.d.ts +56 -0
  60. package/dist/types/modeler/validation.d.ts.map +1 -0
  61. package/dist/types/modeler/variable.d.ts +48 -14
  62. package/dist/types/modeler/variable.d.ts.map +1 -1
  63. package/docs/examples/diet-sensitivity.md +90 -0
  64. package/docs/examples/ecommerce-coupons.md +106 -0
  65. package/docs/examples/index.md +53 -0
  66. package/docs/examples/knapsack.md +60 -0
  67. package/docs/examples/portfolio-qp.md +83 -0
  68. package/docs/examples/production.md +51 -0
  69. package/docs/examples/shift-scheduling.md +175 -0
  70. package/docs/examples/smt-security.md +74 -0
  71. package/docs/examples/transportation.md +90 -0
  72. package/docs/examples/unsat-core.md +64 -0
  73. package/docs/getting-started/ai-agents.md +267 -0
  74. package/docs/getting-started/cross-origin.md +87 -0
  75. package/docs/getting-started/index.md +116 -0
  76. package/docs/getting-started/runtimes.md +227 -0
  77. package/docs/guide/constraints.md +177 -0
  78. package/docs/guide/expressions.md +204 -0
  79. package/docs/guide/objectives.md +170 -0
  80. package/docs/guide/unsat-core.md +147 -0
  81. package/docs/guide/variables.md +188 -0
  82. package/docs/ja/getting-started/ai-agents.md +266 -0
  83. package/docs/solvers/custom-solver.md +525 -0
  84. package/docs/solvers/glpk.md +66 -0
  85. package/docs/solvers/highs.md +93 -0
  86. package/docs/solvers/index.md +42 -0
  87. package/docs/solvers/z3.md +78 -0
  88. package/docs/zh/getting-started/ai-agents.md +266 -0
  89. package/llms-full.txt +3249 -0
  90. package/llms.txt +197 -0
  91. package/package.json +18 -5
  92. package/skills/washi/SKILL.md +197 -0
  93. package/dist/browser/loader-CVt4CloI.js +0 -58
  94. package/dist/lib/async-mutex-Duo4jwzn.js +0 -195
  95. package/dist/lib/constraint-BRuB3ooC.js +0 -90
  96. package/dist/lib/loader-Dti0v9yC.js +0 -50
  97. package/dist/lib/registry-DksqCSjI.js +0 -32
@@ -1,195 +0,0 @@
1
- //#region node_modules/async-mutex/index.mjs
2
- var e = /* @__PURE__ */ Error("timeout while waiting for mutex to become available"), t = /* @__PURE__ */ Error("mutex already locked"), n = /* @__PURE__ */ Error("request for lock canceled"), r = function(e, t, n, r) {
3
- function i(e) {
4
- return e instanceof n ? e : new n(function(t) {
5
- t(e);
6
- });
7
- }
8
- return new (n ||= Promise)(function(n, a) {
9
- function o(e) {
10
- try {
11
- c(r.next(e));
12
- } catch (e) {
13
- a(e);
14
- }
15
- }
16
- function s(e) {
17
- try {
18
- c(r.throw(e));
19
- } catch (e) {
20
- a(e);
21
- }
22
- }
23
- function c(e) {
24
- e.done ? n(e.value) : i(e.value).then(o, s);
25
- }
26
- c((r = r.apply(e, t || [])).next());
27
- });
28
- }, i = class {
29
- constructor(e, t = n) {
30
- if (this._maxConcurrency = e, this._cancelError = t, this._queue = [], this._waiters = [], e <= 0) throw Error("semaphore must be initialized to a positive value");
31
- this._value = e;
32
- }
33
- acquire() {
34
- let e = this.isLocked(), t = new Promise((e, t) => this._queue.push({
35
- resolve: e,
36
- reject: t
37
- }));
38
- return e || this._dispatch(), t;
39
- }
40
- runExclusive(e) {
41
- return r(this, void 0, void 0, function* () {
42
- let [t, n] = yield this.acquire();
43
- try {
44
- return yield e(t);
45
- } finally {
46
- n();
47
- }
48
- });
49
- }
50
- waitForUnlock() {
51
- return r(this, void 0, void 0, function* () {
52
- return this.isLocked() ? new Promise((e) => this._waiters.push({ resolve: e })) : Promise.resolve();
53
- });
54
- }
55
- isLocked() {
56
- return this._value <= 0;
57
- }
58
- release() {
59
- if (this._maxConcurrency > 1) throw Error("this method is unavailable on semaphores with concurrency > 1; use the scoped release returned by acquire instead");
60
- if (this._currentReleaser) {
61
- let e = this._currentReleaser;
62
- this._currentReleaser = void 0, e();
63
- }
64
- }
65
- cancel() {
66
- this._queue.forEach((e) => e.reject(this._cancelError)), this._queue = [];
67
- }
68
- _dispatch() {
69
- let e = this._queue.shift();
70
- if (!e) return;
71
- let t = !1;
72
- this._currentReleaser = () => {
73
- t || (t = !0, this._value++, this._resolveWaiters(), this._dispatch());
74
- }, e.resolve([this._value--, this._currentReleaser]);
75
- }
76
- _resolveWaiters() {
77
- this._waiters.forEach((e) => e.resolve()), this._waiters = [];
78
- }
79
- }, a = function(e, t, n, r) {
80
- function i(e) {
81
- return e instanceof n ? e : new n(function(t) {
82
- t(e);
83
- });
84
- }
85
- return new (n ||= Promise)(function(n, a) {
86
- function o(e) {
87
- try {
88
- c(r.next(e));
89
- } catch (e) {
90
- a(e);
91
- }
92
- }
93
- function s(e) {
94
- try {
95
- c(r.throw(e));
96
- } catch (e) {
97
- a(e);
98
- }
99
- }
100
- function c(e) {
101
- e.done ? n(e.value) : i(e.value).then(o, s);
102
- }
103
- c((r = r.apply(e, t || [])).next());
104
- });
105
- }, o = class {
106
- constructor(e) {
107
- this._semaphore = new i(1, e);
108
- }
109
- acquire() {
110
- return a(this, void 0, void 0, function* () {
111
- let [, e] = yield this._semaphore.acquire();
112
- return e;
113
- });
114
- }
115
- runExclusive(e) {
116
- return this._semaphore.runExclusive(() => e());
117
- }
118
- isLocked() {
119
- return this._semaphore.isLocked();
120
- }
121
- waitForUnlock() {
122
- return this._semaphore.waitForUnlock();
123
- }
124
- release() {
125
- this._semaphore.release();
126
- }
127
- cancel() {
128
- return this._semaphore.cancel();
129
- }
130
- }, s = function(e, t, n, r) {
131
- function i(e) {
132
- return e instanceof n ? e : new n(function(t) {
133
- t(e);
134
- });
135
- }
136
- return new (n ||= Promise)(function(n, a) {
137
- function o(e) {
138
- try {
139
- c(r.next(e));
140
- } catch (e) {
141
- a(e);
142
- }
143
- }
144
- function s(e) {
145
- try {
146
- c(r.throw(e));
147
- } catch (e) {
148
- a(e);
149
- }
150
- }
151
- function c(e) {
152
- e.done ? n(e.value) : i(e.value).then(o, s);
153
- }
154
- c((r = r.apply(e, t || [])).next());
155
- });
156
- };
157
- function c(t, n, r = e) {
158
- return {
159
- acquire: () => new Promise((e, i) => s(this, void 0, void 0, function* () {
160
- let a = !1, o = setTimeout(() => {
161
- a = !0, i(r);
162
- }, n);
163
- try {
164
- let n = yield t.acquire();
165
- a ? (Array.isArray(n) ? n[1] : n)() : (clearTimeout(o), e(n));
166
- } catch (e) {
167
- a || (clearTimeout(o), i(e));
168
- }
169
- })),
170
- runExclusive(e) {
171
- return s(this, void 0, void 0, function* () {
172
- let t = () => void 0;
173
- try {
174
- let n = yield this.acquire();
175
- return Array.isArray(n) ? (t = n[1], yield e(n[0])) : (t = n, yield e());
176
- } finally {
177
- t();
178
- }
179
- });
180
- },
181
- release() {
182
- t.release();
183
- },
184
- cancel() {
185
- return t.cancel();
186
- },
187
- waitForUnlock: () => t.waitForUnlock(),
188
- isLocked: () => t.isLocked()
189
- };
190
- }
191
- function l(e, n = t) {
192
- return c(e, 0, n);
193
- }
194
- //#endregion
195
- export { t as E_ALREADY_LOCKED, n as E_CANCELED, e as E_TIMEOUT, o as Mutex, i as Semaphore, l as tryAcquire, c as withTimeout };
@@ -1,90 +0,0 @@
1
- //#region src/modeler/boolean-expr.ts
2
- var e = 0, t = class {
3
- and(e) {
4
- return new r("and", [this, e]);
5
- }
6
- or(e) {
7
- return new r("or", [this, e]);
8
- }
9
- implies(e) {
10
- return new r("implies", [this, e]);
11
- }
12
- xor(e) {
13
- return new r("xor", [this, e]);
14
- }
15
- not() {
16
- return new r("not", [this]);
17
- }
18
- }, n = class extends t {
19
- id;
20
- name;
21
- value = null;
22
- constructor(t) {
23
- super(), this.id = ++e, this.name = t || `p_${this.id}`;
24
- }
25
- toString() {
26
- return this.name;
27
- }
28
- }, r = class extends t {
29
- op;
30
- children;
31
- constructor(e, t) {
32
- super(), this.op = e, this.children = t;
33
- }
34
- toString() {
35
- return this.op === "not" ? `not(${this.children[0].toString()})` : `(${this.children.map((e) => e.toString()).join(` ${this.op} `)})`;
36
- }
37
- };
38
- function i(...e) {
39
- if (e.length === 0) throw Error("and() requires at least one expression");
40
- return new r("and", e);
41
- }
42
- function a(...e) {
43
- if (e.length === 0) throw Error("or() requires at least one expression");
44
- return new r("or", e);
45
- }
46
- function o(e) {
47
- return new r("not", [e]);
48
- }
49
- function s(e, t) {
50
- return new r("implies", [e, t]);
51
- }
52
- function c(...e) {
53
- if (e.length === 0) throw Error("xor() requires at least one expression");
54
- return new r("xor", e);
55
- }
56
- //#endregion
57
- //#region src/modeler/constraint.ts
58
- var l = 0, u = class {
59
- id;
60
- lhs;
61
- sense;
62
- rhs;
63
- name;
64
- slack = null;
65
- dual = null;
66
- constructor(e, t, n, r) {
67
- this.id = ++l, this.lhs = e, this.sense = t, this.rhs = n, this.name = r || `c_${this.id}`;
68
- }
69
- and(e) {
70
- return new r("and", [this, e]);
71
- }
72
- or(e) {
73
- return new r("or", [this, e]);
74
- }
75
- implies(e) {
76
- return new r("implies", [this, e]);
77
- }
78
- xor(e) {
79
- return new r("xor", [this, e]);
80
- }
81
- not() {
82
- return new r("not", [this]);
83
- }
84
- toString() {
85
- let e = this.sense === "==" ? "=" : this.sense;
86
- return `${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`;
87
- }
88
- };
89
- //#endregion
90
- export { i as a, a as c, n as i, c as l, t as n, s as o, r, o as s, u as t };
@@ -1,50 +0,0 @@
1
- import { getBundledWasmUrl as e } from "./highs-assets.js";
2
- import { loadNodeHighs as t } from "./highs-node-runtime.js";
3
- //#region src/modeler/solvers/highs/loader.ts
4
- var n = "https://cdn.jsdelivr.net/npm/highs@1.15.3/build/highs.wasm", r = null, i = null, a = null;
5
- function o(e) {
6
- a = e, r = null, i = null;
7
- }
8
- function s() {
9
- return a;
10
- }
11
- function c(e) {
12
- return e.length >= 4 && e[0] === 0 && e[1] === 97 && e[2] === 115 && e[3] === 109;
13
- }
14
- async function l(e) {
15
- try {
16
- let t = await fetch(e, { headers: { Range: "bytes=0-3" } });
17
- if (!t.ok || (t.headers.get("content-type") || "").includes("text/html")) return !1;
18
- if (!t.body) return !0;
19
- let n = t.body.getReader(), { value: r, done: i } = await n.read();
20
- return await n.cancel(), i || !r || r.length < 4 ? !1 : c(r);
21
- } catch {
22
- return !1;
23
- }
24
- }
25
- async function u(t) {
26
- return t || a || e();
27
- }
28
- async function d(e = {}) {
29
- let n = typeof process < "u" && process.versions?.node && process.type !== "renderer", a = n ? null : await u(e.wasmUrl), o = a ?? "node";
30
- if (r && i === o) return r;
31
- i = o;
32
- let s = (async () => {
33
- let e = n ? await t() : (await import("./highs-browser-runtime.js")).default;
34
- return n ? await e() : await e({ locateFile: (e) => e.endsWith(".wasm") ? a : e });
35
- })().catch((e) => {
36
- r === s && (r = null, i = null);
37
- let t = e instanceof Error ? e.message : String(e);
38
- throw Error(`[WaSHI] Failed to initialize HiGHS${a ? ` from "${a}"` : ""}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`, { cause: e });
39
- });
40
- return r = s, s;
41
- }
42
- async function f(e, t = {}) {
43
- let n = await d(t), r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
44
- return t.timeLimit !== void 0 && (i.time_limit = t.timeLimit), t.presolve !== void 0 && (i.presolve = t.presolve), t.solver !== void 0 && (i.solver = t.solver), t.relGap !== void 0 && (i.mip_rel_gap = t.relGap), t.absGap !== void 0 && (i.mip_abs_gap = t.absGap), {
45
- result: n.solve(e, i),
46
- runTime: (performance.now() - r) / 1e3
47
- };
48
- }
49
- //#endregion
50
- export { l as a, f as c, c as i, d as n, u as o, s as r, o as s, n as t };
@@ -1,32 +0,0 @@
1
- //#region src/modeler/solvers/registry.ts
2
- var e = Symbol.for("washi.solverRegistry"), t = Symbol.for("washi.defaultSolverFactory"), n = globalThis;
3
- n[e] || (n[e] = /* @__PURE__ */ new Map());
4
- var r = n[e];
5
- function i(e, t) {
6
- r.set(e.toLowerCase(), t);
7
- }
8
- function a(e) {
9
- if (typeof e == "string") {
10
- let i = r.get(e.toLowerCase());
11
- if (!i) throw Error(`Solver '${e}' is not registered.`);
12
- n[t] = i;
13
- } else n[t] = typeof e == "function" ? e : () => e;
14
- }
15
- function o(e, i) {
16
- if (!e) {
17
- let e = n[t] || r.get("highs");
18
- if (!e) throw Error(`No default solver available. Available solvers: ${s().join(", ")}`);
19
- return e(i);
20
- }
21
- if (typeof e == "string") {
22
- let t = e.toLowerCase(), n = r.get(t);
23
- if (!n) throw Error(t === "glpk" ? `Solver 'glpk' not found. Available solvers: ${s().join(", ")}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.` : t === "z3" ? `Solver 'z3' not found. Available solvers: ${s().join(", ")}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.` : `Solver '${e}' not found. Available solvers: ${s().join(", ")}`);
24
- return n(i);
25
- }
26
- return e;
27
- }
28
- function s() {
29
- return Array.from(r.keys());
30
- }
31
- //#endregion
32
- export { a as i, s as n, i as r, o as t };