@iyulab/u-routing 0.2.4 → 0.3.1
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 +13 -0
- package/node/u_routing.cjs +434 -0
- package/node/u_routing.d.cts +23 -0
- package/node/u_routing_bg.wasm +0 -0
- package/package.json +16 -4
- package/u_routing_bg.js +61 -50
- package/u_routing_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -202,6 +202,19 @@ Errors are returned as rejected promises — they never cause `RuntimeError: unr
|
|
|
202
202
|
}
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
+
## npm (WebAssembly)
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm install @iyulab/u-routing
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The package resolves per environment via a conditional `exports` map:
|
|
212
|
+
|
|
213
|
+
| Environment | Entry |
|
|
214
|
+
|---|---|
|
|
215
|
+
| Bundlers (webpack, Vite, …) | ESM + WebAssembly ESM-integration (`default` condition) |
|
|
216
|
+
| Node.js — `require()`, ESM `import`, CJS TS runners (`tsx`, `ts-node`) | CJS glue loading the wasm from the filesystem (`node` condition) — no loader hooks or flags |
|
|
217
|
+
|
|
205
218
|
## Related
|
|
206
219
|
|
|
207
220
|
- [u-numflow](https://crates.io/crates/u-numflow) — Mathematical optimization primitives
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/* @ts-self-types="./u_routing.d.cts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Solve a capacitated VRP problem.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
* * `problem` — A native JS object matching the VRP input schema.
|
|
8
|
+
*
|
|
9
|
+
* # Supported methods
|
|
10
|
+
* - `"nn"` — Nearest Neighbor (default, fast)
|
|
11
|
+
* - `"savings"` — Clarke-Wright Savings
|
|
12
|
+
* - `"ga"` — Genetic Algorithm with Prins split + local search
|
|
13
|
+
* - `"alns"` — Adaptive Large Neighborhood Search + local search
|
|
14
|
+
*
|
|
15
|
+
* # Returns
|
|
16
|
+
* A JS object with `routes`, `total_distance`, `num_vehicles`,
|
|
17
|
+
* `method_used`, and `computation_time_ms`.
|
|
18
|
+
*
|
|
19
|
+
* # Errors
|
|
20
|
+
* Returns a `JsValue` string describing the error if input is invalid.
|
|
21
|
+
* @param {any} problem
|
|
22
|
+
* @returns {any}
|
|
23
|
+
*/
|
|
24
|
+
function solve_vrp(problem) {
|
|
25
|
+
const ret = wasm.solve_vrp(problem);
|
|
26
|
+
if (ret[2]) {
|
|
27
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
28
|
+
}
|
|
29
|
+
return takeFromExternrefTable0(ret[0]);
|
|
30
|
+
}
|
|
31
|
+
exports.solve_vrp = solve_vrp;
|
|
32
|
+
function __wbg_get_imports() {
|
|
33
|
+
const import0 = {
|
|
34
|
+
__proto__: null,
|
|
35
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
36
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
37
|
+
return ret;
|
|
38
|
+
},
|
|
39
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
40
|
+
const ret = String(arg1);
|
|
41
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
42
|
+
const len1 = WASM_VECTOR_LEN;
|
|
43
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
44
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
45
|
+
},
|
|
46
|
+
__wbg___wbindgen_bigint_get_as_i64_d968e41184ae354f: function(arg0, arg1) {
|
|
47
|
+
const v = arg1;
|
|
48
|
+
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
49
|
+
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
50
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
51
|
+
},
|
|
52
|
+
__wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
|
|
53
|
+
const v = arg0;
|
|
54
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
55
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
56
|
+
},
|
|
57
|
+
__wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
|
|
58
|
+
const ret = debugString(arg1);
|
|
59
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
60
|
+
const len1 = WASM_VECTOR_LEN;
|
|
61
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
62
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
63
|
+
},
|
|
64
|
+
__wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
|
|
65
|
+
const ret = arg0 in arg1;
|
|
66
|
+
return ret;
|
|
67
|
+
},
|
|
68
|
+
__wbg___wbindgen_is_bigint_2f76dc55065b4273: function(arg0) {
|
|
69
|
+
const ret = typeof(arg0) === 'bigint';
|
|
70
|
+
return ret;
|
|
71
|
+
},
|
|
72
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
73
|
+
const ret = typeof(arg0) === 'function';
|
|
74
|
+
return ret;
|
|
75
|
+
},
|
|
76
|
+
__wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
|
|
77
|
+
const val = arg0;
|
|
78
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
79
|
+
return ret;
|
|
80
|
+
},
|
|
81
|
+
__wbg___wbindgen_jsval_eq_e659fcf7b0e32763: function(arg0, arg1) {
|
|
82
|
+
const ret = arg0 === arg1;
|
|
83
|
+
return ret;
|
|
84
|
+
},
|
|
85
|
+
__wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
|
|
86
|
+
const ret = arg0 == arg1;
|
|
87
|
+
return ret;
|
|
88
|
+
},
|
|
89
|
+
__wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
|
|
90
|
+
const obj = arg1;
|
|
91
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
92
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
93
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
94
|
+
},
|
|
95
|
+
__wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
|
|
96
|
+
const obj = arg1;
|
|
97
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
98
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
99
|
+
var len1 = WASM_VECTOR_LEN;
|
|
100
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
101
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
102
|
+
},
|
|
103
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
104
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
105
|
+
},
|
|
106
|
+
__wbg_call_8a2dd23819f8a60a: function() { return handleError(function (arg0, arg1) {
|
|
107
|
+
const ret = arg0.call(arg1);
|
|
108
|
+
return ret;
|
|
109
|
+
}, arguments); },
|
|
110
|
+
__wbg_done_89b2b13e91a60321: function(arg0) {
|
|
111
|
+
const ret = arg0.done;
|
|
112
|
+
return ret;
|
|
113
|
+
},
|
|
114
|
+
__wbg_entries_015dc610cd81ede0: function(arg0) {
|
|
115
|
+
const ret = Object.entries(arg0);
|
|
116
|
+
return ret;
|
|
117
|
+
},
|
|
118
|
+
__wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
|
|
119
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
120
|
+
}, arguments); },
|
|
121
|
+
__wbg_get_507a50627bffa49b: function(arg0, arg1) {
|
|
122
|
+
const ret = arg0[arg1 >>> 0];
|
|
123
|
+
return ret;
|
|
124
|
+
},
|
|
125
|
+
__wbg_get_c7eb1f358a7654df: function() { return handleError(function (arg0, arg1) {
|
|
126
|
+
const ret = Reflect.get(arg0, arg1);
|
|
127
|
+
return ret;
|
|
128
|
+
}, arguments); },
|
|
129
|
+
__wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
|
|
130
|
+
const ret = arg0[arg1 >>> 0];
|
|
131
|
+
return ret;
|
|
132
|
+
},
|
|
133
|
+
__wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
|
|
134
|
+
let result;
|
|
135
|
+
try {
|
|
136
|
+
result = arg0 instanceof ArrayBuffer;
|
|
137
|
+
} catch (_) {
|
|
138
|
+
result = false;
|
|
139
|
+
}
|
|
140
|
+
const ret = result;
|
|
141
|
+
return ret;
|
|
142
|
+
},
|
|
143
|
+
__wbg_instanceof_Map_e5b5e3db98422fcc: function(arg0) {
|
|
144
|
+
let result;
|
|
145
|
+
try {
|
|
146
|
+
result = arg0 instanceof Map;
|
|
147
|
+
} catch (_) {
|
|
148
|
+
result = false;
|
|
149
|
+
}
|
|
150
|
+
const ret = result;
|
|
151
|
+
return ret;
|
|
152
|
+
},
|
|
153
|
+
__wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
|
|
154
|
+
let result;
|
|
155
|
+
try {
|
|
156
|
+
result = arg0 instanceof Uint8Array;
|
|
157
|
+
} catch (_) {
|
|
158
|
+
result = false;
|
|
159
|
+
}
|
|
160
|
+
const ret = result;
|
|
161
|
+
return ret;
|
|
162
|
+
},
|
|
163
|
+
__wbg_isArray_0677c962b281d01a: function(arg0) {
|
|
164
|
+
const ret = Array.isArray(arg0);
|
|
165
|
+
return ret;
|
|
166
|
+
},
|
|
167
|
+
__wbg_isSafeInteger_04f36e4056f1b851: function(arg0) {
|
|
168
|
+
const ret = Number.isSafeInteger(arg0);
|
|
169
|
+
return ret;
|
|
170
|
+
},
|
|
171
|
+
__wbg_iterator_6f722e4a93058b71: function() {
|
|
172
|
+
const ret = Symbol.iterator;
|
|
173
|
+
return ret;
|
|
174
|
+
},
|
|
175
|
+
__wbg_length_1f0964f4a5e2c6d8: function(arg0) {
|
|
176
|
+
const ret = arg0.length;
|
|
177
|
+
return ret;
|
|
178
|
+
},
|
|
179
|
+
__wbg_length_370319915dc99107: function(arg0) {
|
|
180
|
+
const ret = arg0.length;
|
|
181
|
+
return ret;
|
|
182
|
+
},
|
|
183
|
+
__wbg_new_32b398fb48b6d94a: function() {
|
|
184
|
+
const ret = new Array();
|
|
185
|
+
return ret;
|
|
186
|
+
},
|
|
187
|
+
__wbg_new_cd45aabdf6073e84: function(arg0) {
|
|
188
|
+
const ret = new Uint8Array(arg0);
|
|
189
|
+
return ret;
|
|
190
|
+
},
|
|
191
|
+
__wbg_new_da52cf8fe3429cb2: function() {
|
|
192
|
+
const ret = new Object();
|
|
193
|
+
return ret;
|
|
194
|
+
},
|
|
195
|
+
__wbg_next_6dbf2c0ac8cde20f: function(arg0) {
|
|
196
|
+
const ret = arg0.next;
|
|
197
|
+
return ret;
|
|
198
|
+
},
|
|
199
|
+
__wbg_next_71f2aa1cb3d1e37e: function() { return handleError(function (arg0) {
|
|
200
|
+
const ret = arg0.next();
|
|
201
|
+
return ret;
|
|
202
|
+
}, arguments); },
|
|
203
|
+
__wbg_now_86c0d4ba3fa605b8: function() {
|
|
204
|
+
const ret = Date.now();
|
|
205
|
+
return ret;
|
|
206
|
+
},
|
|
207
|
+
__wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
|
|
208
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
209
|
+
},
|
|
210
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
211
|
+
arg0[arg1] = arg2;
|
|
212
|
+
},
|
|
213
|
+
__wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
|
|
214
|
+
arg0[arg1 >>> 0] = arg2;
|
|
215
|
+
},
|
|
216
|
+
__wbg_value_a5d5488a9589444a: function(arg0) {
|
|
217
|
+
const ret = arg0.value;
|
|
218
|
+
return ret;
|
|
219
|
+
},
|
|
220
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
221
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
222
|
+
const ret = arg0;
|
|
223
|
+
return ret;
|
|
224
|
+
},
|
|
225
|
+
__wbindgen_cast_0000000000000002: function(arg0) {
|
|
226
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
227
|
+
const ret = arg0;
|
|
228
|
+
return ret;
|
|
229
|
+
},
|
|
230
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
231
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
232
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
233
|
+
return ret;
|
|
234
|
+
},
|
|
235
|
+
__wbindgen_cast_0000000000000004: function(arg0) {
|
|
236
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
237
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
238
|
+
return ret;
|
|
239
|
+
},
|
|
240
|
+
__wbindgen_init_externref_table: function() {
|
|
241
|
+
const table = wasm.__wbindgen_externrefs;
|
|
242
|
+
const offset = table.grow(4);
|
|
243
|
+
table.set(0, undefined);
|
|
244
|
+
table.set(offset + 0, undefined);
|
|
245
|
+
table.set(offset + 1, null);
|
|
246
|
+
table.set(offset + 2, true);
|
|
247
|
+
table.set(offset + 3, false);
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
__proto__: null,
|
|
252
|
+
"./u_routing_bg.js": import0,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function addToExternrefTable0(obj) {
|
|
257
|
+
const idx = wasm.__externref_table_alloc();
|
|
258
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
259
|
+
return idx;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function debugString(val) {
|
|
263
|
+
// primitive types
|
|
264
|
+
const type = typeof val;
|
|
265
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
266
|
+
return `${val}`;
|
|
267
|
+
}
|
|
268
|
+
if (type == 'string') {
|
|
269
|
+
return `"${val}"`;
|
|
270
|
+
}
|
|
271
|
+
if (type == 'symbol') {
|
|
272
|
+
const description = val.description;
|
|
273
|
+
if (description == null) {
|
|
274
|
+
return 'Symbol';
|
|
275
|
+
} else {
|
|
276
|
+
return `Symbol(${description})`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (type == 'function') {
|
|
280
|
+
const name = val.name;
|
|
281
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
282
|
+
return `Function(${name})`;
|
|
283
|
+
} else {
|
|
284
|
+
return 'Function';
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// objects
|
|
288
|
+
if (Array.isArray(val)) {
|
|
289
|
+
const length = val.length;
|
|
290
|
+
let debug = '[';
|
|
291
|
+
if (length > 0) {
|
|
292
|
+
debug += debugString(val[0]);
|
|
293
|
+
}
|
|
294
|
+
for(let i = 1; i < length; i++) {
|
|
295
|
+
debug += ', ' + debugString(val[i]);
|
|
296
|
+
}
|
|
297
|
+
debug += ']';
|
|
298
|
+
return debug;
|
|
299
|
+
}
|
|
300
|
+
// Test for built-in
|
|
301
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
302
|
+
let className;
|
|
303
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
304
|
+
className = builtInMatches[1];
|
|
305
|
+
} else {
|
|
306
|
+
// Failed to match the standard '[object ClassName]'
|
|
307
|
+
return toString.call(val);
|
|
308
|
+
}
|
|
309
|
+
if (className == 'Object') {
|
|
310
|
+
// we're a user defined class or Object
|
|
311
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
312
|
+
// easier than looping through ownProperties of `val`.
|
|
313
|
+
try {
|
|
314
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
315
|
+
} catch (_) {
|
|
316
|
+
return 'Object';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// errors
|
|
320
|
+
if (val instanceof Error) {
|
|
321
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
322
|
+
}
|
|
323
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
324
|
+
return className;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
328
|
+
ptr = ptr >>> 0;
|
|
329
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
let cachedDataViewMemory0 = null;
|
|
333
|
+
function getDataViewMemory0() {
|
|
334
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
335
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
336
|
+
}
|
|
337
|
+
return cachedDataViewMemory0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function getStringFromWasm0(ptr, len) {
|
|
341
|
+
return decodeText(ptr >>> 0, len);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let cachedUint8ArrayMemory0 = null;
|
|
345
|
+
function getUint8ArrayMemory0() {
|
|
346
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
347
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
348
|
+
}
|
|
349
|
+
return cachedUint8ArrayMemory0;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function handleError(f, args) {
|
|
353
|
+
try {
|
|
354
|
+
return f.apply(this, args);
|
|
355
|
+
} catch (e) {
|
|
356
|
+
const idx = addToExternrefTable0(e);
|
|
357
|
+
wasm.__wbindgen_exn_store(idx);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function isLikeNone(x) {
|
|
362
|
+
return x === undefined || x === null;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
366
|
+
if (realloc === undefined) {
|
|
367
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
368
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
369
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
370
|
+
WASM_VECTOR_LEN = buf.length;
|
|
371
|
+
return ptr;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
let len = arg.length;
|
|
375
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
376
|
+
|
|
377
|
+
const mem = getUint8ArrayMemory0();
|
|
378
|
+
|
|
379
|
+
let offset = 0;
|
|
380
|
+
|
|
381
|
+
for (; offset < len; offset++) {
|
|
382
|
+
const code = arg.charCodeAt(offset);
|
|
383
|
+
if (code > 0x7F) break;
|
|
384
|
+
mem[ptr + offset] = code;
|
|
385
|
+
}
|
|
386
|
+
if (offset !== len) {
|
|
387
|
+
if (offset !== 0) {
|
|
388
|
+
arg = arg.slice(offset);
|
|
389
|
+
}
|
|
390
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
391
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
392
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
393
|
+
|
|
394
|
+
offset += ret.written;
|
|
395
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
WASM_VECTOR_LEN = offset;
|
|
399
|
+
return ptr;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function takeFromExternrefTable0(idx) {
|
|
403
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
404
|
+
wasm.__externref_table_dealloc(idx);
|
|
405
|
+
return value;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
409
|
+
cachedTextDecoder.decode();
|
|
410
|
+
function decodeText(ptr, len) {
|
|
411
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const cachedTextEncoder = new TextEncoder();
|
|
415
|
+
|
|
416
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
417
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
418
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
419
|
+
view.set(buf);
|
|
420
|
+
return {
|
|
421
|
+
read: arg.length,
|
|
422
|
+
written: buf.length
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
let WASM_VECTOR_LEN = 0;
|
|
428
|
+
|
|
429
|
+
const wasmPath = `${__dirname}/u_routing_bg.wasm`;
|
|
430
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
431
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
432
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
433
|
+
let wasm = wasmInstance.exports;
|
|
434
|
+
wasm.__wbindgen_start();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Solve a capacitated VRP problem.
|
|
6
|
+
*
|
|
7
|
+
* # Arguments
|
|
8
|
+
* * `problem` — A native JS object matching the VRP input schema.
|
|
9
|
+
*
|
|
10
|
+
* # Supported methods
|
|
11
|
+
* - `"nn"` — Nearest Neighbor (default, fast)
|
|
12
|
+
* - `"savings"` — Clarke-Wright Savings
|
|
13
|
+
* - `"ga"` — Genetic Algorithm with Prins split + local search
|
|
14
|
+
* - `"alns"` — Adaptive Large Neighborhood Search + local search
|
|
15
|
+
*
|
|
16
|
+
* # Returns
|
|
17
|
+
* A JS object with `routes`, `total_distance`, `num_vehicles`,
|
|
18
|
+
* `method_used`, and `computation_time_ms`.
|
|
19
|
+
*
|
|
20
|
+
* # Errors
|
|
21
|
+
* Returns a `JsValue` string describing the error if input is invalid.
|
|
22
|
+
*/
|
|
23
|
+
export function solve_vrp(problem: any): any;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"iyulab"
|
|
6
6
|
],
|
|
7
7
|
"description": "Vehicle routing optimization: TSP, CVRP, VRPTW with constructive heuristics, local search, GA, and ALNS.",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.3.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -15,13 +15,15 @@
|
|
|
15
15
|
"u_routing_bg.wasm",
|
|
16
16
|
"u_routing.js",
|
|
17
17
|
"u_routing_bg.js",
|
|
18
|
-
"u_routing.d.ts"
|
|
18
|
+
"u_routing.d.ts",
|
|
19
|
+
"node"
|
|
19
20
|
],
|
|
20
21
|
"main": "u_routing.js",
|
|
21
22
|
"types": "u_routing.d.ts",
|
|
22
23
|
"sideEffects": [
|
|
23
24
|
"./u_routing.js",
|
|
24
|
-
"./snippets/*"
|
|
25
|
+
"./snippets/*",
|
|
26
|
+
"./node/u_routing.cjs"
|
|
25
27
|
],
|
|
26
28
|
"keywords": [
|
|
27
29
|
"routing",
|
|
@@ -29,5 +31,15 @@
|
|
|
29
31
|
"tsp",
|
|
30
32
|
"optimization",
|
|
31
33
|
"logistics"
|
|
32
|
-
]
|
|
34
|
+
],
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"node": {
|
|
38
|
+
"types": "./node/u_routing.d.cts",
|
|
39
|
+
"default": "./node/u_routing.cjs"
|
|
40
|
+
},
|
|
41
|
+
"types": "./u_routing.d.ts",
|
|
42
|
+
"default": "./u_routing.js"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
33
45
|
}
|
package/u_routing_bg.js
CHANGED
|
@@ -26,14 +26,10 @@ export function solve_vrp(problem) {
|
|
|
26
26
|
}
|
|
27
27
|
return takeFromExternrefTable0(ret[0]);
|
|
28
28
|
}
|
|
29
|
-
export function
|
|
29
|
+
export function __wbg_Error_92b29b0548f8b746(arg0, arg1) {
|
|
30
30
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
31
31
|
return ret;
|
|
32
32
|
}
|
|
33
|
-
export function __wbg_Number_4779d427bae39753(arg0) {
|
|
34
|
-
const ret = Number(arg0);
|
|
35
|
-
return ret;
|
|
36
|
-
}
|
|
37
33
|
export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
38
34
|
const ret = String(arg1);
|
|
39
35
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -41,60 +37,56 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
|
41
37
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
42
38
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
43
39
|
}
|
|
44
|
-
export function
|
|
40
|
+
export function __wbg___wbindgen_bigint_get_as_i64_d968e41184ae354f(arg0, arg1) {
|
|
45
41
|
const v = arg1;
|
|
46
42
|
const ret = typeof(v) === 'bigint' ? v : undefined;
|
|
47
43
|
getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
48
44
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
49
45
|
}
|
|
50
|
-
export function
|
|
46
|
+
export function __wbg___wbindgen_boolean_get_fa956cfa2d1bd751(arg0) {
|
|
51
47
|
const v = arg0;
|
|
52
48
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
53
49
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
54
50
|
}
|
|
55
|
-
export function
|
|
51
|
+
export function __wbg___wbindgen_debug_string_c25d447a39f5578f(arg0, arg1) {
|
|
56
52
|
const ret = debugString(arg1);
|
|
57
53
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
58
54
|
const len1 = WASM_VECTOR_LEN;
|
|
59
55
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
60
56
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
61
57
|
}
|
|
62
|
-
export function
|
|
58
|
+
export function __wbg___wbindgen_in_aca499c5de7ff5e5(arg0, arg1) {
|
|
63
59
|
const ret = arg0 in arg1;
|
|
64
60
|
return ret;
|
|
65
61
|
}
|
|
66
|
-
export function
|
|
62
|
+
export function __wbg___wbindgen_is_bigint_2f76dc55065b4273(arg0) {
|
|
67
63
|
const ret = typeof(arg0) === 'bigint';
|
|
68
64
|
return ret;
|
|
69
65
|
}
|
|
70
|
-
export function
|
|
66
|
+
export function __wbg___wbindgen_is_function_1ff95bcc5517c252(arg0) {
|
|
71
67
|
const ret = typeof(arg0) === 'function';
|
|
72
68
|
return ret;
|
|
73
69
|
}
|
|
74
|
-
export function
|
|
70
|
+
export function __wbg___wbindgen_is_object_a27215656b807791(arg0) {
|
|
75
71
|
const val = arg0;
|
|
76
72
|
const ret = typeof(val) === 'object' && val !== null;
|
|
77
73
|
return ret;
|
|
78
74
|
}
|
|
79
|
-
export function
|
|
80
|
-
const ret = arg0 === undefined;
|
|
81
|
-
return ret;
|
|
82
|
-
}
|
|
83
|
-
export function __wbg___wbindgen_jsval_eq_174c93ec61bab0c5(arg0, arg1) {
|
|
75
|
+
export function __wbg___wbindgen_jsval_eq_e659fcf7b0e32763(arg0, arg1) {
|
|
84
76
|
const ret = arg0 === arg1;
|
|
85
77
|
return ret;
|
|
86
78
|
}
|
|
87
|
-
export function
|
|
79
|
+
export function __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170(arg0, arg1) {
|
|
88
80
|
const ret = arg0 == arg1;
|
|
89
81
|
return ret;
|
|
90
82
|
}
|
|
91
|
-
export function
|
|
83
|
+
export function __wbg___wbindgen_number_get_394265ed1e1b84ee(arg0, arg1) {
|
|
92
84
|
const obj = arg1;
|
|
93
85
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
94
86
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
95
87
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
96
88
|
}
|
|
97
|
-
export function
|
|
89
|
+
export function __wbg___wbindgen_string_get_b0ca35b86a603356(arg0, arg1) {
|
|
98
90
|
const obj = arg1;
|
|
99
91
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
100
92
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -102,43 +94,57 @@ export function __wbg___wbindgen_string_get_fa2687d531ed17a5(arg0, arg1) {
|
|
|
102
94
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
103
95
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
104
96
|
}
|
|
105
|
-
export function
|
|
97
|
+
export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
|
|
106
98
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
107
99
|
}
|
|
108
|
-
export function
|
|
100
|
+
export function __wbg_call_8a2dd23819f8a60a() { return handleError(function (arg0, arg1) {
|
|
109
101
|
const ret = arg0.call(arg1);
|
|
110
102
|
return ret;
|
|
111
103
|
}, arguments); }
|
|
112
|
-
export function
|
|
104
|
+
export function __wbg_done_89b2b13e91a60321(arg0) {
|
|
113
105
|
const ret = arg0.done;
|
|
114
106
|
return ret;
|
|
115
107
|
}
|
|
108
|
+
export function __wbg_entries_015dc610cd81ede0(arg0) {
|
|
109
|
+
const ret = Object.entries(arg0);
|
|
110
|
+
return ret;
|
|
111
|
+
}
|
|
116
112
|
export function __wbg_getRandomValues_3f44b700395062e5() { return handleError(function (arg0, arg1) {
|
|
117
113
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
118
114
|
}, arguments); }
|
|
119
|
-
export function
|
|
115
|
+
export function __wbg_get_507a50627bffa49b(arg0, arg1) {
|
|
116
|
+
const ret = arg0[arg1 >>> 0];
|
|
117
|
+
return ret;
|
|
118
|
+
}
|
|
119
|
+
export function __wbg_get_c7eb1f358a7654df() { return handleError(function (arg0, arg1) {
|
|
120
120
|
const ret = Reflect.get(arg0, arg1);
|
|
121
121
|
return ret;
|
|
122
122
|
}, arguments); }
|
|
123
|
-
export function
|
|
123
|
+
export function __wbg_get_unchecked_6e0ad6d2a41b06f6(arg0, arg1) {
|
|
124
124
|
const ret = arg0[arg1 >>> 0];
|
|
125
125
|
return ret;
|
|
126
126
|
}
|
|
127
|
-
export function
|
|
128
|
-
|
|
127
|
+
export function __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb(arg0) {
|
|
128
|
+
let result;
|
|
129
|
+
try {
|
|
130
|
+
result = arg0 instanceof ArrayBuffer;
|
|
131
|
+
} catch (_) {
|
|
132
|
+
result = false;
|
|
133
|
+
}
|
|
134
|
+
const ret = result;
|
|
129
135
|
return ret;
|
|
130
136
|
}
|
|
131
|
-
export function
|
|
137
|
+
export function __wbg_instanceof_Map_e5b5e3db98422fcc(arg0) {
|
|
132
138
|
let result;
|
|
133
139
|
try {
|
|
134
|
-
result = arg0 instanceof
|
|
140
|
+
result = arg0 instanceof Map;
|
|
135
141
|
} catch (_) {
|
|
136
142
|
result = false;
|
|
137
143
|
}
|
|
138
144
|
const ret = result;
|
|
139
145
|
return ret;
|
|
140
146
|
}
|
|
141
|
-
export function
|
|
147
|
+
export function __wbg_instanceof_Uint8Array_309b927aaf7a3fc7(arg0) {
|
|
142
148
|
let result;
|
|
143
149
|
try {
|
|
144
150
|
result = arg0 instanceof Uint8Array;
|
|
@@ -148,60 +154,60 @@ export function __wbg_instanceof_Uint8Array_b6fe1ac89eba107e(arg0) {
|
|
|
148
154
|
const ret = result;
|
|
149
155
|
return ret;
|
|
150
156
|
}
|
|
151
|
-
export function
|
|
157
|
+
export function __wbg_isArray_0677c962b281d01a(arg0) {
|
|
152
158
|
const ret = Array.isArray(arg0);
|
|
153
159
|
return ret;
|
|
154
160
|
}
|
|
155
|
-
export function
|
|
161
|
+
export function __wbg_isSafeInteger_04f36e4056f1b851(arg0) {
|
|
156
162
|
const ret = Number.isSafeInteger(arg0);
|
|
157
163
|
return ret;
|
|
158
164
|
}
|
|
159
|
-
export function
|
|
165
|
+
export function __wbg_iterator_6f722e4a93058b71() {
|
|
160
166
|
const ret = Symbol.iterator;
|
|
161
167
|
return ret;
|
|
162
168
|
}
|
|
163
|
-
export function
|
|
169
|
+
export function __wbg_length_1f0964f4a5e2c6d8(arg0) {
|
|
164
170
|
const ret = arg0.length;
|
|
165
171
|
return ret;
|
|
166
172
|
}
|
|
167
|
-
export function
|
|
173
|
+
export function __wbg_length_370319915dc99107(arg0) {
|
|
168
174
|
const ret = arg0.length;
|
|
169
175
|
return ret;
|
|
170
176
|
}
|
|
171
|
-
export function
|
|
177
|
+
export function __wbg_new_32b398fb48b6d94a() {
|
|
172
178
|
const ret = new Array();
|
|
173
179
|
return ret;
|
|
174
180
|
}
|
|
175
|
-
export function
|
|
181
|
+
export function __wbg_new_cd45aabdf6073e84(arg0) {
|
|
182
|
+
const ret = new Uint8Array(arg0);
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
export function __wbg_new_da52cf8fe3429cb2() {
|
|
176
186
|
const ret = new Object();
|
|
177
187
|
return ret;
|
|
178
188
|
}
|
|
179
|
-
export function
|
|
180
|
-
const ret =
|
|
189
|
+
export function __wbg_next_6dbf2c0ac8cde20f(arg0) {
|
|
190
|
+
const ret = arg0.next;
|
|
181
191
|
return ret;
|
|
182
192
|
}
|
|
183
|
-
export function
|
|
193
|
+
export function __wbg_next_71f2aa1cb3d1e37e() { return handleError(function (arg0) {
|
|
184
194
|
const ret = arg0.next();
|
|
185
195
|
return ret;
|
|
186
196
|
}, arguments); }
|
|
187
|
-
export function
|
|
188
|
-
const ret = arg0.next;
|
|
189
|
-
return ret;
|
|
190
|
-
}
|
|
191
|
-
export function __wbg_now_bce4dc999095ea77() {
|
|
197
|
+
export function __wbg_now_86c0d4ba3fa605b8() {
|
|
192
198
|
const ret = Date.now();
|
|
193
199
|
return ret;
|
|
194
200
|
}
|
|
195
|
-
export function
|
|
201
|
+
export function __wbg_prototypesetcall_4770620bbe4688a0(arg0, arg1, arg2) {
|
|
196
202
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
197
203
|
}
|
|
198
204
|
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
199
205
|
arg0[arg1] = arg2;
|
|
200
206
|
}
|
|
201
|
-
export function
|
|
207
|
+
export function __wbg_set_8a16b38e4805b298(arg0, arg1, arg2) {
|
|
202
208
|
arg0[arg1 >>> 0] = arg2;
|
|
203
209
|
}
|
|
204
|
-
export function
|
|
210
|
+
export function __wbg_value_a5d5488a9589444a(arg0) {
|
|
205
211
|
const ret = arg0.value;
|
|
206
212
|
return ret;
|
|
207
213
|
}
|
|
@@ -210,12 +216,17 @@ export function __wbindgen_cast_0000000000000001(arg0) {
|
|
|
210
216
|
const ret = arg0;
|
|
211
217
|
return ret;
|
|
212
218
|
}
|
|
213
|
-
export function __wbindgen_cast_0000000000000002(arg0
|
|
219
|
+
export function __wbindgen_cast_0000000000000002(arg0) {
|
|
220
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
221
|
+
const ret = arg0;
|
|
222
|
+
return ret;
|
|
223
|
+
}
|
|
224
|
+
export function __wbindgen_cast_0000000000000003(arg0, arg1) {
|
|
214
225
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
215
226
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
216
227
|
return ret;
|
|
217
228
|
}
|
|
218
|
-
export function
|
|
229
|
+
export function __wbindgen_cast_0000000000000004(arg0) {
|
|
219
230
|
// Cast intrinsic for `U64 -> Externref`.
|
|
220
231
|
const ret = BigInt.asUintN(64, arg0);
|
|
221
232
|
return ret;
|
package/u_routing_bg.wasm
CHANGED
|
Binary file
|