minizinc 4.5.2-edge.6 → 4.5.2-edge.7

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.md CHANGED
@@ -206,30 +206,30 @@ For more detailed documentation of all available options and functionality, visi
206
206
 
207
207
  ### Compiling MiniZinc for WebAssembly
208
208
 
209
- The WebAssembly build of MiniZinc requires [Emscripten](https://emscripten.org/).
209
+ CI downloads `minizinc-compiler-only-wasm32-emscripten.tar.gz` from libminizinc's
210
+ [releases](https://github.com/MiniZinc/libminizinc/releases) (`edge` for the
211
+ development version) rather than building it, which is also the easiest way to get
212
+ one locally.
213
+
214
+ To build it yourself you need [Emscripten](https://emscripten.org/), at the version
215
+ pinned as `emsdk` in libminizinc's `vendor.lock`: the solver archives are built with
216
+ it, and mixing emscripten versions across static archives is not safe.
210
217
 
211
218
  ```sh
212
219
  # Clone MiniZinc
213
220
  git clone https://github.com/MiniZinc/libminizinc minizinc
214
-
215
- # Download solvers (or you can build them yourself using emscripten)
216
221
  cd minizinc
217
- MZNARCH=wasm ./download_vendor
218
-
219
- # Configure MiniZinc
220
- emcmake cmake -S . -B build \
221
- -DCMAKE_FIND_ROOT_PATH="/" \
222
- -DCMAKE_BUILD_TYPE=Release \
223
- -DGecode_ROOT="$PWD/vendor/gecode" \
224
- -DOsiCBC_ROOT="$PWD/vendor/cbc" \
225
- -DCMAKE_PREFIX_PATH="$PWD/vendor/highs/lib/cmake/highs:$PWD/vendor/chuffed/lib/cmake/chuffed" \
226
- -DCMAKE_INSTALL_PREFIX="../minizinc-install"
227
-
228
- # Build MiniZinc
229
- cmake --build build --config Release --target install
222
+
223
+ # Download the solvers built for wasm (requires the gh CLI, authenticated)
224
+ scripts/fetch_vendor.sh wasm32-emscripten gecode cbc chuffed highs
225
+
226
+ # Configure and build, exactly as CI does
227
+ ROOT="$PWD" CMAKE_WRAPPER=emcmake CMAKE_FIND_ROOT_PATH=/ \
228
+ CMAKE_GENERATOR="Unix Makefiles" EXPECT_DEPS="gecode cbc chuffed highs" \
229
+ bash scripts/build.sh
230
230
  ```
231
231
 
232
- The WebAssembly build of MiniZinc can also be obtained from the [build workflow](https://github.com/MiniZinc/minizinc-js/actions/workflows/build.yml) as the `minizinc` artifact.
232
+ This installs into `minizinc/` (`bin/minizinc.js`, `.wasm` and `.data`).
233
233
 
234
234
  ### Building MiniZinc JS
235
235
 
package/dist/minizinc.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=encodeURIComponent("4.5.2-edge.6");let e={workerURL:new URL(`./minizinc-worker.js?version=${t}`,document.currentScript.src),numWorkers:2};const n=[];let s;function r(){if(!s){const t=`importScripts(${JSON.stringify(e.workerURL)});`;s=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const r=new Worker(s);r.postMessage({wasmURL:e.wasmURL?e.wasmURL.toString():new URL(`./minizinc.wasm?version=${t}`,e.workerURL).toString(),dataURL:e.dataURL?e.dataURL.toString():new URL(`./minizinc.data?version=${t}`,e.workerURL).toString()}),n.push({worker:r,runCount:0})}function o(){for(;n.length<e.numWorkers;)r()}class i{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new i;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,s=null){o();const r=[];let i=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;i={...this.vfs,[t]:JSON.stringify(e)},r.push(t)}let{worker:a,runCount:u}=n.pop();return a.postMessage({jsonStream:!0,files:i,args:[...r,...t,...this._toRun],outputFiles:s}),{worker:a,runCount:u+1}}check(t){return new Promise((e,s)=>{const o={...t},{worker:i,runCount:a}=this._run(["--model-check-only"],o.options),u=[];i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":a<10?n.push({worker:i,runCount:a}):(i.terminate(),r()),e(u)}}})}interface(t){return new Promise((e,s)=>{const o={...t},{worker:i,runCount:a}=this._run(["--model-interface-only"],o.options),u=[];let d=null;i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":a<10?n.push({worker:i,runCount:a}):(i.terminate(),r()),0===t.data.code?e(d):s(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const o=["-c","--fzn",s],{worker:i}=this._run(o,e.options,[s]);r();let a={},u=!1,d=null;return i.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":i.terminate(),u=!0,a={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,i.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);r();let o=null,i={},a=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),a=!0,i={};break;case"error":o||(o=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!a,cancel(){if(!a){if(a=!0,s.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=o?{message:o.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}}exports.Model=i,exports.init=async function(t){if(t&&(e={...e,...t}),n.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");o(),await Promise.race(n.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))},exports.readStdlibFileContents=function(t){const e=Array.isArray(t)?t:[t];return new Promise((s,i)=>{o();let{worker:a,runCount:u}=n.pop();a.postMessage({readStdlibFiles:e}),a.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?n.push({worker:a,runCount:u+1}):(a.terminate(),r()),Array.isArray(t)?s(e.data.files):s(e.data.files[t])):"error"===e.data.type&&(a.terminate(),r(),i(e.data.message))}})},exports.shutdown=function(){for(const t of n)t.worker.terminate();n.splice(0),URL.revokeObjectURL(s),s=null},exports.solvers=function(){return new Promise((t,e)=>{o();let{worker:s,runCount:i}=n.pop();s.postMessage({jsonStream:!1,args:["--solvers-json"]}),s.onmessage=o=>{"exit"===o.data.type&&(i<10?n.push({worker:s,runCount:i+1}):(s.terminate(),r()),0===o.data.code?t(JSON.parse(o.data.stdout)):e(o.data))}})},exports.version=function(){return new Promise((t,e)=>{o();let{worker:s,runCount:i}=n.pop();s.postMessage({jsonStream:!1,args:["--version"]}),s.onmessage=o=>{"exit"===o.data.type&&(i<10?n.push({worker:s,runCount:i+1}):(s.terminate(),r()),0===o.data.code?t(o.data.stdout):e(o.data))}})};
1
+ "use strict";const t=encodeURIComponent("4.5.2-edge.7");let e={workerURL:new URL(`./minizinc-worker.js?version=${t}`,document.currentScript.src),numWorkers:2};const n=[];let s;function r(){if(!s){const t=`importScripts(${JSON.stringify(e.workerURL)});`;s=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const r=new Worker(s);r.postMessage({wasmURL:e.wasmURL?e.wasmURL.toString():new URL(`./minizinc.wasm?version=${t}`,e.workerURL).toString(),dataURL:e.dataURL?e.dataURL.toString():new URL(`./minizinc.data?version=${t}`,e.workerURL).toString()}),n.push({worker:r,runCount:0})}function o(){for(;n.length<e.numWorkers;)r()}class i{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new i;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,s=null){o();const r=[];let i=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;i={...this.vfs,[t]:JSON.stringify(e)},r.push(t)}let{worker:a,runCount:u}=n.pop();return a.postMessage({jsonStream:!0,files:i,args:[...r,...t,...this._toRun],outputFiles:s}),{worker:a,runCount:u+1}}check(t){return new Promise((e,s)=>{const o={...t},{worker:i,runCount:a}=this._run(["--model-check-only"],o.options),u=[];i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":a<10?n.push({worker:i,runCount:a}):(i.terminate(),r()),e(u)}}})}interface(t){return new Promise((e,s)=>{const o={...t},{worker:i,runCount:a}=this._run(["--model-interface-only"],o.options),u=[];let d=null;i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":a<10?n.push({worker:i,runCount:a}):(i.terminate(),r()),0===t.data.code?e(d):s(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const o=["-c","--fzn",s],{worker:i}=this._run(o,e.options,[s]);r();let a={},u=!1,d=null;return i.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":i.terminate(),u=!0,a={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,i.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);r();let o=null,i={},a=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),a=!0,i={};break;case"error":o||(o=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!a,cancel(){if(!a){if(a=!0,s.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=o?{message:o.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}}exports.Model=i,exports.init=async function(t){if(t&&(e={...e,...t}),n.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");o(),await Promise.race(n.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))},exports.readStdlibFileContents=function(t){const e=Array.isArray(t)?t:[t];return new Promise((s,i)=>{o();let{worker:a,runCount:u}=n.pop();a.postMessage({readStdlibFiles:e}),a.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?n.push({worker:a,runCount:u+1}):(a.terminate(),r()),Array.isArray(t)?s(e.data.files):s(e.data.files[t])):"error"===e.data.type&&(a.terminate(),r(),i(e.data.message))}})},exports.shutdown=function(){for(const t of n)t.worker.terminate();n.splice(0),URL.revokeObjectURL(s),s=null},exports.solvers=function(){return new Promise((t,e)=>{o();let{worker:s,runCount:i}=n.pop();s.postMessage({jsonStream:!1,args:["--solvers-json"]}),s.onmessage=o=>{"exit"===o.data.type&&(i<10?n.push({worker:s,runCount:i+1}):(s.terminate(),r()),0===o.data.code?t(JSON.parse(o.data.stdout)):e(o.data))}})},exports.version=function(){return new Promise((t,e)=>{o();let{worker:s,runCount:i}=n.pop();s.postMessage({jsonStream:!1,args:["--version"]}),s.onmessage=o=>{"exit"===o.data.type&&(i<10?n.push({worker:s,runCount:i+1}):(s.terminate(),r()),0===o.data.code?t(o.data.stdout):e(o.data))}})};
package/dist/minizinc.js CHANGED
@@ -1 +1 @@
1
- var MiniZinc=function(t){"use strict";const e=encodeURIComponent("4.5.2-edge.6");let n={workerURL:new URL(`./minizinc-worker.js?version=${e}`,document.currentScript.src),numWorkers:2};const s=[];let r;function o(){if(!r){const t=`importScripts(${JSON.stringify(n.workerURL)});`;r=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const t=new Worker(r);t.postMessage({wasmURL:n.wasmURL?n.wasmURL.toString():new URL(`./minizinc.wasm?version=${e}`,n.workerURL).toString(),dataURL:n.dataURL?n.dataURL.toString():new URL(`./minizinc.data?version=${e}`,n.workerURL).toString()}),s.push({worker:t,runCount:0})}function i(){for(;s.length<n.numWorkers;)o()}class a{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new a;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,n=null){i();const r=[];let o=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;o={...this.vfs,[t]:JSON.stringify(e)},r.push(t)}let{worker:a,runCount:u}=s.pop();return a.postMessage({jsonStream:!0,files:o,args:[...r,...t,...this._toRun],outputFiles:n}),{worker:a,runCount:u+1}}check(t){return new Promise((e,n)=>{const r={...t},{worker:i,runCount:a}=this._run(["--model-check-only"],r.options),u=[];i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":a<10?s.push({worker:i,runCount:a}):(i.terminate(),o()),e(u)}}})}interface(t){return new Promise((e,n)=>{const r={...t},{worker:i,runCount:a}=this._run(["--model-interface-only"],r.options),u=[];let d=null;i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":a<10?s.push({worker:i,runCount:a}):(i.terminate(),o()),0===t.data.code?e(d):n(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const r=["-c","--fzn",s],{worker:i}=this._run(r,e.options,[s]);o();let a={},u=!1,d=null;return i.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":i.terminate(),u=!0,a={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,i.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);o();let r=null,i={},a=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),a=!0,i={};break;case"error":r||(r=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!a,cancel(){if(!a){if(a=!0,s.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=r?{message:r.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}}return t.Model=a,t.init=async function(t){if(t&&(n={...n,...t}),s.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");i(),await Promise.race(s.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))},t.readStdlibFileContents=function(t){const e=Array.isArray(t)?t:[t];return new Promise((n,r)=>{i();let{worker:a,runCount:u}=s.pop();a.postMessage({readStdlibFiles:e}),a.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?s.push({worker:a,runCount:u+1}):(a.terminate(),o()),Array.isArray(t)?n(e.data.files):n(e.data.files[t])):"error"===e.data.type&&(a.terminate(),o(),r(e.data.message))}})},t.shutdown=function(){for(const t of s)t.worker.terminate();s.splice(0),URL.revokeObjectURL(r),r=null},t.solvers=function(){return new Promise((t,e)=>{i();let{worker:n,runCount:r}=s.pop();n.postMessage({jsonStream:!1,args:["--solvers-json"]}),n.onmessage=i=>{"exit"===i.data.type&&(r<10?s.push({worker:n,runCount:r+1}):(n.terminate(),o()),0===i.data.code?t(JSON.parse(i.data.stdout)):e(i.data))}})},t.version=function(){return new Promise((t,e)=>{i();let{worker:n,runCount:r}=s.pop();n.postMessage({jsonStream:!1,args:["--version"]}),n.onmessage=i=>{"exit"===i.data.type&&(r<10?s.push({worker:n,runCount:r+1}):(n.terminate(),o()),0===i.data.code?t(i.data.stdout):e(i.data))}})},t}({});
1
+ var MiniZinc=function(t){"use strict";const e=encodeURIComponent("4.5.2-edge.7");let n={workerURL:new URL(`./minizinc-worker.js?version=${e}`,document.currentScript.src),numWorkers:2};const s=[];let r;function o(){if(!r){const t=`importScripts(${JSON.stringify(n.workerURL)});`;r=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const t=new Worker(r);t.postMessage({wasmURL:n.wasmURL?n.wasmURL.toString():new URL(`./minizinc.wasm?version=${e}`,n.workerURL).toString(),dataURL:n.dataURL?n.dataURL.toString():new URL(`./minizinc.data?version=${e}`,n.workerURL).toString()}),s.push({worker:t,runCount:0})}function i(){for(;s.length<n.numWorkers;)o()}class a{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new a;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,n=null){i();const r=[];let o=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;o={...this.vfs,[t]:JSON.stringify(e)},r.push(t)}let{worker:a,runCount:u}=s.pop();return a.postMessage({jsonStream:!0,files:o,args:[...r,...t,...this._toRun],outputFiles:n}),{worker:a,runCount:u+1}}check(t){return new Promise((e,n)=>{const r={...t},{worker:i,runCount:a}=this._run(["--model-check-only"],r.options),u=[];i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":a<10?s.push({worker:i,runCount:a}):(i.terminate(),o()),e(u)}}})}interface(t){return new Promise((e,n)=>{const r={...t},{worker:i,runCount:a}=this._run(["--model-interface-only"],r.options),u=[];let d=null;i.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":a<10?s.push({worker:i,runCount:a}):(i.terminate(),o()),0===t.data.code?e(d):n(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const r=["-c","--fzn",s],{worker:i}=this._run(r,e.options,[s]);o();let a={},u=!1,d=null;return i.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":i.terminate(),u=!0,a={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,i.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);o();let r=null,i={},a=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),a=!0,i={};break;case"error":r||(r=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!a,cancel(){if(!a){if(a=!0,s.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=r?{message:r.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}}return t.Model=a,t.init=async function(t){if(t&&(n={...n,...t}),s.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");i(),await Promise.race(s.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))},t.readStdlibFileContents=function(t){const e=Array.isArray(t)?t:[t];return new Promise((n,r)=>{i();let{worker:a,runCount:u}=s.pop();a.postMessage({readStdlibFiles:e}),a.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?s.push({worker:a,runCount:u+1}):(a.terminate(),o()),Array.isArray(t)?n(e.data.files):n(e.data.files[t])):"error"===e.data.type&&(a.terminate(),o(),r(e.data.message))}})},t.shutdown=function(){for(const t of s)t.worker.terminate();s.splice(0),URL.revokeObjectURL(r),r=null},t.solvers=function(){return new Promise((t,e)=>{i();let{worker:n,runCount:r}=s.pop();n.postMessage({jsonStream:!1,args:["--solvers-json"]}),n.onmessage=i=>{"exit"===i.data.type&&(r<10?s.push({worker:n,runCount:r+1}):(n.terminate(),o()),0===i.data.code?t(JSON.parse(i.data.stdout)):e(i.data))}})},t.version=function(){return new Promise((t,e)=>{i();let{worker:n,runCount:r}=s.pop();n.postMessage({jsonStream:!1,args:["--version"]}),n.onmessage=i=>{"exit"===i.data.type&&(r<10?s.push({worker:n,runCount:r+1}):(n.terminate(),o()),0===i.data.code?t(i.data.stdout):e(i.data))}})},t}({});
package/dist/minizinc.mjs CHANGED
@@ -1 +1 @@
1
- const t=encodeURIComponent("4.5.2-edge.6");let e={workerURL:new URL(`./minizinc-worker.js?version=${t}`,import.meta.url),numWorkers:2};const n=[];let s;function o(){if(!s){const t=`importScripts(${JSON.stringify(e.workerURL)});`;s=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const o=new Worker(s);o.postMessage({wasmURL:e.wasmURL?e.wasmURL.toString():new URL(`./minizinc.wasm?version=${t}`,e.workerURL).toString(),dataURL:e.dataURL?e.dataURL.toString():new URL(`./minizinc.data?version=${t}`,e.workerURL).toString()}),n.push({worker:o,runCount:0})}function r(){for(;n.length<e.numWorkers;)o()}async function a(t){if(t&&(e={...e,...t}),n.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");r(),await Promise.race(n.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))}function i(){for(const t of n)t.worker.terminate();n.splice(0),URL.revokeObjectURL(s),s=null}class u{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new u;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,s=null){r();const o=[];let a=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;a={...this.vfs,[t]:JSON.stringify(e)},o.push(t)}let{worker:i,runCount:u}=n.pop();return i.postMessage({jsonStream:!0,files:a,args:[...o,...t,...this._toRun],outputFiles:s}),{worker:i,runCount:u+1}}check(t){return new Promise((e,s)=>{const r={...t},{worker:a,runCount:i}=this._run(["--model-check-only"],r.options),u=[];a.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":i<10?n.push({worker:a,runCount:i}):(a.terminate(),o()),e(u)}}})}interface(t){return new Promise((e,s)=>{const r={...t},{worker:a,runCount:i}=this._run(["--model-interface-only"],r.options),u=[];let d=null;a.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":i<10?n.push({worker:a,runCount:i}):(a.terminate(),o()),0===t.data.code?e(d):s(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const r=["-c","--fzn",s],{worker:a}=this._run(r,e.options,[s]);o();let i={},u=!1,d=null;return a.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":a.terminate(),u=!0,i={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,a.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);o();let r=null,a={},i=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),i=!0,a={};break;case"error":r||(r=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!i,cancel(){if(!i){if(i=!0,s.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=r?{message:r.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}}function d(){return new Promise((t,e)=>{r();let{worker:s,runCount:a}=n.pop();s.postMessage({jsonStream:!1,args:["--version"]}),s.onmessage=r=>{"exit"===r.data.type&&(a<10?n.push({worker:s,runCount:a+1}):(s.terminate(),o()),0===r.data.code?t(r.data.stdout):e(r.data))}})}function c(){return new Promise((t,e)=>{r();let{worker:s,runCount:a}=n.pop();s.postMessage({jsonStream:!1,args:["--solvers-json"]}),s.onmessage=r=>{"exit"===r.data.type&&(a<10?n.push({worker:s,runCount:a+1}):(s.terminate(),o()),0===r.data.code?t(JSON.parse(r.data.stdout)):e(r.data))}})}function m(t){const e=Array.isArray(t)?t:[t];return new Promise((s,a)=>{r();let{worker:i,runCount:u}=n.pop();i.postMessage({readStdlibFiles:e}),i.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?n.push({worker:i,runCount:u+1}):(i.terminate(),o()),Array.isArray(t)?s(e.data.files):s(e.data.files[t])):"error"===e.data.type&&(i.terminate(),o(),a(e.data.message))}})}export{u as Model,a as init,m as readStdlibFileContents,i as shutdown,c as solvers,d as version};
1
+ const t=encodeURIComponent("4.5.2-edge.7");let e={workerURL:new URL(`./minizinc-worker.js?version=${t}`,import.meta.url),numWorkers:2};const n=[];let s;function o(){if(!s){const t=`importScripts(${JSON.stringify(e.workerURL)});`;s=URL.createObjectURL(new Blob([t],{type:"text/javascript"}))}const o=new Worker(s);o.postMessage({wasmURL:e.wasmURL?e.wasmURL.toString():new URL(`./minizinc.wasm?version=${t}`,e.workerURL).toString(),dataURL:e.dataURL?e.dataURL.toString():new URL(`./minizinc.data?version=${t}`,e.workerURL).toString()}),n.push({worker:o,runCount:0})}function r(){for(;n.length<e.numWorkers;)o()}async function a(t){if(t&&(e={...e,...t}),n.length>0)throw new Error("MiniZinc.init() called after library already used/initialised");r(),await Promise.race(n.map(t=>new Promise(e=>{t.worker.addEventListener("message",t=>{"ready"===t.data.type&&e()},{once:!0})})))}function i(){for(const t of n)t.worker.terminate();n.splice(0),URL.revokeObjectURL(s),s=null}class u{constructor(){this.vfs={},this._toRun=[],this.unnamedCount=0}clone(){const t=new u;return t.vfs={...this.vfs},t._toRun=[...this.toRun],t.unnamedCount=this.unnamedCount,t}addString(t){let e=`_mzn_${this.unnamedCount++}.mzn`;for(;e in this.vfs;)e=`_mzn_${this.unnamedCount++}.mzn`;return this.addFile(e,t),e}addDznString(t){let e=`_dzn_${this.unnamedCount++}.dzn`;for(;e in this.vfs;)e=`_dzn_${this.unnamedCount++}.dzn`;return this.addFile(e,t),e}addJson(t){let e=`_json_${this.unnamedCount++}.json`;for(;e in this.vfs;)e=`_json_${this.unnamedCount++}.json`;return this.addFile(e,JSON.stringify(t)),e}addFile(t,e,n=!0){if("string"!=typeof e){if(t in this.vfs)return void this._addToRun(t,n);throw new Error("Missing file contents argument")}this.vfs[t]=e,this._addToRun(t,n)}_addToRun(t,e){e&&(t.endsWith(".mzn")||t.endsWith(".mzc")||t.endsWith(".dzn")||t.endsWith(".json")||t.endsWith(".mpc")||t.endsWith(".fzn"))&&-1===this._toRun.indexOf(t)&&this._toRun.push(t)}_run(t,e,s=null){r();const o=[];let a=this.vfs;if(e){let t=`_mzn_${this.unnamedCount++}.mpc`;for(;t in this.vfs;)t=`_mzn_${this.unnamedCount++}.mpc`;a={...this.vfs,[t]:JSON.stringify(e)},o.push(t)}let{worker:i,runCount:u}=n.pop();return i.postMessage({jsonStream:!0,files:a,args:[...o,...t,...this._toRun],outputFiles:s}),{worker:i,runCount:u+1}}check(t){return new Promise((e,s)=>{const r={...t},{worker:a,runCount:i}=this._run(["--model-check-only"],r.options),u=[];a.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"exit":i<10?n.push({worker:a,runCount:i}):(a.terminate(),o()),e(u)}}})}interface(t){return new Promise((e,s)=>{const r={...t},{worker:a,runCount:i}=this._run(["--model-interface-only"],r.options),u=[];let d=null;a.onmessage=t=>{switch(t.data.type){case"error":u.push(t.data);break;case"interface":d=t.data;break;case"exit":i<10?n.push({worker:a,runCount:i}):(a.terminate(),o()),0===t.data.code?e(d):s(u)}}})}compile(t){const e={...t};let n=0,s=`_fzn_${n++}.fzn`;for(;s in this.vfs;)s=`_fzn_${n++}.fzn`;const r=["-c","--fzn",s],{worker:a}=this._run(r,e.options,[s]);o();let i={},u=!1,d=null;return a.onmessage=t=>{if(i[t.data.type])for(const e of i[t.data.type])e(t.data);switch(t.data.type){case"exit":a.terminate(),u=!0,i={};break;case"error":d||(d=t.data)}},{isRunning:()=>!u,cancel(){if(!u){if(u=!0,a.terminate(),i.exit)for(const t of i.exit)t({type:"exit",code:null});i={}}},on(t,e){i[t]?i[t].add(e):i[t]=new Set([e])},off(t,e){i[t]&&i[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t(n.outputFiles[s]);else{const t=d?{message:d.message,...n}:n;if(!e)throw t;e(t)}};i.exit?i.exit.add(n):i.exit=new Set([n])}}}solve(t){const e={jsonOutput:!0,...t},n=["-i"];e.jsonOutput&&(n.push("--output-mode"),n.push("json"));const{worker:s}=this._run(n,e.options);o();let r=null,a={},i=!1,u=null,d={},c="UNKNOWN";return s.onmessage=t=>{if(a[t.data.type])for(const e of a[t.data.type])e(t.data);switch(t.data.type){case"exit":s.terminate(),i=!0,a={};break;case"error":r||(r=t.data);break;case"statistics":d={...d,...t.data.statistics};break;case"solution":u=t.data,c="SATISFIED";break;case"status":c=t.data.status}},{isRunning:()=>!i,cancel(){if(!i){if(i=!0,s.terminate(),a.exit)for(const t of a.exit)t({type:"exit",code:null});a={}}},on(t,e){a[t]?a[t].add(e):a[t]=new Set([e])},off(t,e){a[t]&&a[t].delete(e)},then(t,e){const n=n=>{if(0===n.code)t({status:c,solution:u,statistics:d});else{const t=r?{message:r.message,...n}:n;if(!e)throw t;e(t)}};a.exit?a.exit.add(n):a.exit=new Set([n])}}}}function d(){return new Promise((t,e)=>{r();let{worker:s,runCount:a}=n.pop();s.postMessage({jsonStream:!1,args:["--version"]}),s.onmessage=r=>{"exit"===r.data.type&&(a<10?n.push({worker:s,runCount:a+1}):(s.terminate(),o()),0===r.data.code?t(r.data.stdout):e(r.data))}})}function c(){return new Promise((t,e)=>{r();let{worker:s,runCount:a}=n.pop();s.postMessage({jsonStream:!1,args:["--solvers-json"]}),s.onmessage=r=>{"exit"===r.data.type&&(a<10?n.push({worker:s,runCount:a+1}):(s.terminate(),o()),0===r.data.code?t(JSON.parse(r.data.stdout)):e(r.data))}})}function m(t){const e=Array.isArray(t)?t:[t];return new Promise((s,a)=>{r();let{worker:i,runCount:u}=n.pop();i.postMessage({readStdlibFiles:e}),i.onmessage=e=>{"readStdlibFiles"===e.data.type?(u<10?n.push({worker:i,runCount:u+1}):(i.terminate(),o()),Array.isArray(t)?s(e.data.files):s(e.data.files[t])):"error"===e.data.type&&(i.terminate(),o(),a(e.data.message))}})}export{u as Model,a as init,m as readStdlibFileContents,i as shutdown,c as solvers,d as version};
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minizinc",
3
- "version": "4.5.2-edge.6",
3
+ "version": "4.5.2-edge.7",
4
4
  "description": "JavaScript API for MiniZinc",
5
5
  "homepage": "https://js.minizinc.dev",
6
6
  "types": "types/index.d.ts",