@iyulab/u-routing 0.1.0 → 0.2.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.md +63 -0
- package/package.json +1 -1
- package/u_routing.d.ts +8 -1
- package/u_routing_bg.js +15 -1
- package/u_routing_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -118,6 +118,69 @@ u-routing
|
|
|
118
118
|
- Ropke, S. & Pisinger, D. (2006). "An Adaptive Large Neighborhood Search Heuristic for the Pickup and Delivery Problem with Time Windows"
|
|
119
119
|
- Shaw, P. (1998). "Using Constraint Programming and Local Search Methods to Solve Vehicle Routing Problems"
|
|
120
120
|
|
|
121
|
+
## WebAssembly / npm
|
|
122
|
+
|
|
123
|
+
Available as an npm package via [wasm-pack](https://rustwasm.github.io/wasm-pack/).
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm install @iyulab/u-routing
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Quick Start
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import init, { solve_vrp } from '@iyulab/u-routing';
|
|
133
|
+
|
|
134
|
+
await init();
|
|
135
|
+
const result = solve_vrp({
|
|
136
|
+
customers: [
|
|
137
|
+
{ id: 1, x: 1.0, y: 2.0, demand: 10 },
|
|
138
|
+
{ id: 2, x: 3.0, y: 4.0, demand: 15 },
|
|
139
|
+
],
|
|
140
|
+
vehicles: [{ capacity: 100 }],
|
|
141
|
+
depot: { x: 0.0, y: 0.0 },
|
|
142
|
+
method: "nn"
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Functions
|
|
147
|
+
|
|
148
|
+
#### `solve_vrp(input) -> VrpOutput`
|
|
149
|
+
|
|
150
|
+
Solve a capacitated VRP with optional time windows. Four solver methods available.
|
|
151
|
+
|
|
152
|
+
**Methods:** `"nn"` (Nearest Neighbor), `"savings"` (Clarke-Wright), `"ga"` (Genetic Algorithm + Split DP), `"alns"` (Adaptive Large Neighborhood Search).
|
|
153
|
+
|
|
154
|
+
**Input:**
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"customers": [
|
|
158
|
+
{ "id": 1, "x": 1.0, "y": 2.0, "demand": 10, "service_time": 0.5, "time_window": [8.0, 12.0] }
|
|
159
|
+
],
|
|
160
|
+
"vehicles": [{ "capacity": 100 }],
|
|
161
|
+
"depot": { "x": 0.0, "y": 0.0 },
|
|
162
|
+
"method": "ga",
|
|
163
|
+
"config": {
|
|
164
|
+
"population_size": 50, "max_generations": 200,
|
|
165
|
+
"mutation_rate": 0.1, "elite_ratio": 0.1,
|
|
166
|
+
"max_iterations": 500, "seed": 42
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
GA uses `population_size`, `max_generations`, `mutation_rate`, `elite_ratio`. ALNS uses `max_iterations`. Both accept `seed`.
|
|
172
|
+
|
|
173
|
+
**Output:**
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"routes": [[1, 3, 5], [2, 4]],
|
|
177
|
+
"total_distance": 42.5,
|
|
178
|
+
"num_vehicles": 2,
|
|
179
|
+
"method_used": "ga",
|
|
180
|
+
"computation_time_ms": 120.0
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
121
184
|
## Related
|
|
122
185
|
|
|
123
186
|
- [u-numflow](https://crates.io/crates/u-numflow) — Mathematical optimization primitives
|
package/package.json
CHANGED
package/u_routing.d.ts
CHANGED
|
@@ -7,8 +7,15 @@
|
|
|
7
7
|
* # Arguments
|
|
8
8
|
* * `problem_json` — A JS object matching the VRP input schema.
|
|
9
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
|
+
*
|
|
10
16
|
* # Returns
|
|
11
|
-
* A JS object with `routes`, `total_distance`,
|
|
17
|
+
* A JS object with `routes`, `total_distance`, `num_vehicles`,
|
|
18
|
+
* `method_used`, and `computation_time_ms`.
|
|
12
19
|
*
|
|
13
20
|
* # Errors
|
|
14
21
|
* Returns a `JsValue` string describing the error if input is invalid.
|
package/u_routing_bg.js
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
4
4
|
* # Arguments
|
|
5
5
|
* * `problem_json` — A JS object matching the VRP input schema.
|
|
6
6
|
*
|
|
7
|
+
* # Supported methods
|
|
8
|
+
* - `"nn"` — Nearest Neighbor (default, fast)
|
|
9
|
+
* - `"savings"` — Clarke-Wright Savings
|
|
10
|
+
* - `"ga"` — Genetic Algorithm with Prins split + local search
|
|
11
|
+
* - `"alns"` — Adaptive Large Neighborhood Search + local search
|
|
12
|
+
*
|
|
7
13
|
* # Returns
|
|
8
|
-
* A JS object with `routes`, `total_distance`,
|
|
14
|
+
* A JS object with `routes`, `total_distance`, `num_vehicles`,
|
|
15
|
+
* `method_used`, and `computation_time_ms`.
|
|
9
16
|
*
|
|
10
17
|
* # Errors
|
|
11
18
|
* Returns a `JsValue` string describing the error if input is invalid.
|
|
@@ -106,6 +113,9 @@ export function __wbg_done_08ce71ee07e3bd17(arg0) {
|
|
|
106
113
|
const ret = arg0.done;
|
|
107
114
|
return ret;
|
|
108
115
|
}
|
|
116
|
+
export function __wbg_getRandomValues_3f44b700395062e5() { return handleError(function (arg0, arg1) {
|
|
117
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
118
|
+
}, arguments); }
|
|
109
119
|
export function __wbg_get_326e41e095fb2575() { return handleError(function (arg0, arg1) {
|
|
110
120
|
const ret = Reflect.get(arg0, arg1);
|
|
111
121
|
return ret;
|
|
@@ -178,6 +188,10 @@ export function __wbg_next_e01a967809d1aa68(arg0) {
|
|
|
178
188
|
const ret = arg0.next;
|
|
179
189
|
return ret;
|
|
180
190
|
}
|
|
191
|
+
export function __wbg_now_16f0c993d5dd6c27() {
|
|
192
|
+
const ret = Date.now();
|
|
193
|
+
return ret;
|
|
194
|
+
}
|
|
181
195
|
export function __wbg_prototypesetcall_d62e5099504357e6(arg0, arg1, arg2) {
|
|
182
196
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
183
197
|
}
|
package/u_routing_bg.wasm
CHANGED
|
Binary file
|