@ohtaman/washi 0.7.0 → 0.8.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.
- package/README.ja.md +58 -19
- package/README.md +58 -19
- package/README.zh-CN.md +58 -19
- package/THIRD_PARTY_LICENSES.md +34 -1
- package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
- package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
- package/dist/browser/highs-worker.js +26 -11
- package/dist/browser/highs.wasm +0 -0
- package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
- package/dist/browser/solvers/glpk.js +289 -238
- package/dist/browser/solvers/glpk.min.js +1 -1
- package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
- package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
- package/dist/browser/solvers/pumpkin-worker.js +45 -0
- package/dist/browser/solvers/pumpkin.js +1777 -0
- package/dist/browser/solvers/pumpkin.min.js +1 -0
- package/dist/browser/solvers/pumpkin.wasm +0 -0
- package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/browser/solvers/z3.js +1600 -1335
- package/dist/browser/solvers/z3.min.js +2 -2
- package/dist/browser/washi.js +3374 -1377
- package/dist/browser/washi.min.js +5 -3
- package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
- package/dist/lib/highs-browser-runtime.js +1846 -1618
- package/dist/lib/highs-runtime.js +16 -2
- package/dist/lib/highs-worker.js +26 -11
- package/dist/lib/highs.wasm +0 -0
- package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
- package/dist/lib/registry-dx7x4e5c.js +1694 -0
- package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
- package/dist/lib/solvers/glpk.js +161 -121
- package/dist/lib/solvers/pumpkin-assets.js +1 -0
- package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
- package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
- package/dist/lib/solvers/pumpkin-worker.js +45 -0
- package/dist/lib/solvers/pumpkin.js +1767 -0
- package/dist/lib/solvers/pumpkin.wasm +0 -0
- package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/lib/solvers/z3.js +486 -306
- package/dist/lib/washi.js +2563 -1154
- package/dist/types/decomposition/benders.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/boolean-expr.d.ts +137 -29
- package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
- package/dist/types/modeler/constraint.d.ts +40 -4
- package/dist/types/modeler/constraint.d.ts.map +1 -1
- package/dist/types/modeler/expression.d.ts +129 -2
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +4 -5
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/linearizer.d.ts +11 -2
- package/dist/types/modeler/linearizer.d.ts.map +1 -1
- package/dist/types/modeler/lp-writer.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +85 -124
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +8 -2
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/solution-validator.d.ts +12 -12
- package/dist/types/modeler/solution-validator.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
- package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/mock.d.ts +2 -3
- package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +7 -9
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +12 -15
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/validation.d.ts +26 -2
- package/dist/types/modeler/validation.d.ts.map +1 -1
- package/dist/types/modeler/variable.d.ts +9 -5
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/docs/examples/index.md +6 -1
- package/docs/examples/project-scheduling.md +106 -0
- package/docs/examples/shift-scheduling.md +3 -0
- package/docs/examples/smt-security.md +1 -0
- package/docs/examples/traveling-salesperson.md +1 -1
- package/docs/examples/unsat-core.md +3 -2
- package/docs/getting-started/ai-agents.md +94 -25
- package/docs/getting-started/coding-agents.md +158 -0
- package/docs/getting-started/cross-origin.md +2 -2
- package/docs/getting-started/index.md +40 -41
- package/docs/getting-started/runtimes.md +42 -18
- package/docs/guide/constraint-programming.md +141 -0
- package/docs/guide/constraints.md +64 -14
- package/docs/guide/decomposition.md +59 -59
- package/docs/guide/expressions.md +42 -10
- package/docs/guide/formulation-tips.md +6 -6
- package/docs/guide/objectives.md +65 -62
- package/docs/guide/unsat-core.md +36 -27
- package/docs/guide/variables.md +30 -17
- package/docs/solvers/custom-solver.md +18 -13
- package/docs/solvers/highs.md +18 -23
- package/docs/solvers/index.md +12 -6
- package/docs/solvers/pumpkin.md +163 -0
- package/docs/solvers/z3.md +2 -2
- package/llms-full.txt +944 -314
- package/llms.txt +43 -22
- package/package.json +38 -11
- package/skills/washi/SKILL.md +79 -27
- package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
- package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
- package/docs/ja/getting-started/ai-agents.md +0 -280
- package/docs/zh/getting-started/ai-agents.md +0 -280
|
@@ -2,24 +2,11 @@ import type { CheckModelData, SolveModelData, Solver, SolverCapabilities, Solver
|
|
|
2
2
|
import { type LpExportResult, type LpModelData } from "../../lp-writer.js";
|
|
3
3
|
import { resetZ3LoaderCache, killZ3Threads, notifyZ3WorkerError } from "./loader.js";
|
|
4
4
|
export { resetZ3LoaderCache, killZ3Threads, notifyZ3WorkerError };
|
|
5
|
-
/**
|
|
6
|
-
* Z3 SMT / SAT / MIP Solver Adapter
|
|
7
|
-
*
|
|
8
|
-
* Supports:
|
|
9
|
-
* - SAT & SMT logical formulas (And, Or, Not, Implies, Xor)
|
|
10
|
-
* - Feasibility checking via check()
|
|
11
|
-
* - Unsatisfiable core extraction (unsatCore) for conflict diagnosis
|
|
12
|
-
* - Mixed-Integer Programming (MIP) optimization via Z3 Optimize
|
|
13
|
-
*
|
|
14
|
-
* Solution metrics provided by Z3:
|
|
15
|
-
* - `status` and `terminationStatus`: `"Optimal" | "Infeasible" | "Error"`
|
|
16
|
-
* - `hasPrimalSolution`: `true` when Z3 returns `"sat"` (`status === "Optimal"`), `false` otherwise.
|
|
17
|
-
* - `objectiveValue`: Primal objective value when `hasPrimalSolution` is `true`, otherwise `null`.
|
|
18
|
-
* - `objectiveBound`, `relGap` (`mipGap`), `absGap`: Z3 Optimize is an SMT optimization engine and does not expose branch-and-bound MIP dual bounds or relative/absolute MIP gaps, so these fields are intentionally left `undefined` rather than returning invented defaults.
|
|
19
|
-
*/
|
|
20
5
|
export declare class Z3Solver implements Solver {
|
|
21
6
|
readonly name = "z3";
|
|
7
|
+
readonly options: SolverOptions;
|
|
22
8
|
readonly capabilities: SolverCapabilities;
|
|
9
|
+
constructor(options?: SolverOptions);
|
|
23
10
|
/**
|
|
24
11
|
* Helper to build AST translations for a given Z3 Context
|
|
25
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solver.d.ts","sourceRoot":"","sources":["../../../../../src/modeler/solvers/z3/solver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"solver.d.ts","sourceRoot":"","sources":["../../../../../src/modeler/solvers/z3/solver.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,iBAAiB,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAU,kBAAkB,EAAE,aAAa,EAA0B,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErH,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC;AAwFlE,qBAAa,QAAS,YAAW,MAAM;IACrC,QAAQ,CAAC,IAAI,QAAQ;IACrB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAOvC;IAEF,YAAY,OAAO,GAAE,aAAkB,EAEtC;IAED;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAwc/B,OAAO,CAAC,iBAAiB;YAqBX,wBAAwB;IAgBtC;;;OAGG;IACG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+H9F;IAED;;OAEG;IACG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACjF,KAAK,CACT,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,cAAc,EACxB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CAAC;CAkT1B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
|
@@ -9,7 +9,7 @@ export type OptimizationSense = "Minimize" | "Maximize" | "minimize" | "maximize
|
|
|
9
9
|
* Throws a descriptive error if an invalid sense string is provided at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export declare function normalizeSense(sense?: OptimizationSense): "Maximize" | "Minimize";
|
|
12
|
-
export type ComparisonSense = "<=" | ">=" | "==";
|
|
12
|
+
export type ComparisonSense = "<=" | ">=" | "==" | "!=";
|
|
13
13
|
export type SolverStatus = "Optimal" | "Feasible" | "Infeasible" | "Unbounded" | "TimeLimit" | "IterationLimit" | "Error" | "NotSolved" | "Sat" | "Unsat" | "Unknown";
|
|
14
14
|
export type TerminationStatus = "Optimal" | "Feasible" | "Infeasible" | "Unbounded" | "InfeasibleOrUnbounded" | "TimeLimit" | "IterationLimit" | "SolutionLimit" | "MemoryLimit" | "ObjectiveBound" | "ObjectiveTarget" | "Interrupted" | "Error" | "NotSolved" | "Sat" | "Unsat" | "Unknown";
|
|
15
15
|
export interface SolveProgressEvent {
|
|
@@ -24,11 +24,9 @@ export interface SolveProgressEvent {
|
|
|
24
24
|
/** Best proven dual / objective bound when available */
|
|
25
25
|
objectiveBound?: number;
|
|
26
26
|
/** Relative MIP optimality gap when available */
|
|
27
|
-
|
|
28
|
-
/** Alias for relGap: relative MIP optimality gap when available */
|
|
29
|
-
mipGap?: number;
|
|
27
|
+
relativeGap?: number;
|
|
30
28
|
/** Absolute MIP optimality gap |objectiveValue - objectiveBound| when available */
|
|
31
|
-
|
|
29
|
+
absoluteGap?: number;
|
|
32
30
|
/** Explored MIP branch-and-bound node count when available */
|
|
33
31
|
nodes?: number;
|
|
34
32
|
/** Solver iteration count (simplex, IPM, or MIP LP iterations) when available */
|
|
@@ -41,16 +39,17 @@ export interface SolveOptions {
|
|
|
41
39
|
outputFlag?: boolean;
|
|
42
40
|
presolve?: "on" | "off" | "choose";
|
|
43
41
|
solver?: any;
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
relativeGap?: number;
|
|
43
|
+
absoluteGap?: number;
|
|
46
44
|
wasmUrl?: string;
|
|
47
45
|
/**
|
|
48
46
|
* AbortSignal to cancel a solve:
|
|
49
47
|
* - Pre-solve cancellation (`signal.aborted` before execution starts) is supported by all solvers.
|
|
50
|
-
* - Preemptive mid-solve cancellation is supported in browser HiGHS via Web Worker
|
|
51
|
-
* (and cancels queued Worker requests before they are dispatched).
|
|
52
|
-
* - Main-thread (Node.js) HiGHS
|
|
53
|
-
* triggered synchronously inside an `onProgress` callback
|
|
48
|
+
* - Preemptive mid-solve cancellation is supported in browser HiGHS and Pumpkin via Web Worker
|
|
49
|
+
* termination (and cancels queued Worker requests before they are dispatched).
|
|
50
|
+
* - Main-thread (Node.js) HiGHS and Pumpkin support cooperative mid-solve cancellation (`abort()`
|
|
51
|
+
* triggered synchronously inside an `onProgress` callback for HiGHS; `should_abort` solver
|
|
52
|
+
* interrupt checkpoints for Pumpkin).
|
|
54
53
|
* - Single-threaded WASM solvers without interrupt hooks (GLPK, Z3) check `signal` before execution starts.
|
|
55
54
|
*/
|
|
56
55
|
signal?: AbortSignal;
|
|
@@ -70,11 +69,9 @@ export interface SolverSolution {
|
|
|
70
69
|
/** Best proven dual/objective bound when provided by the solver */
|
|
71
70
|
objectiveBound?: number;
|
|
72
71
|
/** Relative MIP optimality gap when provided by the solver */
|
|
73
|
-
|
|
74
|
-
/** Alias for relGap: relative MIP optimality gap when provided by the solver */
|
|
75
|
-
mipGap?: number;
|
|
72
|
+
relativeGap?: number;
|
|
76
73
|
/** Absolute MIP optimality gap |objectiveValue - objectiveBound| when provided by the solver */
|
|
77
|
-
|
|
74
|
+
absoluteGap?: number;
|
|
78
75
|
values: Record<string, number>;
|
|
79
76
|
duals: Record<string, number>;
|
|
80
77
|
reducedCosts: Record<string, number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modeler/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AAEH,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,MAAM,GACN,KAAK,GACL,KAAK,CAAC;AAEV,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,UAAU,GAAG,UAAU,CAUjF;AAGD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modeler/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AAEH,MAAM,MAAM,OAAO,GACf,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,MAAM,GACN,KAAK,GACL,KAAK,CAAC;AAEV,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,UAAU,GAAG,UAAU,CAUjF;AAGD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExD,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,UAAU,GACV,YAAY,GACZ,WAAW,GACX,WAAW,GACX,gBAAgB,GAChB,OAAO,GACP,WAAW,GACX,KAAK,GACL,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,UAAU,GACV,YAAY,GACZ,WAAW,GACX,uBAAuB,GACvB,WAAW,GACX,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,OAAO,GACP,WAAW,GACX,KAAK,GACL,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,cAAc,CAAC,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AAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type { Model } from "./model.js";
|
|
1
|
+
import type { Model, LogicalConstraint } from "./model.js";
|
|
2
2
|
import { Var } from "./variable.js";
|
|
3
3
|
import { BoolVar, type LogicElement } from "./boolean-expr.js";
|
|
4
4
|
import { Constraint } from "./constraint.js";
|
|
5
5
|
import { LinExpr } from "./expression.js";
|
|
6
6
|
import { QuadExpr } from "./quad-expr.js";
|
|
7
|
+
/**
|
|
8
|
+
* Registers an internal mutation callback for a Model instance.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerModelMutationCallback(model: object, onMutate: () => void): void;
|
|
11
|
+
/**
|
|
12
|
+
* Notifies an owning model that one of its entities was mutated.
|
|
13
|
+
*/
|
|
14
|
+
export declare function notifyModelMutation(ownerModel: object | null | undefined): void;
|
|
7
15
|
/**
|
|
8
16
|
* Recursively attaches ownerModel mutation tracking to any Constraint nodes embedded in a logical expression.
|
|
9
17
|
*/
|
|
@@ -49,8 +57,24 @@ export declare function validateLinearConstraint(c: Constraint, modelName: strin
|
|
|
49
57
|
* Validates a logical constraint element recursively.
|
|
50
58
|
*/
|
|
51
59
|
export declare function validateLogicElement(elem: LogicElement, lcName: string, modelName: string, isOwnedVar: (v: Var) => boolean, isOwnedBoolVar: (bv: BoolVar) => boolean, ownerModel?: Model): void;
|
|
60
|
+
/**
|
|
61
|
+
* Internal snapshot passed to `validateModelIntegrity` so `Model` keeps backing arrays and lookup maps private.
|
|
62
|
+
*/
|
|
63
|
+
export interface ModelIntegritySnapshot {
|
|
64
|
+
model: Model;
|
|
65
|
+
name: string;
|
|
66
|
+
variables: readonly Var[];
|
|
67
|
+
boolVars: readonly BoolVar[];
|
|
68
|
+
constraints: readonly Constraint[];
|
|
69
|
+
logicalConstraints: readonly LogicalConstraint[];
|
|
70
|
+
objectiveExpr: LinExpr | QuadExpr;
|
|
71
|
+
getVarByName: (name: string) => Var | undefined;
|
|
72
|
+
getBoolVarByName: (name: string) => BoolVar | undefined;
|
|
73
|
+
getConstraintByName: (name: string) => Constraint | undefined;
|
|
74
|
+
getLogicalConstraintByName: (name: string) => LogicalConstraint | undefined;
|
|
75
|
+
}
|
|
52
76
|
/**
|
|
53
77
|
* Validates the structural and numerical integrity of an optimization model.
|
|
54
78
|
*/
|
|
55
|
-
export declare function validateModelIntegrity(
|
|
79
|
+
export declare function validateModelIntegrity(snapshot: ModelIntegritySnapshot): void;
|
|
56
80
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/modeler/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/modeler/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAsD,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAEvF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAI/E;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,KAAK,EACZ,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,OAAO,EAC/B,cAAc,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,EACxC,UAAU,CAAC,EAAE,KAAK,GACjB,IAAI,CA6EN;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC;IAC1B,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IACnC,kBAAkB,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACjD,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,GAAG,SAAS,CAAC;IAChD,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAC;IACxD,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAC;IAC9D,0BAA0B,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,iBAAiB,GAAG,SAAS,CAAC;CAC7E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAmG7E"}
|
|
@@ -11,7 +11,7 @@ export interface VarOptions {
|
|
|
11
11
|
/**
|
|
12
12
|
* Optional finite primal initial value (MIP start / warm-start hint), distinct from solved `Var.value`.
|
|
13
13
|
* Validated within tolerance `1e-6` against `[lb, ub]` and integer/binary domains.
|
|
14
|
-
* Supported by HiGHS (`supportsWarmStart: true`); throws on solvers without warm-start support (GLPK, Z3).
|
|
14
|
+
* Supported by HiGHS and Pumpkin (`supportsWarmStart: true`); throws on solvers without warm-start support (GLPK, Z3).
|
|
15
15
|
*/
|
|
16
16
|
initialValue?: number;
|
|
17
17
|
}
|
|
@@ -33,9 +33,7 @@ export declare class Var {
|
|
|
33
33
|
private _name;
|
|
34
34
|
readonly prefix: string;
|
|
35
35
|
hasExplicitName: boolean;
|
|
36
|
-
ownerModel:
|
|
37
|
-
notifyMutation?: () => void;
|
|
38
|
-
} | null;
|
|
36
|
+
ownerModel: object | null;
|
|
39
37
|
private _type;
|
|
40
38
|
private _lb;
|
|
41
39
|
private _ub;
|
|
@@ -54,7 +52,7 @@ export declare class Var {
|
|
|
54
52
|
set ub(val: number);
|
|
55
53
|
/**
|
|
56
54
|
* Optional finite primal initial value (MIP start / warm-start hint), distinct from solved `Var.value`.
|
|
57
|
-
* Supported by HiGHS (`supportsWarmStart: true`); throws on solvers without warm-start support (GLPK, Z3).
|
|
55
|
+
* Supported by HiGHS and Pumpkin (`supportsWarmStart: true`); throws on solvers without warm-start support (GLPK, Z3).
|
|
58
56
|
*/
|
|
59
57
|
get initialValue(): number | undefined;
|
|
60
58
|
set initialValue(val: number | undefined);
|
|
@@ -82,6 +80,12 @@ export declare class Var {
|
|
|
82
80
|
ge(rhs: number | Var | LinExpr | QuadExpr | Constraint, name?: string): Constraint;
|
|
83
81
|
/** Create an equality constraint: this == rhs */
|
|
84
82
|
eq(rhs: number | Var | LinExpr | QuadExpr | Constraint, name?: string): Constraint;
|
|
83
|
+
/** Create a discrete strict less-than constraint: this < rhs (normalized to this <= rhs - 1) */
|
|
84
|
+
lt(rhs: number | Var | LinExpr | QuadExpr | Constraint, name?: string): Constraint;
|
|
85
|
+
/** Create a discrete strict greater-than constraint: this > rhs (normalized to this >= rhs + 1) */
|
|
86
|
+
gt(rhs: number | Var | LinExpr | QuadExpr | Constraint, name?: string): Constraint;
|
|
87
|
+
/** Create a discrete not-equal constraint: this != rhs */
|
|
88
|
+
ne(rhs: number | Var | LinExpr | QuadExpr | Constraint, name?: string): Constraint;
|
|
85
89
|
toString(): string;
|
|
86
90
|
}
|
|
87
91
|
//# sourceMappingURL=variable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../../src/modeler/variable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAeD;;;;;;;;;;;;GAYG;AACH,qBAAa,GAAG;IACd,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,SAAgB,MAAM,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE
|
|
1
|
+
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../../src/modeler/variable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,YAAY,CAAC,E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E,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAEjF;IAED,mGAAmG;IACnG,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAEjF;IAED,0DAA0D;IAC1D,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAEjF;IAED,QAAQ,IAAI,MAAM,CAEjB;CACF"}
|
package/docs/examples/index.md
CHANGED
|
@@ -4,7 +4,7 @@ Explore runnable optimization and logic formulations built with WaSHI. Every exa
|
|
|
4
4
|
|
|
5
5
|
## Examples
|
|
6
6
|
|
|
7
|
-
| Example | Problem Class | Solver | Key WaSHI APIs | Description |
|
|
7
|
+
| Example | Problem Class | Solver | Key WaSHI APIs | Description | Playground / Guide |
|
|
8
8
|
| :--- | :--- | :--- | :--- | :--- | :--- |
|
|
9
9
|
| **[Production Planning](./production.md)** | LP / MIP | HiGHS | `m.integer()`, `m.constraint()`, `expr` | Basic variables, tagged template literal equations, and maximizing profit under resource limits. | [Playground](https://washi.ohtaman.dev/demo/?preset=production) |
|
|
10
10
|
| **[0-1 Knapsack](./knapsack.md)** | Binary MIP | HiGHS | `m.binary(keys)`, `expr` (`dot`), `m.constraint()` | 1D dictionary of `Binary` variables and linear aggregation over item arrays. | [Playground](https://washi.ohtaman.dev/demo/?preset=knapsack) |
|
|
@@ -13,6 +13,7 @@ Explore runnable optimization and logic formulations built with WaSHI. Every exa
|
|
|
13
13
|
| **[Staff Shift Scheduling](./shift-scheduling.md)** | Binary MIP + Unsat Core | HiGHS + Z3 | `m.binary(staff, days)`, `check()`, `unsatCore` | 5×7 weekly roster planner (coverage, senior duty, max shifts, day-off requests) and diagnosing conflicting vacation requests with Z3 `unsatCore`. | [Playground](https://washi.ohtaman.dev/demo/?preset=shift_scheduling) |
|
|
14
14
|
| **[E-Commerce Coupon Optimizer](./ecommerce-coupons.md)** | Indicator MIP | HiGHS | `m.indicator()`, `expr` (`sum`, `dot`), `m.constraint()` | Checkout optimizer using `m.indicator()` for minimum spend thresholds, exclusive vs. stackable rules, and smart filler add-on suggestions. | [Playground](https://washi.ohtaman.dev/demo/?preset=cart_coupon) |
|
|
15
15
|
| **[Portfolio Optimization](./portfolio-qp.md)** | Convex QP | HiGHS | `m.continuous()`, `m.constraint()`, `dot()`, `QuadExpr` | Markowitz mean-variance risk minimization ($w^T \Sigma w$) using `QuadExpr` subject to return targets. | [Playground](https://washi.ohtaman.dev/demo/?preset=portfolio_qp) |
|
|
16
|
+
| **[Project Scheduling (RCPSP)](./project-scheduling.md)** | CP / LCG + Unsat Core | Pumpkin | `m.integer()`, `disjoint()`, `cumulative()`, `max()`, `m.check()` | 6-task resource-constrained schedule (unary rig + 3-engineer crew limit) and zero-`COOP`/`COEP` `unsatCore` deadline conflict check. | [Playground](https://washi.ohtaman.dev/demo/?preset=project_scheduling) |
|
|
16
17
|
| **[SMT Security Policies](./smt-security.md)** | SMT Logic | Z3 | `m.bool()`, `m.constraint()`, `m.check()` | Propositional variables (`BoolVar`) and logical connectives (`implies`, `and`, `not`, `xor`) mixed with integer bounds. | [Playground](https://washi.ohtaman.dev/demo/?preset=smt_security) |
|
|
17
18
|
| **[Conflict Diagnosis (`unsatCore`)](./unsat-core.md)** | Unsat Core | Z3 | `m.constraint()`, `m.check()`, `m.unsatCore` | Extracting a conflicting constraint subset (`unsatCore`) when staffing and budget rules contradict each other. | [Playground](https://washi.ohtaman.dev/demo/?preset=conflict_diagnosis_unsat) |
|
|
18
19
|
| **[Vehicle Routing (CVRP)](./vehicle-routing.md)** | Combinatorial OR / Dantzig-Wolfe | HiGHS | `m.solveColumnGeneration()`, `pricing` | Dynamic route column generation from customer dual shadow prices to minimize total fleet vehicles. | [Decomposition Guide](../guide/decomposition.md) |
|
|
@@ -36,6 +37,9 @@ Looking for a specific modeling method or solver capability? Jump straight to th
|
|
|
36
37
|
| `m.check()` & `m.unsatCore` | Feasibility check & conflict diagnosis | [Conflict Diagnosis](./unsat-core.md), [Shift Scheduling](./shift-scheduling.md) | [`05-unsat-core-diagnosis.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/05-unsat-core-diagnosis.ts) |
|
|
37
38
|
| `m.solveColumnGeneration()` | Dantzig-Wolfe Column Generation | [Vehicle Routing](./vehicle-routing.md) | [`13-vehicle-routing-column-generation.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/13-vehicle-routing-column-generation.ts) |
|
|
38
39
|
| `m.solveBenders()` | Benders Decomposition & cut separation | [Traveling Salesperson](./traveling-salesperson.md) | [`14-traveling-salesperson-benders.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/14-traveling-salesperson-benders.ts) |
|
|
40
|
+
| `distinct()` / `disjoint()` / `cumulative()` / `allowed()` | Backend-agnostic CP global constraints | [Project Scheduling](./project-scheduling.md), [CP Modeling Guide](../guide/constraint-programming.md) | [`15-project-scheduling-cp.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/15-project-scheduling-cp.ts) |
|
|
41
|
+
| `max()` / `min()` / `abs()` / `at()` | Piecewise-linear & element lookup primitives | [Project Scheduling](./project-scheduling.md), [Expressions Guide](../guide/expressions.md) | [`15-project-scheduling-cp.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/15-project-scheduling-cp.ts) |
|
|
42
|
+
| `solver: "pumpkin"` | Bundled CP/LCG scheduling & zero-`COOP`/`COEP` `unsatCore` | [Project Scheduling](./project-scheduling.md), [Pumpkin Solver Guide](../solvers/pumpkin.md) | [`15-project-scheduling-cp.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/15-project-scheduling-cp.ts) |
|
|
39
43
|
| `solver: "glpk"` | Solving LP/MIP with GLPK plugin | [GLPK Solver Guide](../solvers/glpk.md) | [`08-glpk-solver-plugin.ts`](https://github.com/ohtaman/washi/blob/main/examples/node/08-glpk-solver-plugin.ts) |
|
|
40
44
|
|
|
41
45
|
## Running Examples Locally in Node.js
|
|
@@ -56,4 +60,5 @@ npx tsx examples/node/11-shift-scheduling.ts
|
|
|
56
60
|
npx tsx examples/node/12-ecommerce-coupon-optimizer.ts
|
|
57
61
|
npx tsx examples/node/13-vehicle-routing-column-generation.ts
|
|
58
62
|
npx tsx examples/node/14-traveling-salesperson-benders.ts
|
|
63
|
+
npx tsx examples/node/15-project-scheduling-cp.ts
|
|
59
64
|
```
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Resource-Constrained Project Scheduling (CP / Pumpkin)
|
|
2
|
+
|
|
3
|
+
| Problem Class | Solver | Key APIs | Links |
|
|
4
|
+
| :--- | :--- | :--- | :--- |
|
|
5
|
+
| CP / LCG (RCPSP & Unsat Core) | Pumpkin (`@ohtaman/washi/solvers/pumpkin`) | `m.integer()`, `disjoint()`, `cumulative()`, `max()`, `and()`, `m.check()` | <ul><li><a href="https://washi.ohtaman.dev/demo/?preset=project_scheduling">Playground (Schedule)</a></li><li><a href="https://washi.ohtaman.dev/demo/?preset=project_conflict_unsat">Playground (Conflict)</a></li><li><a href="https://github.com/ohtaman/washi/blob/main/examples/node/15-project-scheduling-cp.ts">Source Code</a></li><li><a href="/guide/constraint-programming">CP Modeling Guide</a></li></ul> |
|
|
6
|
+
|
|
7
|
+
The **Resource-Constrained Project Scheduling Problem (RCPSP)** models project tasks governed simultaneously by **precedence dependencies**, **unary shared equipment** (disjunctive resource), and **limited renewable team headcount** (cumulative resource).
|
|
8
|
+
|
|
9
|
+
Using WaSHI's bundled **Pumpkin** solver (`@ohtaman/washi/solvers/pumpkin`):
|
|
10
|
+
1. Every task needs only **one finite-domain start variable** (`start[task]`), avoiding $O(|T| \cdot H)$ time-indexed binary variables.
|
|
11
|
+
2. When adding tighter maintenance windows or rush shipping deadlines causes infeasibility, `m.check()` extracts the conflicting rule subset (`unsatCore`) client-side with **zero `COOP` / `COEP` headers**.
|
|
12
|
+
|
|
13
|
+
## Problem Inputs
|
|
14
|
+
|
|
15
|
+
We schedule **6 hardware prototype tasks** over a 24-hour window (`crewCapacity = 3` engineers, 1 shared Hardware-in-the-Loop (HIL) calibration rig):
|
|
16
|
+
|
|
17
|
+
| Task | Duration | Crew | Dependencies | Shared Rig (`disjoint`) |
|
|
18
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
19
|
+
| `chassis` | 4h | 2 | — | No |
|
|
20
|
+
| `board` | 3h | 2 | — | No |
|
|
21
|
+
| `firmware` | 4h | 1 | — | **Yes** |
|
|
22
|
+
| `assembly` | 3h | 2 | `chassis`, `board` | No |
|
|
23
|
+
| `calib` | 3h | 1 | `board` | **Yes** |
|
|
24
|
+
| `test` | 2h | 2 | `assembly`, `firmware`, `calib` | **Yes** |
|
|
25
|
+
|
|
26
|
+
Notice that ignoring crew capacity gives a naive critical path of `9h` (`chassis 4h -> assembly 3h -> test 2h`), whereas respecting the `crewCapacity = 3` constraint prevents `{chassis, board, assembly}` (2 engineers each) from overlapping, making the true minimum makespan **`12h`**.
|
|
27
|
+
|
|
28
|
+
## Implementation in WaSHI
|
|
29
|
+
|
|
30
|
+
<CodeRunner preset="project_scheduling">
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Model, expr, disjoint, cumulative, max, and, minimize } from "@ohtaman/washi";
|
|
34
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
35
|
+
|
|
36
|
+
async function runProjectScheduling() {
|
|
37
|
+
const horizon = 24;
|
|
38
|
+
const crewCapacity = 3;
|
|
39
|
+
const tasks = [
|
|
40
|
+
{ id: "chassis", duration: 4, crew: 2, usesRig: false },
|
|
41
|
+
{ id: "board", duration: 3, crew: 2, usesRig: false },
|
|
42
|
+
{ id: "firmware", duration: 4, crew: 1, usesRig: true },
|
|
43
|
+
{ id: "assembly", duration: 3, crew: 2, usesRig: false },
|
|
44
|
+
{ id: "calib", duration: 3, crew: 1, usesRig: true },
|
|
45
|
+
{ id: "test", duration: 2, crew: 2, usesRig: true },
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
const m = new Model("PrototypeRCPSP", { solver: "pumpkin" });
|
|
49
|
+
const start = m.integer(tasks.map((t) => t.id), { lb: 0, ub: horizon, prefix: "start" });
|
|
50
|
+
|
|
51
|
+
// 1. Precedence network
|
|
52
|
+
m.constraint(expr`${start.chassis} + 4 <= ${start.assembly}`, "assembly_after_chassis");
|
|
53
|
+
m.constraint(expr`${start.board} + 3 <= ${start.assembly}`, "assembly_after_board");
|
|
54
|
+
m.constraint(expr`${start.board} + 3 <= ${start.calib}`, "calib_after_board");
|
|
55
|
+
m.constraint(expr`${start.assembly} + 3 <= ${start.test}`, "test_after_assembly");
|
|
56
|
+
m.constraint(expr`${start.firmware} + 4 <= ${start.test}`, "test_after_firmware");
|
|
57
|
+
m.constraint(expr`${start.calib} + 3 <= ${start.test}`, "test_after_calib");
|
|
58
|
+
|
|
59
|
+
// 2. Exclusive HIL / calibration rig & 3-engineer cumulative limit
|
|
60
|
+
m.constraint(
|
|
61
|
+
disjoint(tasks.filter((t) => t.usesRig).map((t) => ({ start: start[t.id], duration: t.duration }))),
|
|
62
|
+
"single_rig"
|
|
63
|
+
);
|
|
64
|
+
m.constraint(
|
|
65
|
+
cumulative(
|
|
66
|
+
tasks.map((t) => ({ start: start[t.id], duration: t.duration, demand: t.crew })),
|
|
67
|
+
crewCapacity
|
|
68
|
+
),
|
|
69
|
+
"crew_limit"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// 3. Minimize project makespan: max_t (start[t] + duration[t])
|
|
73
|
+
const makespan = max(tasks.map((t) => expr`${start[t.id]} + ${t.duration}`));
|
|
74
|
+
m.objective(minimize(makespan));
|
|
75
|
+
|
|
76
|
+
const status = await m.solve();
|
|
77
|
+
const optMakespan = m.objectiveValue;
|
|
78
|
+
const report = m.verify();
|
|
79
|
+
console.log(`Status: ${status} (valid: ${report.valid}), Minimum Makespan: ${optMakespan}h`);
|
|
80
|
+
for (const t of tasks) {
|
|
81
|
+
const s = start[t.id].value ?? 0;
|
|
82
|
+
console.log(` ${t.id}: [${s}h, ${s + t.duration}h) crew=${t.crew}${t.usesRig ? " [Rig]" : ""}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 4. Diagnose an impossible rush deadline when the rig is offline for maintenance [0, 6)
|
|
86
|
+
m.constraint(
|
|
87
|
+
and(expr`${start.firmware} >= 6`, expr`${start.calib} >= 6`),
|
|
88
|
+
"rig_maintenance_window"
|
|
89
|
+
);
|
|
90
|
+
m.constraint(expr`${makespan} <= 13`, "rush_ship_deadline");
|
|
91
|
+
|
|
92
|
+
const diag = await m.check();
|
|
93
|
+
console.log(`Deadline Check: ${diag.status}`);
|
|
94
|
+
console.log(`Unsat Core: ${(diag.unsatCore ?? []).join(", ")}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
runProjectScheduling();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
</CodeRunner>
|
|
101
|
+
|
|
102
|
+
## Practical Notes
|
|
103
|
+
|
|
104
|
+
- **Why Pumpkin shines here**: Combining `disjoint` (edge-finding) and `cumulative` (time-table propagation) directly on bounded integers lets Pumpkin learn why a schedule bottlenecks (`crew_limit` or `single_rig`) cleanly through Lazy Clause Generation, with zero time-indexed binary variables.
|
|
105
|
+
- **Snapshot `m.objectiveValue` before `m.check()`**: Calling `await m.check()` on the same `Model` clears prior `solve()` fields (`m.objectiveValue` becomes `null`), so capture optimization outputs before running feasibility/conflict checks.
|
|
106
|
+
- **Client-side `unsatCore` without `COOP` / `COEP`**: Notice that `diag.unsatCore` excludes unrelated `crew_limit` while isolating the rig maintenance (`firmware >= 6`, `calib >= 6`), `assembly -> test` chain (`test >= 7`), unary `single_rig` total of 9h ($\implies \text{completion} \ge 15 > 13$), and `rush_ship_deadline`.
|
|
@@ -186,3 +186,6 @@ m.objective(minimize(expr`dot(${costMatrix}, ${shift}) + 500 * sum(${requestedSh
|
|
|
186
186
|
```
|
|
187
187
|
|
|
188
188
|
With this soft formulation on Scenario B, HiGHS automatically finds a valid roster that honors 3 of the 4 requests (`Alice (Sat)`, `Charlie (Sat)`, and `Diana (Wed)`) and overrides only `Bob (Sat)`—choosing Bob over Alice because Bob's daily wage (`$210`) is `$10` lower than Alice's (`$220`).
|
|
189
|
+
|
|
190
|
+
> [!TIP]
|
|
191
|
+
> **Diagnosing `unsatCore` Without `COOP` / `COEP` Headers**: Because every variable in this roster model is a 0-1 binary (`m.binary(...)`) with integer coefficients, you can also run `await model.check({ solver: "pumpkin" })` (after `import "@ohtaman/washi/solvers/pumpkin"`) to extract `unsatCore` in standard browser environments without `COOP` / `COEP` headers or external peer dependencies.
|
|
@@ -84,3 +84,4 @@ verifySecurityRules();
|
|
|
84
84
|
|
|
85
85
|
- **Proof by Refutation (Counterexample Search)**: A single `Sat` check shows that *a* valid assignment exists. To formally prove that a safety property $P$ (such as `sirenActive`) **must** hold in *every* valid state, assert its negation `not(P)` and verify that `m.check()` returns `"Unsat"`. If it returns `"Sat"`, the solver's variable values give you a concrete counterexample (security loophole).
|
|
86
86
|
- **One-Way Implication (`implies`) vs. Equivalence**: In classical logic, `` implies(expr`${luxLevel} <= 50`, isNight) `` only constrains `isNight` when `luxLevel <= 50`. During daytime (`luxLevel > 50`), `isNight` is unconstrained ("open-world" assumption) and could be assigned either `true` or `false` unless you also add the converse rule `` implies(expr`${luxLevel} >= 51`, not(isNight)) ``.
|
|
87
|
+
- **Running Without `COOP` / `COEP` Headers (`solver: "pumpkin"`)**: Because all variables in this model are propositional `BoolVar`s and bounded integers (`luxLevel` in `[0, 1000]`), the exact same deduction and counterexample `unsatCore` proof works out of the box with bundled `@ohtaman/washi/solvers/pumpkin` (`m.check({ solver: "pumpkin" })`) without `COOP` / `COEP` headers or `z3-solver`.
|
|
@@ -12,7 +12,7 @@ $$\sum_{i \in S, j \notin S} x_{ij} \ge 1 \quad \forall S \subset V, \; 2 \le |S
|
|
|
12
12
|
|
|
13
13
|
Because there are $2^n - 2$ subsets, enumerating all subtour constraints upfront is impractical as $n$ grows. With **Benders Decomposition (Lazy Constraint Separation)**, constraints are added only when violated:
|
|
14
14
|
1. **Master Problem**: Solves the degree-assignment relaxation (each city has 1 incoming and 1 outgoing edge).
|
|
15
|
-
2. **Separation Subproblem**: Inspects the candidate solution graph. If disconnected cycles exist, it adds
|
|
15
|
+
2. **Separation Subproblem**: Inspects the candidate solution graph. If disconnected cycles exist, it adds **Benders Feasibility Cuts** eliminating all detected subtours simultaneously (multi-cut separation) and resolves until a single connected tour is obtained.
|
|
16
16
|
|
|
17
17
|
## Problem Inputs
|
|
18
18
|
|
|
@@ -69,6 +69,7 @@ diagnoseConflicts();
|
|
|
69
69
|
|
|
70
70
|
## Practical Notes
|
|
71
71
|
|
|
72
|
-
- **Z3
|
|
73
|
-
- **
|
|
72
|
+
- **Choosing Between Pumpkin, Z3, and HiGHS for Conflict Diagnosis**:
|
|
73
|
+
- **Pumpkin (`m.check({ solver: "pumpkin" })`)** is bundled with `@ohtaman/washi/solvers/pumpkin` (zero external dependencies, no `COOP` / `COEP` headers) and extracts scale-invariant `unsatCore` subsets for discrete models where all variables are bounded `Integer`, `Binary`, or `BoolVar` (for example, when `budget` above is modeled with `m.integer("budget", ...)`).
|
|
74
|
+
- **Z3 (`m.check({ solver: "z3" })`)** supports `Continuous` variables (like `budget` above) and fractional arithmetic, returning all four rules that jointly form the contradiction (`budget_limit`, `rush_required`, `rush_staffing_rule`, `strict_board_budget_cap`), while excluding the innocent `minimum_one_employee` rule.
|
|
74
75
|
- **HiGHS (`m.check({ solver: "highs" })`)** solves a single $L_1$ elastic slack minimization problem ($\min \sum s_i$). Because relaxing `rush_staffing_rule` (or `rush_required`) requires a slack of only `1`–`2` units whereas relaxing `strict_board_budget_cap` requires a slack of `14,000` dollars, unweighted $L_1$ minimization naturally highlights the smallest-magnitude repair (`rush_required`) needed to restore feasibility.
|