@areb0s/scip.js 1.2.7 → 1.2.9
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/dist/pre.js +36 -0
- package/dist/scip-wrapper.js +43 -43
- package/dist/scip.js +403 -10
- package/dist/scip.min.js +10 -9
- package/package.json +3 -3
package/dist/pre.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Pre-initialization script for SCIP WASM
|
|
2
|
+
// This runs before the main SCIP module initializes
|
|
3
|
+
|
|
4
|
+
Module['preRun'] = Module['preRun'] || [];
|
|
5
|
+
Module['postRun'] = Module['postRun'] || [];
|
|
6
|
+
|
|
7
|
+
// Create virtual filesystem directories
|
|
8
|
+
Module['preRun'].push(function() {
|
|
9
|
+
FS.mkdir('/problems');
|
|
10
|
+
FS.mkdir('/solutions');
|
|
11
|
+
FS.mkdir('/settings');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Capture stdout/stderr
|
|
15
|
+
Module['print'] = function(text) {
|
|
16
|
+
if (Module['onStdout']) {
|
|
17
|
+
Module['onStdout'](text);
|
|
18
|
+
} else {
|
|
19
|
+
console.log('[SCIP]', text);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
Module['printErr'] = function(text) {
|
|
24
|
+
if (Module['onStderr']) {
|
|
25
|
+
Module['onStderr'](text);
|
|
26
|
+
} else {
|
|
27
|
+
console.error('[SCIP Error]', text);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Exit handler
|
|
32
|
+
Module['onExit'] = function(code) {
|
|
33
|
+
if (Module['onExitCallback']) {
|
|
34
|
+
Module['onExitCallback'](code);
|
|
35
|
+
}
|
|
36
|
+
};
|
package/dist/scip-wrapper.js
CHANGED
|
@@ -44,13 +44,13 @@ const DEFAULT_CDN_BASE =
|
|
|
44
44
|
/**
|
|
45
45
|
* Get base URL from global SCIP_BASE_URL or default CDN
|
|
46
46
|
*/
|
|
47
|
-
function getBaseUrl() {
|
|
48
|
-
// Safe check for global scope (works in browser, worker, and SSR)
|
|
49
|
-
const globalScope =
|
|
50
|
-
(typeof globalThis !== "undefined" && globalThis) ||
|
|
51
|
-
(typeof self !== "undefined" && self) ||
|
|
52
|
-
(typeof window !== "undefined" && window) ||
|
|
53
|
-
{};
|
|
47
|
+
function getBaseUrl() {
|
|
48
|
+
// Safe check for global scope (works in browser, worker, and SSR)
|
|
49
|
+
const globalScope =
|
|
50
|
+
(typeof globalThis !== "undefined" && globalThis) ||
|
|
51
|
+
(typeof self !== "undefined" && self) ||
|
|
52
|
+
(typeof window !== "undefined" && window) ||
|
|
53
|
+
{};
|
|
54
54
|
|
|
55
55
|
// Check for explicit SCIP_BASE_URL
|
|
56
56
|
if (globalScope.SCIP_BASE_URL) {
|
|
@@ -66,9 +66,9 @@ function getBaseUrl() {
|
|
|
66
66
|
return __importMetaUrl.substring(0, __importMetaUrl.lastIndexOf("/") + 1);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// Default to CDN
|
|
70
|
-
return DEFAULT_CDN_BASE;
|
|
71
|
-
}
|
|
69
|
+
// Default to CDN
|
|
70
|
+
return DEFAULT_CDN_BASE;
|
|
71
|
+
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Solution status enum
|
|
@@ -171,28 +171,28 @@ export async function init(options = {}) {
|
|
|
171
171
|
const baseUrl = getBaseUrl();
|
|
172
172
|
const wasmPath = options.wasmPath || baseUrl + "scip.wasm";
|
|
173
173
|
|
|
174
|
-
// Dynamic import of the Emscripten-generated module
|
|
175
|
-
const createSCIP = (await import("./scip-core.js")).default;
|
|
176
|
-
|
|
177
|
-
scipModule = await createSCIP({
|
|
178
|
-
locateFile: (path) => {
|
|
179
|
-
if (path.endsWith(".wasm")) {
|
|
180
|
-
return wasmPath;
|
|
181
|
-
}
|
|
182
|
-
return path;
|
|
183
|
-
},
|
|
184
|
-
// Capture stdout/stderr from Emscripten
|
|
185
|
-
print: (text) => {
|
|
186
|
-
if (scipModule && scipModule.onStdout) {
|
|
187
|
-
scipModule.onStdout(text);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
printErr: (text) => {
|
|
191
|
-
if (scipModule && scipModule.onStderr) {
|
|
192
|
-
scipModule.onStderr(text);
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
});
|
|
174
|
+
// Dynamic import of the Emscripten-generated module
|
|
175
|
+
const createSCIP = (await import("./scip-core.js")).default;
|
|
176
|
+
|
|
177
|
+
scipModule = await createSCIP({
|
|
178
|
+
locateFile: (path) => {
|
|
179
|
+
if (path.endsWith(".wasm")) {
|
|
180
|
+
return wasmPath;
|
|
181
|
+
}
|
|
182
|
+
return path;
|
|
183
|
+
},
|
|
184
|
+
// Capture stdout/stderr from Emscripten
|
|
185
|
+
print: (text) => {
|
|
186
|
+
if (scipModule && scipModule.onStdout) {
|
|
187
|
+
scipModule.onStdout(text);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
printErr: (text) => {
|
|
191
|
+
if (scipModule && scipModule.onStderr) {
|
|
192
|
+
scipModule.onStderr(text);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
196
|
|
|
197
197
|
// Create directories for problems, solutions, settings
|
|
198
198
|
if (scipModule.FS) {
|
|
@@ -286,14 +286,14 @@ export async function solve(problem, options = {}) {
|
|
|
286
286
|
await init(options);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
289
|
+
const {
|
|
290
|
+
format = "lp",
|
|
291
|
+
timeLimit = 3600,
|
|
292
|
+
gap = null,
|
|
293
|
+
verbose = false,
|
|
294
|
+
parameters = {},
|
|
295
|
+
initialSolution = null, // Warm start: { varName: value, ... }
|
|
296
|
+
} = options;
|
|
297
297
|
|
|
298
298
|
// Capture output
|
|
299
299
|
let stdout = "";
|
|
@@ -342,14 +342,14 @@ export async function solve(problem, options = {}) {
|
|
|
342
342
|
|
|
343
343
|
// Warm start: write and read initial solution
|
|
344
344
|
if (initialSolution && Object.keys(initialSolution).length > 0) {
|
|
345
|
-
const solLines = [
|
|
345
|
+
const solLines = ["solution status: unknown"];
|
|
346
346
|
for (const [varName, value] of Object.entries(initialSolution)) {
|
|
347
347
|
if (value !== 0) {
|
|
348
348
|
solLines.push(`${varName} ${value}`);
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
const initialSolutionFile =
|
|
352
|
-
scipModule.FS.writeFile(initialSolutionFile, solLines.join(
|
|
351
|
+
const initialSolutionFile = "/solutions/initial.sol";
|
|
352
|
+
scipModule.FS.writeFile(initialSolutionFile, solLines.join("\n"));
|
|
353
353
|
commands.push(`read solution ${initialSolutionFile}`);
|
|
354
354
|
}
|
|
355
355
|
commands.push("optimize");
|